HomeAssistant-API 3.0.3.post2__py3-none-any.whl → 3.0.3.post3__py3-none-any.whl
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/_async/asyncclient.py +8 -2
- homeassistant_api/processing.py +4 -0
- homeassistant_api/rawapi.py +4 -4
- homeassistant_api/rawclient.py +6 -0
- {homeassistant_api-3.0.3.post2.dist-info → homeassistant_api-3.0.3.post3.dist-info}/METADATA +1 -1
- {homeassistant_api-3.0.3.post2.dist-info → homeassistant_api-3.0.3.post3.dist-info}/RECORD +8 -8
- {homeassistant_api-3.0.3.post2.dist-info → homeassistant_api-3.0.3.post3.dist-info}/LICENSE +0 -0
- {homeassistant_api-3.0.3.post2.dist-info → homeassistant_api-3.0.3.post3.dist-info}/WHEEL +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Module for interacting with Home Assistant asyncronously."""
|
|
2
2
|
import asyncio
|
|
3
|
+
import logging
|
|
3
4
|
from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union, cast
|
|
4
5
|
from urllib.parse import urljoin as join
|
|
5
6
|
|
|
@@ -13,6 +14,8 @@ from ..processing import Processing
|
|
|
13
14
|
from ..rawapi import RawWrapper
|
|
14
15
|
from .models import AsyncEntity, AsyncGroup
|
|
15
16
|
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
class RawAsyncClient(RawWrapper, JsonProcessingMixin):
|
|
18
21
|
"""
|
|
@@ -26,7 +29,10 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
|
|
|
26
29
|
_async_session: Optional[CachedSession] = None
|
|
27
30
|
|
|
28
31
|
async def __aenter__(self):
|
|
29
|
-
self._async_session = CachedSession(
|
|
32
|
+
self._async_session = CachedSession(
|
|
33
|
+
expire_after=self.cache_expire_after, cache=self.cache_backend
|
|
34
|
+
)
|
|
35
|
+
logger.debug(f"Entering cached requests session {self._async_session!r}")
|
|
30
36
|
await self._async_session.__aenter__()
|
|
31
37
|
await self.async_check_api_running()
|
|
32
38
|
return self
|
|
@@ -197,7 +203,7 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
|
|
|
197
203
|
) -> List[State]:
|
|
198
204
|
"""Tells Home Assistant to trigger a service, returns stats changed while being called"""
|
|
199
205
|
data = await self.async_request(
|
|
200
|
-
|
|
206
|
+
f"services/{domain}/{service}",
|
|
201
207
|
method="POST",
|
|
202
208
|
json=service_data,
|
|
203
209
|
)
|
homeassistant_api/processing.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
4
|
import json
|
|
5
|
+
import logging
|
|
5
6
|
import sys
|
|
6
7
|
from typing import Any, Callable, ClassVar, Dict, Tuple, Union, cast
|
|
7
8
|
|
|
@@ -22,6 +23,8 @@ from .errors import (
|
|
|
22
23
|
)
|
|
23
24
|
from .models import BaseModel
|
|
24
25
|
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
25
28
|
|
|
26
29
|
class Processing(BaseModel):
|
|
27
30
|
"""Uses to processor functions to convert json data into common python data types."""
|
|
@@ -49,6 +52,7 @@ class Processing(BaseModel):
|
|
|
49
52
|
mimetype = self.response.headers.get("content-type", "text/plain") # type: ignore[arg-type]
|
|
50
53
|
for processor in self._processors.get(mimetype, ()):
|
|
51
54
|
if not _async ^ inspect.iscoroutinefunction(processor):
|
|
55
|
+
logger.debug(f"Using processor {processor!r} on {self.response!r}")
|
|
52
56
|
return processor(self.response)
|
|
53
57
|
if _async:
|
|
54
58
|
raise ProcessorNotFoundError(
|
homeassistant_api/rawapi.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""Module for parent RawWrapper class"""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
import re
|
|
5
4
|
from datetime import datetime
|
|
6
5
|
from typing import Dict, Optional, Tuple, Union
|
|
6
|
+
from urllib.parse import urljoin as join
|
|
7
7
|
|
|
8
8
|
from .const import DATE_FMT
|
|
9
9
|
from .models import Entity
|
|
@@ -42,7 +42,7 @@ class RawWrapper:
|
|
|
42
42
|
|
|
43
43
|
def endpoint(self, path: str) -> str:
|
|
44
44
|
"""Joins the api base url with a local path to an absolute url"""
|
|
45
|
-
return
|
|
45
|
+
return join(self.api_url, path)
|
|
46
46
|
|
|
47
47
|
@property
|
|
48
48
|
def _headers(self) -> Dict[str, str]:
|
|
@@ -122,7 +122,7 @@ class RawWrapper:
|
|
|
122
122
|
if start_timestamp is not None:
|
|
123
123
|
if isinstance(start_timestamp, datetime):
|
|
124
124
|
formatted_timestamp = start_timestamp.strftime(DATE_FMT)
|
|
125
|
-
url =
|
|
125
|
+
url = join("history/period", formatted_timestamp)
|
|
126
126
|
else:
|
|
127
127
|
raise TypeError(f"timestamp needs to be of type {datetime!r}")
|
|
128
128
|
else:
|
|
@@ -148,7 +148,7 @@ class RawWrapper:
|
|
|
148
148
|
if start_timestamp is not None:
|
|
149
149
|
if isinstance(start_timestamp, datetime):
|
|
150
150
|
formatted_timestamp = start_timestamp.strftime(DATE_FMT)
|
|
151
|
-
url =
|
|
151
|
+
url = join("logbook", formatted_timestamp)
|
|
152
152
|
else:
|
|
153
153
|
url = "logbook"
|
|
154
154
|
return params, url
|
homeassistant_api/rawclient.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Module for all interaction with homeassistant."""
|
|
2
2
|
|
|
3
|
+
import logging
|
|
3
4
|
from typing import Any, Dict, Generator, List, Optional, Tuple, Union, cast
|
|
4
5
|
from urllib.parse import urljoin as join
|
|
5
6
|
|
|
@@ -12,6 +13,8 @@ from .models import Domain, Entity, Event, Group, History, LogbookEntry, State
|
|
|
12
13
|
from .processing import Processing
|
|
13
14
|
from .rawapi import RawWrapper
|
|
14
15
|
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
15
18
|
|
|
16
19
|
class RawClient(RawWrapper, JsonProcessingMixin):
|
|
17
20
|
"""
|
|
@@ -29,12 +32,14 @@ class RawClient(RawWrapper, JsonProcessingMixin):
|
|
|
29
32
|
expire_after=self.cache_expire_after,
|
|
30
33
|
backend=self.cache_backend,
|
|
31
34
|
)
|
|
35
|
+
logger.debug(f"Entering cached requests session {self._session!r}")
|
|
32
36
|
self._session.__enter__()
|
|
33
37
|
self.check_api_running()
|
|
34
38
|
self.check_api_config()
|
|
35
39
|
return self
|
|
36
40
|
|
|
37
41
|
def __exit__(self, *args):
|
|
42
|
+
logger.debug(f"Exiting requests session {self._session!r}")
|
|
38
43
|
self._session.__exit__()
|
|
39
44
|
self._session = None
|
|
40
45
|
|
|
@@ -49,6 +54,7 @@ class RawClient(RawWrapper, JsonProcessingMixin):
|
|
|
49
54
|
try:
|
|
50
55
|
if self.global_request_kwargs is not None:
|
|
51
56
|
kwargs.update(self.global_request_kwargs)
|
|
57
|
+
logger.debug(f"{method} request to {self.endpoint(path)}")
|
|
52
58
|
if self._session is not None:
|
|
53
59
|
resp = self._session.request(
|
|
54
60
|
method,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
homeassistant_api/__init__.py,sha256=AH9XX6azCAhlYkvfAKlPpH4PJllEHDZafCw0BFoMe3Y,1063
|
|
2
2
|
homeassistant_api/_async/__init__.py,sha256=XEF5FPZYe_jT-ivHrAZh90P946aAV3yDMPOmgI7_Oks,319
|
|
3
|
-
homeassistant_api/_async/asyncclient.py,sha256=
|
|
3
|
+
homeassistant_api/_async/asyncclient.py,sha256=2E4B4zzW8_WsGjFN1OMnLAdCN5UZmOD7jwVHBib8oos,10988
|
|
4
4
|
homeassistant_api/_async/models/__init__.py,sha256=A2C8C-7Pnp7cs5jc6xm12FdSShbEMpNnGeQlRB-mj9Y,255
|
|
5
5
|
homeassistant_api/_async/models/domains.py,sha256=G3fcvz_1A4QBk8gr30eFDCpHa-ndGkAisnvwNHEQWCo,2117
|
|
6
6
|
homeassistant_api/_async/models/entity.py,sha256=hTSrVc_Yps4t2gdF8lODnAXreHSNYZjKn9F1zy7Q5_8,2321
|
|
@@ -17,11 +17,11 @@ homeassistant_api/models/events.py,sha256=zHB8dNGEkgMlS0pg6NzRstxpjCRYvaz2d9ezM0
|
|
|
17
17
|
homeassistant_api/models/history.py,sha256=a5HHV7bw4qeFtOYSqpmun98Kx5yV0DesTmLNi0WLoTo,634
|
|
18
18
|
homeassistant_api/models/logbook.py,sha256=Op99ux61IQfcD_0UpdFqkKIl6G3j6mcZEhDJPgWoZUc,377
|
|
19
19
|
homeassistant_api/models/states.py,sha256=60OOGntib5xJndTR6OYR10cZC31dvwPYveNR58rd250,420
|
|
20
|
-
homeassistant_api/processing.py,sha256=
|
|
20
|
+
homeassistant_api/processing.py,sha256=WqworL2RdlvdfoQUfu7t-ISdJjmwYxB3pWvvjnlkCVc,4754
|
|
21
21
|
homeassistant_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
-
homeassistant_api/rawapi.py,sha256=
|
|
23
|
-
homeassistant_api/rawclient.py,sha256=
|
|
24
|
-
homeassistant_api-3.0.3.
|
|
25
|
-
homeassistant_api-3.0.3.
|
|
26
|
-
homeassistant_api-3.0.3.
|
|
27
|
-
homeassistant_api-3.0.3.
|
|
22
|
+
homeassistant_api/rawapi.py,sha256=fD1CxSZNv7V2OcchWAk3m9o1mxgee2c9zhbdv6kEA5U,5804
|
|
23
|
+
homeassistant_api/rawclient.py,sha256=u6W0wQprXew1_-mSfVflCNSkUGqJpXvGvCLRuQcRXN8,10444
|
|
24
|
+
homeassistant_api-3.0.3.post3.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
25
|
+
homeassistant_api-3.0.3.post3.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
|
|
26
|
+
homeassistant_api-3.0.3.post3.dist-info/METADATA,sha256=ApMgNVcdZGJWDIM7F-eVJO-3TEtOYE9MeWrQ4XY7RKI,2902
|
|
27
|
+
homeassistant_api-3.0.3.post3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|