HomeAssistant-API 4.0.1__tar.gz → 4.1.0__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.
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/PKG-INFO +4 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/README.md +3 -1
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/client.py +0 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/errors.py +4 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/processing.py +15 -9
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/rawclient.py +6 -5
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/pyproject.toml +30 -29
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/setup.py +2 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/LICENSE +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/__init__.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/__init__.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/base.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/domains.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/entity.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/events.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/history.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/logbook.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/models/states.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/py.typed +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/rawasyncclient.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.0}/homeassistant_api/rawbaseclient.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: homeassistant-api
|
|
3
|
-
Version: 4.0
|
|
3
|
+
Version: 4.1.0
|
|
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
|
|
@@ -32,7 +32,9 @@ Description-Content-Type: text/markdown
|
|
|
32
32
|
[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
|
|
33
33
|
[](https://github.com/GrandMoff100/HomeassistantAPI/releases)
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
<a href="https://home-assistant.io">
|
|
36
|
+
<img src="https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true" width="60%">
|
|
37
|
+
</a>
|
|
36
38
|
|
|
37
39
|
## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
|
|
38
40
|
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
|
|
7
7
|
[](https://github.com/GrandMoff100/HomeassistantAPI/releases)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<a href="https://home-assistant.io">
|
|
10
|
+
<img src="https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true" width="60%">
|
|
11
|
+
</a>
|
|
10
12
|
|
|
11
13
|
## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
|
|
12
14
|
|
|
@@ -21,8 +21,6 @@ class Client(RawClient, RawAsyncClient):
|
|
|
21
21
|
|
|
22
22
|
def __init__(self, *args: Any, use_async: bool = False, **kwargs: Any) -> None:
|
|
23
23
|
if use_async:
|
|
24
|
-
logger.error("Initializing Client asyncsyncronously")
|
|
25
24
|
RawAsyncClient.__init__(self, *args, **kwargs)
|
|
26
25
|
else:
|
|
27
|
-
logger.error("Initializing Client syncronously")
|
|
28
26
|
RawClient.__init__(self, *args, **kwargs)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Module for custom error classes"""
|
|
2
2
|
|
|
3
|
+
from typing import Union
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class HomeassistantAPIError(BaseException):
|
|
5
7
|
"""Base class for custom errors"""
|
|
@@ -40,10 +42,10 @@ class ParameterMissingError(HomeassistantAPIError):
|
|
|
40
42
|
class InternalServerError(HomeassistantAPIError):
|
|
41
43
|
"""Error raised when Home Assistant says that it got itself in trouble."""
|
|
42
44
|
|
|
43
|
-
def __init__(self, status_code: int, content: str) -> None:
|
|
45
|
+
def __init__(self, status_code: int, content: Union[str, bytes]) -> None:
|
|
44
46
|
super().__init__(
|
|
45
47
|
f"Home Assistant returned a response with an error status code {status_code!r}.\n"
|
|
46
|
-
f"{content}\n"
|
|
48
|
+
f"{content!r}\n"
|
|
47
49
|
"If this happened, "
|
|
48
50
|
"please report it at https://github.com/GrandMoff100/HomeAssistantAPI/issues "
|
|
49
51
|
"with the request status code and the request content. Thanks!"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Module for processing responses from homeassistant."""
|
|
1
|
+
"""Module for processing API responses from homeassistant."""
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
4
|
import json
|
|
@@ -37,8 +37,9 @@ class Processing:
|
|
|
37
37
|
_response: AllResponseType
|
|
38
38
|
_processors: ClassVar[Dict[str, Tuple[ProcessorType, ...]]] = {}
|
|
39
39
|
|
|
40
|
-
def __init__(self, response: AllResponseType) -> None:
|
|
40
|
+
def __init__(self, response: AllResponseType, decode_bytes: bool = True) -> None:
|
|
41
41
|
self._response = response
|
|
42
|
+
self._decode_bytes = decode_bytes
|
|
42
43
|
|
|
43
44
|
@staticmethod
|
|
44
45
|
def processor(mimetype: str) -> Callable[[ProcessorType], ProcessorType]:
|
|
@@ -72,13 +73,17 @@ class Processing:
|
|
|
72
73
|
|
|
73
74
|
def process(self) -> Any:
|
|
74
75
|
"""Validates the http status code before starting to process the repsonse content"""
|
|
76
|
+
content: Union[str, bytes]
|
|
75
77
|
if async_ := isinstance(self._response, (ClientResponse, AsyncCachedResponse)):
|
|
76
78
|
status_code = self._response.status
|
|
77
79
|
_buffer = self._response.content._buffer
|
|
78
|
-
content = "" if not _buffer else _buffer[0]
|
|
80
|
+
content = b"" if not _buffer else _buffer[0]
|
|
79
81
|
elif isinstance(self._response, (Response, CachedResponse)):
|
|
80
82
|
status_code = self._response.status_code
|
|
81
|
-
content = self._response.content
|
|
83
|
+
content = self._response.content
|
|
84
|
+
if self._decode_bytes and isinstance(content, bytes):
|
|
85
|
+
content = content.decode()
|
|
86
|
+
|
|
82
87
|
if status_code in (200, 201):
|
|
83
88
|
return self.process_content(async_=async_)
|
|
84
89
|
if status_code == 400:
|
|
@@ -88,11 +93,10 @@ class Processing:
|
|
|
88
93
|
if status_code == 404:
|
|
89
94
|
raise EndpointNotFoundError(str(self._response.url))
|
|
90
95
|
if status_code == 405:
|
|
91
|
-
|
|
92
|
-
self._response.request.method
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
96
|
+
if isinstance(self._response, (Response, CachedResponse)):
|
|
97
|
+
method = self._response.request.method
|
|
98
|
+
else:
|
|
99
|
+
method = self._response.method
|
|
96
100
|
raise MethodNotAllowedError(cast(str, method))
|
|
97
101
|
if status_code >= 500:
|
|
98
102
|
raise InternalServerError(status_code, content)
|
|
@@ -111,6 +115,7 @@ def process_json(response: ResponseType) -> Dict[str, Any]:
|
|
|
111
115
|
) from err
|
|
112
116
|
|
|
113
117
|
|
|
118
|
+
@Processing.processor("text/plain") # type: ignore[arg-type]
|
|
114
119
|
@Processing.processor("application/octet-stream") # type: ignore[arg-type]
|
|
115
120
|
def process_text(response: ResponseType) -> str:
|
|
116
121
|
"""Returns the plaintext of the reponse."""
|
|
@@ -128,6 +133,7 @@ async def async_process_json(response: AsyncResponseType) -> Dict[str, Any]:
|
|
|
128
133
|
) from err
|
|
129
134
|
|
|
130
135
|
|
|
136
|
+
@Processing.processor("text/plain") # type: ignore[arg-type]
|
|
131
137
|
@Processing.processor("application/octet-stream") # type: ignore[arg-type]
|
|
132
138
|
async def async_process_text(response: AsyncResponseType) -> str:
|
|
133
139
|
"""Returns the plaintext of the reponse."""
|
|
@@ -83,6 +83,7 @@ class RawClient(RawBaseClient):
|
|
|
83
83
|
path,
|
|
84
84
|
method="GET",
|
|
85
85
|
headers: Dict[str, str] = None,
|
|
86
|
+
decode_bytes: bool = True,
|
|
86
87
|
**kwargs,
|
|
87
88
|
) -> Any:
|
|
88
89
|
"""Base method for making requests to the api"""
|
|
@@ -101,12 +102,12 @@ class RawClient(RawBaseClient):
|
|
|
101
102
|
raise RequestTimeoutError(
|
|
102
103
|
f'Home Assistant did not respond in time (timeout: {kwargs.get("timeout", 300)} sec)'
|
|
103
104
|
) from err
|
|
104
|
-
return self.response_logic(resp)
|
|
105
|
+
return self.response_logic(response=resp, decode_bytes=decode_bytes)
|
|
105
106
|
|
|
106
107
|
@classmethod
|
|
107
|
-
def response_logic(cls, response: ResponseType) -> Any:
|
|
108
|
+
def response_logic(cls, response: ResponseType, decode_bytes: bool = True) -> Any:
|
|
108
109
|
"""Processes responses from the API and formats them"""
|
|
109
|
-
return Processing(response=response).process()
|
|
110
|
+
return Processing(response=response, decode_bytes=decode_bytes).process()
|
|
110
111
|
|
|
111
112
|
# API information methods
|
|
112
113
|
def get_error_log(self) -> str:
|
|
@@ -236,7 +237,7 @@ class RawClient(RawBaseClient):
|
|
|
236
237
|
|
|
237
238
|
# Services and domain methods
|
|
238
239
|
def get_domains(self) -> Dict[str, Domain]:
|
|
239
|
-
"""Fetches all :py:class:`Service`s from the API."""
|
|
240
|
+
"""Fetches all :py:class:`Service` 's from the API."""
|
|
240
241
|
data = self.request("services")
|
|
241
242
|
domains = map(
|
|
242
243
|
lambda json: Domain.from_json(json, client=cast(Client, self)),
|
|
@@ -245,7 +246,7 @@ class RawClient(RawBaseClient):
|
|
|
245
246
|
return {domain.domain_id: domain for domain in domains}
|
|
246
247
|
|
|
247
248
|
def get_domain(self, domain_id: str) -> Optional[Domain]:
|
|
248
|
-
"""Fetches all
|
|
249
|
+
"""Fetches all :py:class:`Service`'s under a particular service :py:class:`Domain`."""
|
|
249
250
|
return self.get_domains().get(domain_id)
|
|
250
251
|
|
|
251
252
|
def trigger_service(
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
build-backend = "poetry.core.masonry.api"
|
|
3
3
|
requires = ["poetry-core>=1.0.0"]
|
|
4
4
|
|
|
5
|
-
[tool.bandit]
|
|
6
|
-
skips = ["B105"]
|
|
7
|
-
|
|
8
|
-
[tool.isort]
|
|
9
|
-
profile = "black"
|
|
10
|
-
|
|
11
5
|
[tool.poetry]
|
|
12
6
|
authors = ["GrandMoff100 <minecraftcrusher100@gmail.com>"]
|
|
13
7
|
description = "Python Wrapper for Homeassistant's REST API"
|
|
@@ -18,7 +12,7 @@ name = "HomeAssistant-API"
|
|
|
18
12
|
readme = "README.md"
|
|
19
13
|
include = ["homeassistant_api/py.typed"]
|
|
20
14
|
repository = "https://github.com/GrandMoff100/HomeAssistantAPI"
|
|
21
|
-
version = "4.0
|
|
15
|
+
version = "4.1.0"
|
|
22
16
|
packages = [{ include = "homeassistant_api" }]
|
|
23
17
|
|
|
24
18
|
[tool.poetry.dependencies]
|
|
@@ -37,37 +31,27 @@ optional = true
|
|
|
37
31
|
sphinx-autodoc-typehints = "^1.17.0"
|
|
38
32
|
sphinx-rtd-theme = "^1.0.0"
|
|
39
33
|
autodoc-pydantic = "^1.6.1"
|
|
40
|
-
toml = "^0.10.2"
|
|
41
34
|
|
|
42
|
-
[tool.poetry.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
[tool.poetry.group.styling]
|
|
36
|
+
optional = true
|
|
37
|
+
|
|
38
|
+
[tool.poetry.group.styling.dependencies]
|
|
46
39
|
pre-commit = "^2.17.0"
|
|
47
|
-
pylint = "^2.12.2"
|
|
48
|
-
pytest = "^6.2.5"
|
|
49
|
-
toml = "^0.10.2"
|
|
50
40
|
types-docutils = "^0.17.5"
|
|
51
41
|
types-requests = "^2.27.9"
|
|
52
42
|
types-simplejson = "^3.17.3"
|
|
53
43
|
types-toml = "^0.10.4"
|
|
54
44
|
mypy = "^0.931"
|
|
55
|
-
|
|
56
|
-
pytest-cov = "^3.0.0"
|
|
57
|
-
aiosqlite = "^0.17.0"
|
|
45
|
+
ruff = "^0.0.209"
|
|
58
46
|
|
|
59
|
-
[tool.
|
|
60
|
-
|
|
61
|
-
ignore-paths = ["examples"]
|
|
62
|
-
|
|
63
|
-
[tool.pylint.messages_control]
|
|
64
|
-
disable = [
|
|
65
|
-
"duplicate-code",
|
|
66
|
-
"too-many-public-methods",
|
|
67
|
-
"too-many-arguments",
|
|
68
|
-
"protected-access"
|
|
69
|
-
]
|
|
47
|
+
[tool.poetry.group.testing]
|
|
48
|
+
optional = true
|
|
70
49
|
|
|
50
|
+
[tool.poetry.group.testing.dependencies]
|
|
51
|
+
pytest-asyncio = "^0.18.3"
|
|
52
|
+
pytest-cov = "^3.0.0"
|
|
53
|
+
pytest = "^6.2.5"
|
|
54
|
+
aiosqlite = "^0.18.0"
|
|
71
55
|
|
|
72
56
|
[tool.pytest.ini_options]
|
|
73
57
|
asyncio_mode = "auto"
|
|
@@ -86,3 +70,20 @@ exclude_lines = [
|
|
|
86
70
|
"last_updated < \\(now := datetime\\.now\\(\\)\\) - wait",
|
|
87
71
|
"pragma: no cover"
|
|
88
72
|
]
|
|
73
|
+
|
|
74
|
+
[tool.ruff]
|
|
75
|
+
exclude = [
|
|
76
|
+
'.git',
|
|
77
|
+
'__pycache__',
|
|
78
|
+
'.github',
|
|
79
|
+
]
|
|
80
|
+
ignore = ['E501']
|
|
81
|
+
select = [
|
|
82
|
+
'E',
|
|
83
|
+
'F',
|
|
84
|
+
'W',
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[tool.ruff.per-file-ignores]
|
|
88
|
+
"__init__.py" = ['F401']
|
|
89
|
+
"conf.py" = ['E402']
|
|
@@ -17,9 +17,9 @@ install_requires = \
|
|
|
17
17
|
|
|
18
18
|
setup_kwargs = {
|
|
19
19
|
'name': 'homeassistant-api',
|
|
20
|
-
'version': '4.0
|
|
20
|
+
'version': '4.1.0',
|
|
21
21
|
'description': "Python Wrapper for Homeassistant's REST API",
|
|
22
|
-
'long_description': '# HomeassistantAPI\n\n[](https://codecov.io/gh/GrandMoff100/HomeAssistantAPI)\n[](https://pypi.org/project/homeassistant_api)\n\n[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)\n[](https://github.com/GrandMoff100/HomeassistantAPI/releases)\n\n
|
|
22
|
+
'long_description': '# HomeassistantAPI\n\n[](https://codecov.io/gh/GrandMoff100/HomeAssistantAPI)\n[](https://pypi.org/project/homeassistant_api)\n\n[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)\n[](https://github.com/GrandMoff100/HomeassistantAPI/releases)\n\n<a href="https://home-assistant.io">\n <img src="https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true" width="60%">\n</a>\n\n## Python wrapper for Homeassistant\'s [REST API](https://developers.home-assistant.io/docs/api/rest/)\n\nHere is a quick example.\n\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```\n\nAll the methods also support async!\n\n## Documentation\n\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',
|
|
23
23
|
'author': 'GrandMoff100',
|
|
24
24
|
'author_email': 'minecraftcrusher100@gmail.com',
|
|
25
25
|
'maintainer': 'None',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|