HomeAssistant-API 4.0.1__tar.gz → 4.1.1__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.1}/PKG-INFO +4 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/README.md +3 -1
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/client.py +9 -5
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/errors.py +6 -4
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/entity.py +2 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/history.py +1 -1
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/processing.py +22 -16
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/rawasyncclient.py +16 -11
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/rawbaseclient.py +2 -2
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/rawclient.py +22 -18
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/pyproject.toml +39 -29
- homeassistant_api-4.0.1/setup.py +0 -35
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/LICENSE +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/__init__.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/__init__.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/base.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/domains.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/events.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/logbook.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/models/states.py +0 -0
- {homeassistant_api-4.0.1 → homeassistant_api-4.1.1}/homeassistant_api/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: homeassistant-api
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.1.1
|
|
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
|
|
|
@@ -19,10 +19,14 @@ class Client(RawClient, RawAsyncClient):
|
|
|
19
19
|
:param async_cache_session: A :py:class:`aiohttp_client_cache.CachedSession` object to use for caching requests. Optional.
|
|
20
20
|
""" # pylint: disable=line-too-long
|
|
21
21
|
|
|
22
|
-
def __init__(
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
*args: Any,
|
|
25
|
+
use_async: bool = False,
|
|
26
|
+
verify_ssl: bool = True,
|
|
27
|
+
**kwargs: Any
|
|
28
|
+
) -> None:
|
|
23
29
|
if use_async:
|
|
24
|
-
|
|
25
|
-
RawAsyncClient.__init__(self, *args, **kwargs)
|
|
30
|
+
RawAsyncClient.__init__(self, *args, verify_ssl=verify_ssl, **kwargs)
|
|
26
31
|
else:
|
|
27
|
-
|
|
28
|
-
RawClient.__init__(self, *args, **kwargs)
|
|
32
|
+
RawClient.__init__(self, *args, verify_ssl=verify_ssl, **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!"
|
|
@@ -53,14 +55,14 @@ class InternalServerError(HomeassistantAPIError):
|
|
|
53
55
|
class UnauthorizedError(HomeassistantAPIError):
|
|
54
56
|
"""Error raised when an invalid token in used to authenticate with homeassistant."""
|
|
55
57
|
|
|
56
|
-
def __init__(self):
|
|
58
|
+
def __init__(self) -> None:
|
|
57
59
|
super().__init__("Invalid authentication token")
|
|
58
60
|
|
|
59
61
|
|
|
60
62
|
class EndpointNotFoundError(HomeassistantAPIError):
|
|
61
63
|
"""Error raised when a request is made to a non existing endpoint."""
|
|
62
64
|
|
|
63
|
-
def __init__(self, path: str):
|
|
65
|
+
def __init__(self, path: str) -> None:
|
|
64
66
|
super().__init__(f"Cannot make request to the endpoint {path!r}")
|
|
65
67
|
|
|
66
68
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Module for Entity and entity Group data models"""
|
|
2
2
|
|
|
3
3
|
from datetime import datetime
|
|
4
|
-
from typing import TYPE_CHECKING, Dict, Optional
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional
|
|
5
5
|
|
|
6
6
|
from pydantic import Field
|
|
7
7
|
|
|
@@ -43,7 +43,7 @@ class Group(BaseModel):
|
|
|
43
43
|
"""Returns Entity with the given name if it exists. Otherwise returns None"""
|
|
44
44
|
return self.entities.get(slug)
|
|
45
45
|
|
|
46
|
-
def __getattr__(self, key: str):
|
|
46
|
+
def __getattr__(self, key: str) -> Any:
|
|
47
47
|
if key in self.entities:
|
|
48
48
|
return self.get_entity(key)
|
|
49
49
|
return super().__getattribute__(key)
|
|
@@ -14,7 +14,7 @@ class History(BaseModel):
|
|
|
14
14
|
..., description="A tuple of previous states of an entity."
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
-
def __init__(self, *args, **kwargs):
|
|
17
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
18
18
|
super().__init__(*args, **kwargs)
|
|
19
19
|
assert self.entity_id is not None
|
|
20
20
|
|
|
@@ -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]:
|
|
@@ -61,7 +62,7 @@ class Processing:
|
|
|
61
62
|
mimetype = self._response.headers.get( # type: ignore [arg-type]
|
|
62
63
|
"content-type",
|
|
63
64
|
"text/plain",
|
|
64
|
-
)
|
|
65
|
+
)
|
|
65
66
|
for processor in self._processors.get(mimetype, ()):
|
|
66
67
|
if not async_ ^ inspect.iscoroutinefunction(processor):
|
|
67
68
|
logger.debug("Using processor %r on %r", processor, self._response)
|
|
@@ -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)
|
|
@@ -101,34 +105,36 @@ class Processing:
|
|
|
101
105
|
|
|
102
106
|
# List of default processors
|
|
103
107
|
@Processing.processor("application/json") # type: ignore[arg-type]
|
|
104
|
-
def process_json(response: ResponseType) ->
|
|
108
|
+
def process_json(response: ResponseType) -> dict[str, Any]:
|
|
105
109
|
"""Returns the json dict content of the response."""
|
|
106
110
|
try:
|
|
107
|
-
return response.json()
|
|
111
|
+
return cast(dict[str, Any], response.json())
|
|
108
112
|
except (json.JSONDecodeError, simplejson.JSONDecodeError) as err:
|
|
109
113
|
raise MalformedDataError(
|
|
110
114
|
f"Home Assistant responded with non-json response: {repr(response.text)}"
|
|
111
115
|
) from err
|
|
112
116
|
|
|
113
117
|
|
|
114
|
-
@Processing.processor("
|
|
118
|
+
@Processing.processor("text/plain") # type: ignore[arg-type]
|
|
119
|
+
@Processing.processor("application/octet-stream")
|
|
115
120
|
def process_text(response: ResponseType) -> str:
|
|
116
121
|
"""Returns the plaintext of the reponse."""
|
|
117
122
|
return response.text
|
|
118
123
|
|
|
119
124
|
|
|
120
125
|
@Processing.processor("application/json") # type: ignore[arg-type]
|
|
121
|
-
async def async_process_json(response: AsyncResponseType) ->
|
|
126
|
+
async def async_process_json(response: AsyncResponseType) -> dict[str, Any]:
|
|
122
127
|
"""Returns the json dict content of the response."""
|
|
123
128
|
try:
|
|
124
|
-
return await response.json()
|
|
129
|
+
return cast(dict[str, Any], await response.json())
|
|
125
130
|
except (json.JSONDecodeError, simplejson.JSONDecodeError) as err:
|
|
126
131
|
raise MalformedDataError(
|
|
127
132
|
f"Home Assistant responded with non-json response: {repr(await response.text())}"
|
|
128
133
|
) from err
|
|
129
134
|
|
|
130
135
|
|
|
131
|
-
@Processing.processor("
|
|
136
|
+
@Processing.processor("text/plain") # type: ignore[arg-type]
|
|
137
|
+
@Processing.processor("application/octet-stream")
|
|
132
138
|
async def async_process_text(response: AsyncResponseType) -> str:
|
|
133
139
|
"""Returns the plaintext of the reponse."""
|
|
134
140
|
return await response.text()
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"""Module for interacting with Home Assistant asyncronously."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
2
4
|
import asyncio
|
|
3
5
|
import json
|
|
4
6
|
import logging
|
|
@@ -54,17 +56,20 @@ class RawAsyncClient(RawBaseClient):
|
|
|
54
56
|
Literal[False],
|
|
55
57
|
Literal[None],
|
|
56
58
|
] = None, # Explicitly disable cache with async_cache_session=False
|
|
59
|
+
verify_ssl: bool = True,
|
|
57
60
|
**kwargs,
|
|
58
61
|
):
|
|
59
62
|
RawBaseClient.__init__(self, *args, **kwargs)
|
|
63
|
+
connector = aiohttp.TCPConnector(verify_ssl=False) if not verify_ssl else None
|
|
60
64
|
if async_cache_session is False:
|
|
61
|
-
self.async_cache_session = aiohttp.ClientSession()
|
|
65
|
+
self.async_cache_session = aiohttp.ClientSession(connector=connector)
|
|
62
66
|
elif async_cache_session is None:
|
|
63
|
-
self.async_cache_session = aiohttp_client_cache.CachedSession(
|
|
64
|
-
cache=aiohttp_client_cache.CacheBackend(
|
|
67
|
+
self.async_cache_session = aiohttp_client_cache.CachedSession( # type: ignore[attr-defined]
|
|
68
|
+
cache=aiohttp_client_cache.CacheBackend( # type: ignore[attr-defined]
|
|
65
69
|
cache_name="default_async_cache",
|
|
66
70
|
expire_after=300,
|
|
67
71
|
),
|
|
72
|
+
connector=connector,
|
|
68
73
|
)
|
|
69
74
|
else:
|
|
70
75
|
self.async_cache_session = async_cache_session
|
|
@@ -155,14 +160,14 @@ class RawAsyncClient(RawBaseClient):
|
|
|
155
160
|
for states in data:
|
|
156
161
|
yield History.parse_obj({"states": states})
|
|
157
162
|
|
|
158
|
-
async def async_get_rendered_template(self, template: str):
|
|
163
|
+
async def async_get_rendered_template(self, template: str) -> str:
|
|
159
164
|
"""Renders a given Jinja2 template string with Home Assistant context data."""
|
|
160
165
|
try:
|
|
161
|
-
return await self.async_request(
|
|
166
|
+
return cast(str, await self.async_request(
|
|
162
167
|
"template",
|
|
163
168
|
json=dict(template=template),
|
|
164
169
|
method="POST",
|
|
165
|
-
)
|
|
170
|
+
))
|
|
166
171
|
except RequestError as err:
|
|
167
172
|
raise BadTemplateError(
|
|
168
173
|
"Your template is invalid. "
|
|
@@ -208,9 +213,9 @@ class RawAsyncClient(RawBaseClient):
|
|
|
208
213
|
|
|
209
214
|
async def async_get_entity(
|
|
210
215
|
self,
|
|
211
|
-
group_id: str = None,
|
|
212
|
-
slug: str = None,
|
|
213
|
-
entity_id: str = None,
|
|
216
|
+
group_id: str | None = None,
|
|
217
|
+
slug: str | None = None,
|
|
218
|
+
entity_id: str | None = None,
|
|
214
219
|
) -> Optional[Entity]:
|
|
215
220
|
"""Returns a Entity model for an :code:`entity_id`"""
|
|
216
221
|
if group_id is not None and slug is not None:
|
|
@@ -311,14 +316,14 @@ class RawAsyncClient(RawBaseClient):
|
|
|
311
316
|
return event
|
|
312
317
|
return None
|
|
313
318
|
|
|
314
|
-
async def async_fire_event(self, event_type: str, **event_data) -> str:
|
|
319
|
+
async def async_fire_event(self, event_type: str, **event_data: Any) -> str:
|
|
315
320
|
"""Fires a given event_type within homeassistant. Must be an existing event_type."""
|
|
316
321
|
data = await self.async_request(
|
|
317
322
|
join("events", event_type),
|
|
318
323
|
method="POST",
|
|
319
324
|
json=event_data,
|
|
320
325
|
)
|
|
321
|
-
return data.get("message", "No message provided")
|
|
326
|
+
return cast(str, data.get("message", "No message provided"))
|
|
322
327
|
|
|
323
328
|
async def async_get_components(self) -> Tuple[str, ...]:
|
|
324
329
|
"""Returns a tuple of all registered components."""
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import re
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from posixpath import join
|
|
6
|
-
from typing import Dict, Iterable, Optional, Tuple, Union
|
|
6
|
+
from typing import Dict, Iterable, Optional, Tuple, Union, Any
|
|
7
7
|
|
|
8
8
|
from .models import Entity
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ class RawBaseClient:
|
|
|
13
13
|
|
|
14
14
|
api_url: str
|
|
15
15
|
token: str
|
|
16
|
-
global_request_kwargs: Dict[str,
|
|
16
|
+
global_request_kwargs: Dict[str, Any]
|
|
17
17
|
|
|
18
18
|
def __init__(
|
|
19
19
|
self,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Module for all interaction with homeassistant."""
|
|
2
|
+
from __future__ import annotations
|
|
2
3
|
|
|
3
4
|
import json
|
|
4
5
|
import logging
|
|
@@ -53,13 +54,15 @@ class RawClient(RawBaseClient):
|
|
|
53
54
|
Literal[False],
|
|
54
55
|
Literal[None],
|
|
55
56
|
] = None, # Explicitly disable cache with cache_session=False
|
|
57
|
+
verify_ssl: bool = True,
|
|
56
58
|
**kwargs,
|
|
57
59
|
):
|
|
58
60
|
RawBaseClient.__init__(self, *args, **kwargs)
|
|
61
|
+
self.global_request_kwargs["verify"] = verify_ssl
|
|
59
62
|
if cache_session is False:
|
|
60
63
|
self.cache_session = requests.Session()
|
|
61
64
|
elif cache_session is None:
|
|
62
|
-
self.cache_session = requests_cache.CachedSession(
|
|
65
|
+
self.cache_session = requests_cache.CachedSession( # type: ignore[attr-defined]
|
|
63
66
|
cache_name="default_cache",
|
|
64
67
|
backend="memory",
|
|
65
68
|
expire_after=300,
|
|
@@ -67,22 +70,23 @@ class RawClient(RawBaseClient):
|
|
|
67
70
|
else:
|
|
68
71
|
self.cache_session = cache_session
|
|
69
72
|
|
|
70
|
-
def __enter__(self):
|
|
73
|
+
def __enter__(self) -> "RawClient":
|
|
71
74
|
logger.debug("Entering cached requests session %r.", self.cache_session)
|
|
72
75
|
self.cache_session.__enter__()
|
|
73
76
|
self.check_api_running()
|
|
74
77
|
self.check_api_config()
|
|
75
78
|
return self
|
|
76
79
|
|
|
77
|
-
def __exit__(self, _, __, ___):
|
|
80
|
+
def __exit__(self, _, __, ___) -> None:
|
|
78
81
|
logger.debug("Exiting requests session %r", self.cache_session)
|
|
79
82
|
self.cache_session.close()
|
|
80
83
|
|
|
81
84
|
def request(
|
|
82
85
|
self,
|
|
83
|
-
path,
|
|
86
|
+
path: str,
|
|
84
87
|
method="GET",
|
|
85
|
-
headers: Dict[str, str] = None,
|
|
88
|
+
headers: Dict[str, str] | None = None,
|
|
89
|
+
decode_bytes: bool = True,
|
|
86
90
|
**kwargs,
|
|
87
91
|
) -> Any:
|
|
88
92
|
"""Base method for making requests to the api"""
|
|
@@ -101,12 +105,12 @@ class RawClient(RawBaseClient):
|
|
|
101
105
|
raise RequestTimeoutError(
|
|
102
106
|
f'Home Assistant did not respond in time (timeout: {kwargs.get("timeout", 300)} sec)'
|
|
103
107
|
) from err
|
|
104
|
-
return self.response_logic(resp)
|
|
108
|
+
return self.response_logic(response=resp, decode_bytes=decode_bytes)
|
|
105
109
|
|
|
106
110
|
@classmethod
|
|
107
|
-
def response_logic(cls, response: ResponseType) -> Any:
|
|
111
|
+
def response_logic(cls, response: ResponseType, decode_bytes: bool = True) -> Any:
|
|
108
112
|
"""Processes responses from the API and formats them"""
|
|
109
|
-
return Processing(response=response).process()
|
|
113
|
+
return Processing(response=response, decode_bytes=decode_bytes).process()
|
|
110
114
|
|
|
111
115
|
# API information methods
|
|
112
116
|
def get_error_log(self) -> str:
|
|
@@ -201,7 +205,7 @@ class RawClient(RawBaseClient):
|
|
|
201
205
|
group_id, entity_slug = state.entity_id.split(".")
|
|
202
206
|
if group_id not in entities:
|
|
203
207
|
entities[group_id] = Group(
|
|
204
|
-
group_id=
|
|
208
|
+
group_id=group_id,
|
|
205
209
|
_client=self, # type: ignore[arg-type]
|
|
206
210
|
)
|
|
207
211
|
entities[group_id]._add_entity(entity_slug, state)
|
|
@@ -209,9 +213,9 @@ class RawClient(RawBaseClient):
|
|
|
209
213
|
|
|
210
214
|
def get_entity(
|
|
211
215
|
self,
|
|
212
|
-
group_id: str = None,
|
|
213
|
-
slug: str = None,
|
|
214
|
-
entity_id: str = None,
|
|
216
|
+
group_id: str | None = None,
|
|
217
|
+
slug: str | None = None,
|
|
218
|
+
entity_id: str | None = None,
|
|
215
219
|
) -> Optional[Entity]:
|
|
216
220
|
"""Returns an :py:class:`Entity` model for an :code:`entity_id`"""
|
|
217
221
|
if group_id is not None and slug is not None:
|
|
@@ -228,15 +232,15 @@ class RawClient(RawBaseClient):
|
|
|
228
232
|
)
|
|
229
233
|
split_group_id, split_slug = state.entity_id.split(".")
|
|
230
234
|
group = Group(
|
|
231
|
-
group_id=
|
|
235
|
+
group_id=split_group_id,
|
|
232
236
|
_client=self, # type: ignore[arg-type]
|
|
233
237
|
)
|
|
234
|
-
group._add_entity(
|
|
235
|
-
return group.get_entity(
|
|
238
|
+
group._add_entity(split_slug, state)
|
|
239
|
+
return group.get_entity(split_slug)
|
|
236
240
|
|
|
237
241
|
# Services and domain methods
|
|
238
242
|
def get_domains(self) -> Dict[str, Domain]:
|
|
239
|
-
"""Fetches all :py:class:`Service`s from the API."""
|
|
243
|
+
"""Fetches all :py:class:`Service` 's from the API."""
|
|
240
244
|
data = self.request("services")
|
|
241
245
|
domains = map(
|
|
242
246
|
lambda json: Domain.from_json(json, client=cast(Client, self)),
|
|
@@ -245,7 +249,7 @@ class RawClient(RawBaseClient):
|
|
|
245
249
|
return {domain.domain_id: domain for domain in domains}
|
|
246
250
|
|
|
247
251
|
def get_domain(self, domain_id: str) -> Optional[Domain]:
|
|
248
|
-
"""Fetches all
|
|
252
|
+
"""Fetches all :py:class:`Service`'s under a particular service :py:class:`Domain`."""
|
|
249
253
|
return self.get_domains().get(domain_id)
|
|
250
254
|
|
|
251
255
|
def trigger_service(
|
|
@@ -325,7 +329,7 @@ class RawClient(RawBaseClient):
|
|
|
325
329
|
method="POST",
|
|
326
330
|
json=event_data,
|
|
327
331
|
)
|
|
328
|
-
return cast(dict, data).get("message")
|
|
332
|
+
return cast(dict[str, Any], data).get("message")
|
|
329
333
|
|
|
330
334
|
def get_components(self) -> Tuple[str, ...]:
|
|
331
335
|
"""Returns a tuple of all registered components."""
|
|
@@ -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.
|
|
15
|
+
version = "4.1.1"
|
|
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,29 @@ 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']
|
|
90
|
+
|
|
91
|
+
[tool.isort]
|
|
92
|
+
profile = "black"
|
|
93
|
+
|
|
94
|
+
[tool.mypy]
|
|
95
|
+
disable_error_code = [
|
|
96
|
+
"no-untyped-def",
|
|
97
|
+
"name-defined",
|
|
98
|
+
]
|
homeassistant_api-4.0.1/setup.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['homeassistant_api', 'homeassistant_api.models']
|
|
6
|
-
|
|
7
|
-
package_data = \
|
|
8
|
-
{'': ['*']}
|
|
9
|
-
|
|
10
|
-
install_requires = \
|
|
11
|
-
['aiohttp-client-cache>=0.6.1,<0.7.0',
|
|
12
|
-
'aiohttp>=3.8.1,<4.0.0',
|
|
13
|
-
'pydantic<=1.9.0',
|
|
14
|
-
'requests-cache>=0.9.2,<0.10.0',
|
|
15
|
-
'requests>=2.27.1,<3.0.0',
|
|
16
|
-
'simplejson>=3.17.6,<4.0.0']
|
|
17
|
-
|
|
18
|
-
setup_kwargs = {
|
|
19
|
-
'name': 'homeassistant-api',
|
|
20
|
-
'version': '4.0.1',
|
|
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[](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\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
|
-
'author': 'GrandMoff100',
|
|
24
|
-
'author_email': 'minecraftcrusher100@gmail.com',
|
|
25
|
-
'maintainer': 'None',
|
|
26
|
-
'maintainer_email': 'None',
|
|
27
|
-
'url': 'https://github.com/GrandMoff100/HomeAssistantAPI',
|
|
28
|
-
'packages': packages,
|
|
29
|
-
'package_data': package_data,
|
|
30
|
-
'install_requires': install_requires,
|
|
31
|
-
'python_requires': '>=3.7,<4.0',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
setup(**setup_kwargs)
|
|
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
|