HomeAssistant-API 3.0.2__tar.gz → 3.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/PKG-INFO +3 -6
  2. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/README.md +0 -3
  3. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/models/domains.py +29 -4
  4. HomeAssistant-API-3.0.3/homeassistant_api/py.typed +0 -0
  5. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/rawapi.py +9 -14
  6. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/rawclient.py +2 -2
  7. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/pyproject.toml +33 -41
  8. HomeAssistant-API-3.0.3/setup.py +39 -0
  9. HomeAssistant-API-3.0.2/setup.py +0 -38
  10. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/LICENSE +0 -0
  11. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/__init__.py +0 -0
  12. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/__init__.py +0 -0
  13. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/asyncclient.py +0 -0
  14. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/models/__init__.py +0 -0
  15. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/models/entity.py +0 -0
  16. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/_async/models/events.py +0 -0
  17. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/client.py +0 -0
  18. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/const.py +0 -0
  19. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/errors.py +0 -0
  20. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/mixins.py +0 -0
  21. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/__init__.py +0 -0
  22. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/base.py +0 -0
  23. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/domains.py +0 -0
  24. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/entity.py +0 -0
  25. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/events.py +0 -0
  26. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/history.py +0 -0
  27. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/logbook.py +0 -0
  28. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/models/states.py +0 -0
  29. {HomeAssistant-API-3.0.2 → HomeAssistant-API-3.0.3}/homeassistant_api/processing.py +0 -0
@@ -1,20 +1,20 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homeassistant-api
3
- Version: 3.0.2
3
+ Version: 3.0.3
4
4
  Summary: Python Wrapper for Homeassistant's REST API
5
5
  Home-page: https://github.com/GrandMoff100/HomeAssistantAPI
6
6
  License: GPL-3.0-or-later
7
7
  Author: GrandMoff100
8
8
  Author-email: minecraftcrusher100@gmail.com
9
- Requires-Python: >=3.7,<4.0
9
+ Requires-Python: >=3.8,<4.0
10
10
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.7
14
13
  Classifier: Programming Language :: Python :: 3.8
15
14
  Classifier: Programming Language :: Python :: 3.9
16
15
  Requires-Dist: aiohttp (>=3.8.1,<4.0.0)
17
16
  Requires-Dist: aiohttp-client-cache (>=0.6.1,<0.7.0)
17
+ Requires-Dist: autodoc-pydantic (>=1.6.1,<2.0.0)
18
18
  Requires-Dist: pydantic (>=1.9.0,<2.0.0)
19
19
  Requires-Dist: requests (>=2.26.0,<3.0.0)
20
20
  Requires-Dist: requests-cache (>=0.9.2,<0.10.0)
@@ -25,7 +25,6 @@ Description-Content-Type: text/markdown
25
25
 
26
26
  # HomeassistantAPI
27
27
 
28
- ![Lines of code](https://img.shields.io/tokei/lines/github/GrandMoff100/HomeassistantAPI?style=for-the-badge)
29
28
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/HomeAssistant-API?style=for-the-badge)](https://pypi.org/project/homeassistant_api)
30
29
  ![GitHub commits since latest release (by date including pre-releases)](https://img.shields.io/github/commits-since/GrandMoff100/HomeassistantAPI/latest/dev?include_prereleases&style=for-the-badge)
31
30
  [![Read the Docs (version)](https://img.shields.io/readthedocs/homeassistantapi?style=for-the-badge)](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
@@ -35,8 +34,6 @@ Description-Content-Type: text/markdown
35
34
 
36
35
  ## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
37
36
 
38
- Please ⭐️ the repo if you find this project useful or cool!
39
-
40
37
  Here is a quick example.
41
38
  ```py
42
39
  from homeassistant_api import Client
@@ -1,6 +1,5 @@
1
1
  # HomeassistantAPI
2
2
 
3
- ![Lines of code](https://img.shields.io/tokei/lines/github/GrandMoff100/HomeassistantAPI?style=for-the-badge)
4
3
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/HomeAssistant-API?style=for-the-badge)](https://pypi.org/project/homeassistant_api)
5
4
  ![GitHub commits since latest release (by date including pre-releases)](https://img.shields.io/github/commits-since/GrandMoff100/HomeassistantAPI/latest/dev?include_prereleases&style=for-the-badge)
6
5
  [![Read the Docs (version)](https://img.shields.io/readthedocs/homeassistantapi?style=for-the-badge)](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
@@ -10,8 +9,6 @@
10
9
 
11
10
  ## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
12
11
 
13
- Please ⭐️ the repo if you find this project useful or cool!
14
-
15
12
  Here is a quick example.
16
13
  ```py
17
14
  from homeassistant_api import Client
@@ -1,13 +1,23 @@
1
1
  """File for Service and Domain data models"""
2
2
 
3
- from typing import Any, Dict, Tuple, cast
3
+ from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, cast
4
4
 
5
- from ...models import Domain, Service, State
5
+ from pydantic import BaseModel, Field
6
6
 
7
+ from ...models import State
8
+ from ...models.domains import ServiceField
7
9
 
8
- class AsyncDomain(Domain):
10
+ if TYPE_CHECKING:
11
+ from homeassistant_api import Client
12
+
13
+
14
+ class AsyncDomain(BaseModel):
9
15
  """A class representing the domain that services belong to."""
10
16
 
17
+ domain_id: str
18
+ client: "Client" = Field(exclude=True, repr=False)
19
+ services: Dict[str, "AsyncService"] = {}
20
+
11
21
  def add_service(self, service_id: str, **data) -> None:
12
22
  """Registers services into a domain to be used or accessed"""
13
23
  self.services.update(
@@ -24,10 +34,25 @@ class AsyncDomain(Domain):
24
34
  """Return a Service with the given service_id, returns None if no such service exists"""
25
35
  return self.services.get(service_id, None)
26
36
 
37
+ def __getattr__(self, attr: str):
38
+ """Allows services accessible as attributes"""
39
+ if attr in self.__dict__:
40
+ return super().__getattribute__(attr)
41
+ if attr in self.services:
42
+ return self.get_service(attr)
43
+ return super().__getattribute__(attr)
27
44
 
28
- class AsyncService(Service):
45
+
46
+ class AsyncService(BaseModel):
29
47
  """Class representing services from homeassistant"""
30
48
 
49
+ service_id: str
50
+ domain: AsyncDomain
51
+ name: Optional[str] = None
52
+ description: Optional[str] = None
53
+ fields: Optional[Dict[str, ServiceField]] = None
54
+ target: Optional[Dict[str, dict]] = None
55
+
31
56
  async def async_trigger(self, **service_data) -> Tuple[State, ...]:
32
57
  """Triggers the service associated with this object."""
33
58
  data = await self.domain.client.async_trigger_service(
File without changes
@@ -1,11 +1,11 @@
1
1
  """Module for parent RawWrapper class"""
2
2
 
3
3
  import os
4
+ import re
4
5
  from datetime import datetime
5
6
  from typing import Dict, Optional, Tuple, Union
6
7
 
7
8
  from .const import DATE_FMT
8
- from .errors import MalformedInputError
9
9
  from .models import Entity
10
10
 
11
11
 
@@ -72,16 +72,13 @@ class RawWrapper:
72
72
  """Custom method for constructing non-standard query strings"""
73
73
  return "&".join([k if v is None else f"{k}={v}" for k, v in params.items()])
74
74
 
75
- @classmethod
76
- def malformed_id(cls, entity_id: str) -> bool:
77
- """Checks whether or not a given entity_id is formatted correctly"""
78
- checks = [
79
- " " in entity_id,
80
- "." not in entity_id,
81
- "-" in entity_id,
82
- entity_id.lower() == entity_id,
83
- ]
84
- return True in checks
75
+ @staticmethod
76
+ def format_entity_id(entity_id: str) -> str:
77
+ """Takes in a string and formats it into valid snake_case."""
78
+ entity_id = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", entity_id)
79
+ entity_id = re.sub(r"([a-z\d])([A-Z])", r"\1_\2", entity_id)
80
+ entity_id = entity_id.replace("-", "_")
81
+ return entity_id.lower()
85
82
 
86
83
  def prepare_entity_id(
87
84
  self,
@@ -100,9 +97,7 @@ class RawWrapper:
100
97
  entity_id = group + "." + slug
101
98
  elif entity_id is None:
102
99
  raise ValueError("Neither group and slug or entity_id provided.")
103
- if self.malformed_id(entity_id):
104
- raise MalformedInputError(f"The entity_id, {entity_id!r}, is malformed")
105
- return entity_id
100
+ return self.format_entity_id(entity_id)
106
101
 
107
102
  @staticmethod
108
103
  def prepare_get_entity_histories_params(
@@ -237,8 +237,8 @@ class RawClient(RawWrapper, JsonProcessingMixin):
237
237
  **payload,
238
238
  ) -> State:
239
239
  """
240
- Sets the state of an entity and it does not have to be backed by a real entity.
241
- Returns the new state afterwards.
240
+ This method sets the representation of a device within Home Assistant and will not communicate with the actual device.
241
+ To communicate with the device, use :py:meth:`homeassistant_api.Service.trigger` or :py:meth:`homeassistant_api.AsyncService.trigger`
242
242
  """
243
243
  entity_id = self.prepare_entity_id(
244
244
  group=group,
@@ -1,61 +1,53 @@
1
+ [build-system]
2
+ build-backend = "poetry.core.masonry.api"
3
+ requires = ["poetry-core>=1.0.0"]
4
+
5
+ [tool]
6
+ [tool.bandit]
7
+ skips = ["B105"]
8
+ [tool.isort]
9
+ profile = "black"
1
10
  [tool.poetry]
2
- name = "HomeAssistant-API"
3
- version = "3.0.2"
4
- description = "Python Wrapper for Homeassistant's REST API"
5
11
  authors = ["GrandMoff100 <minecraftcrusher100@gmail.com>"]
12
+ description = "Python Wrapper for Homeassistant's REST API"
13
+ documentation = "https://homeassistantapi.readthedocs.io"
14
+ homepage = "https://github.com/GrandMoff100/HomeAssistantAPI"
6
15
  license = "GPL-3.0-or-later"
16
+ name = "HomeAssistant-API"
7
17
  readme = "README.md"
8
- homepage = "https://github.com/GrandMoff100/HomeAssistantAPI"
18
+ include = ["homeassistant_api/py.typed"]
9
19
  repository = "https://github.com/GrandMoff100/HomeAssistantAPI"
10
- documentation = "https://homeassistantapi.readthedocs.io"
11
- packages = [
12
- { include = "homeassistant_api" },
13
- ]
14
-
20
+ version = "3.0.3"
15
21
  [tool.poetry.dependencies]
16
- python = "^3.7"
17
- requests = "^2.26.0"
18
- simplejson = "^3.17.6"
22
+ aiohttp = "^3.8.1"
23
+ aiohttp-client-cache = "^0.6.1"
24
+ autodoc-pydantic = "^1.6.1"
19
25
  pydantic = "^1.9.0"
26
+ python = "^3.8"
27
+ requests = "^2.26.0"
20
28
  requests-cache = "^0.9.2"
21
- aiohttp-client-cache = "^0.6.1"
22
- aiohttp = "^3.8.1"
23
-
29
+ simplejson = "^3.17.6"
24
30
  [tool.poetry.dev-dependencies]
25
- mypy = {git = "https://github.com/python/mypy"}
31
+ black = "^21.12b0"
26
32
  flake8 = "^4.0.1"
27
33
  isort = "^5.10.1"
28
- black = "^21.12b0"
34
+ pre-commit = "^2.17.0"
35
+ pylint = "^2.12.2"
29
36
  pytest = "^6.2.5"
37
+ sphinx-autodoc-typehints = "^1.17.0"
38
+ sphinx-rtd-theme = "^1.0.0"
39
+ toml = "^0.10.2"
30
40
  types-docutils = "^0.17.5"
31
41
  types-requests = "^2.27.9"
32
42
  types-simplejson = "^3.17.3"
33
- pylint = "^2.12.2"
34
- sphinx-rtd-theme = "^1.0.0"
35
- toml = "^0.10.2"
36
43
  types-toml = "^0.10.4"
37
- sphinx-autodoc-typehints = "^1.17.0"
38
- pre-commit = "^2.17.0"
39
-
40
- [tool.isort]
41
- profile = "black"
42
-
43
- [tool.pylint.messages_control]
44
- disable = [
45
- "invalid-name",
46
- "duplicate-code",
47
- "no-member",
48
- "too-few-public-methods",
49
- "too-many-arguments"
50
- ]
44
+ mypy = "^0.931"
51
45
 
46
+ [[tool.poetry.packages]]
47
+ include = "homeassistant_api"
48
+ [tool.pylint]
52
49
  [tool.pylint.master]
53
50
  extension-pkg-whitelist = ["pydantic"]
54
51
  ignore-paths = ["examples"]
55
-
56
- [tool.bandit]
57
- skips = ["B105"]
58
-
59
- [build-system]
60
- requires = ["poetry-core>=1.0.0"]
61
- build-backend = "poetry.core.masonry.api"
52
+ [tool.pylint.messages_control]
53
+ disable = ["invalid-name", "duplicate-code", "no-member", "too-few-public-methods", "too-many-arguments"]
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ packages = \
5
+ ['homeassistant_api',
6
+ 'homeassistant_api._async',
7
+ 'homeassistant_api._async.models',
8
+ 'homeassistant_api.models']
9
+
10
+ package_data = \
11
+ {'': ['*']}
12
+
13
+ install_requires = \
14
+ ['aiohttp-client-cache>=0.6.1,<0.7.0',
15
+ 'aiohttp>=3.8.1,<4.0.0',
16
+ 'autodoc-pydantic>=1.6.1,<2.0.0',
17
+ 'pydantic>=1.9.0,<2.0.0',
18
+ 'requests-cache>=0.9.2,<0.10.0',
19
+ 'requests>=2.26.0,<3.0.0',
20
+ 'simplejson>=3.17.6,<4.0.0']
21
+
22
+ setup_kwargs = {
23
+ 'name': 'homeassistant-api',
24
+ 'version': '3.0.3',
25
+ 'description': "Python Wrapper for Homeassistant's REST API",
26
+ 'long_description': '# HomeassistantAPI\n\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/HomeAssistant-API?style=for-the-badge)](https://pypi.org/project/homeassistant_api)\n![GitHub commits since latest release (by date including pre-releases)](https://img.shields.io/github/commits-since/GrandMoff100/HomeassistantAPI/latest/dev?include_prereleases&style=for-the-badge)\n[![Read the Docs (version)](https://img.shields.io/readthedocs/homeassistantapi?style=for-the-badge)](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/GrandMoff100/HomeassistantAPI?style=for-the-badge)](https://github.com/GrandMoff100/HomeassistantAPI/releases)\n\n[![Home Assistant Logo](https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true)](https://home-assistant.io)\n\n## Python wrapper for Homeassistant\'s [REST API](https://developers.home-assistant.io/docs/api/rest/)\n\nHere is a quick example.\n```py\nfrom homeassistant_api import Client\n\nwith Client(\n \'<API Server URL>\',\n \'<Your Long Lived Access-Token>\'\n) as client:\n\n light = client.get_domain("light")\n\n light.turn_on(entity_id=\'light.living_room_lamp\')\n```\nAll the methods also support async!\n\n## Documentation\nAll documentation, API reference, contribution guidelines and pretty much everything else\nyou\'d want to know is on our readthedocs site [here](https://homeassistantapi.readthedocs.io)\n\nIf there is something missing, open an issue and let us know! Thanks!\n\nGo make some cool stuff! Maybe come back and tell us about it in a\n[discussion](https://github.com/GrandMoff100/HomeAssistantAPI/discussions)?\nWe\'d love to hear about how you use our library!!\n\n## License\n\nThis project is under the GNU GPLv3 license, as defined by the Free Software Foundation.\n',
27
+ 'author': 'GrandMoff100',
28
+ 'author_email': 'minecraftcrusher100@gmail.com',
29
+ 'maintainer': None,
30
+ 'maintainer_email': None,
31
+ 'url': 'https://github.com/GrandMoff100/HomeAssistantAPI',
32
+ 'packages': packages,
33
+ 'package_data': package_data,
34
+ 'install_requires': install_requires,
35
+ 'python_requires': '>=3.8,<4.0',
36
+ }
37
+
38
+
39
+ setup(**setup_kwargs)
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['homeassistant_api',
6
- 'homeassistant_api._async',
7
- 'homeassistant_api._async.models',
8
- 'homeassistant_api.models']
9
-
10
- package_data = \
11
- {'': ['*']}
12
-
13
- install_requires = \
14
- ['aiohttp-client-cache>=0.6.1,<0.7.0',
15
- 'aiohttp>=3.8.1,<4.0.0',
16
- 'pydantic>=1.9.0,<2.0.0',
17
- 'requests-cache>=0.9.2,<0.10.0',
18
- 'requests>=2.26.0,<3.0.0',
19
- 'simplejson>=3.17.6,<4.0.0']
20
-
21
- setup_kwargs = {
22
- 'name': 'homeassistant-api',
23
- 'version': '3.0.2',
24
- 'description': "Python Wrapper for Homeassistant's REST API",
25
- 'long_description': '# HomeassistantAPI\n\n![Lines of code](https://img.shields.io/tokei/lines/github/GrandMoff100/HomeassistantAPI?style=for-the-badge)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/HomeAssistant-API?style=for-the-badge)](https://pypi.org/project/homeassistant_api)\n![GitHub commits since latest release (by date including pre-releases)](https://img.shields.io/github/commits-since/GrandMoff100/HomeassistantAPI/latest/dev?include_prereleases&style=for-the-badge)\n[![Read the Docs (version)](https://img.shields.io/readthedocs/homeassistantapi?style=for-the-badge)](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/GrandMoff100/HomeassistantAPI?style=for-the-badge)](https://github.com/GrandMoff100/HomeassistantAPI/releases)\n\n[![Home Assistant Logo](https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true)](https://home-assistant.io)\n\n## Python wrapper for Homeassistant\'s [REST API](https://developers.home-assistant.io/docs/api/rest/)\n\nPlease ⭐️ the repo if you find this project useful or cool!\n\nHere is a quick example.\n```py\nfrom homeassistant_api import Client\n\nwith Client(\n \'<API Server URL>\',\n \'<Your Long Lived Access-Token>\'\n) as client:\n\n light = client.get_domain("light")\n\n light.turn_on(entity_id=\'light.living_room_lamp\')\n```\nAll the methods also support async!\n\n## Documentation\nAll documentation, API reference, contribution guidelines and pretty much everything else\nyou\'d want to know is on our readthedocs site [here](https://homeassistantapi.readthedocs.io)\n\nIf there is something missing, open an issue and let us know! Thanks!\n\nGo make some cool stuff! Maybe come back and tell us about it in a\n[discussion](https://github.com/GrandMoff100/HomeAssistantAPI/discussions)?\nWe\'d love to hear about how you use our library!!\n\n## License\n\nThis project is under the GNU GPLv3 license, as defined by the Free Software Foundation.\n',
26
- 'author': 'GrandMoff100',
27
- 'author_email': 'minecraftcrusher100@gmail.com',
28
- 'maintainer': None,
29
- 'maintainer_email': None,
30
- 'url': 'https://github.com/GrandMoff100/HomeAssistantAPI',
31
- 'packages': packages,
32
- 'package_data': package_data,
33
- 'install_requires': install_requires,
34
- 'python_requires': '>=3.7,<4.0',
35
- }
36
-
37
-
38
- setup(**setup_kwargs)