HomeAssistant-API 3.0.3.post2__py3-none-any.whl → 3.0.3.post4__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.
@@ -1,7 +1,8 @@
1
1
  """Module for interacting with Home Assistant asyncronously."""
2
2
  import asyncio
3
+ import logging
4
+ from posixpath import join
3
5
  from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union, cast
4
- from urllib.parse import urljoin as join
5
6
 
6
7
  import aiohttp
7
8
  from aiohttp_client_cache import CachedSession
@@ -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(expire_after=30)
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
- join("services", domain + "/" + service),
206
+ f"services/{domain}/{service}",
201
207
  method="POST",
202
208
  json=service_data,
203
209
  )
@@ -1,6 +1,6 @@
1
1
  """Module for Entity and entity Group data models"""
2
+ from posixpath import join
2
3
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
3
- from urllib.parse import urljoin as join
4
4
 
5
5
  from pydantic import Field
6
6
 
@@ -1,7 +1,7 @@
1
1
  """Module for Entity and entity Group data models"""
2
2
 
3
+ from posixpath import join
3
4
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
4
- from urllib.parse import urljoin as join
5
5
 
6
6
  from pydantic import Field
7
7
 
@@ -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(
@@ -1,8 +1,8 @@
1
1
  """Module for parent RawWrapper class"""
2
2
 
3
- import os
4
3
  import re
5
4
  from datetime import datetime
5
+ from posixpath import join
6
6
  from typing import Dict, Optional, Tuple, Union
7
7
 
8
8
  from .const import DATE_FMT
@@ -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 os.path.join(self.api_url, path)
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 = os.path.join("history/period", formatted_timestamp)
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 = os.path.join("logbook", formatted_timestamp)
151
+ url = join("logbook", formatted_timestamp)
152
152
  else:
153
153
  url = "logbook"
154
154
  return params, url
@@ -1,7 +1,8 @@
1
1
  """Module for all interaction with homeassistant."""
2
2
 
3
+ import logging
4
+ from posixpath import join
3
5
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union, cast
4
- from urllib.parse import urljoin as join
5
6
 
6
7
  import requests
7
8
  from requests_cache import CachedSession
@@ -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
  Metadata-Version: 2.1
2
2
  Name: homeassistant-api
3
- Version: 3.0.3.post2
3
+ Version: 3.0.3.post4
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
@@ -1,9 +1,9 @@
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=h2hrIyFbZGqxY1EqR-IQ_LyNjVWzwLcFBcZujs9eXhs,10794
3
+ homeassistant_api/_async/asyncclient.py,sha256=UsSszq48oCy_j3S8hCvPu0CX96OBH283NG1kwOmeGp4,10974
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
- homeassistant_api/_async/models/entity.py,sha256=hTSrVc_Yps4t2gdF8lODnAXreHSNYZjKn9F1zy7Q5_8,2321
6
+ homeassistant_api/_async/models/entity.py,sha256=89To595nV9wloVN9G5GCDzspL-qQjDc3wZuBInpX-0A,2307
7
7
  homeassistant_api/_async/models/events.py,sha256=bs86N92XMJQXJeVzWGz5YkjXH8zLWDzKO2OscFwd5Gk,792
8
8
  homeassistant_api/client.py,sha256=L9bWMQKPh0fOyW9USli16JjGODEzqSvkNR3eiZiie1E,225
9
9
  homeassistant_api/const.py,sha256=XSNCLYcEsdE5ji2LjpMmfeKdMACPhuRY3nHxhPJXXqA,84
@@ -12,16 +12,16 @@ homeassistant_api/mixins.py,sha256=Ii0t8JD9vncvtErTeo0ng7hK0GZD-Y0H6xBDEQdI1_s,2
12
12
  homeassistant_api/models/__init__.py,sha256=3ZX2JOrA4lWB9DTtWuhGzyKaB9WarysCcKHvyiE50Sc,394
13
13
  homeassistant_api/models/base.py,sha256=-5XsyKSTVzQHtaHNUgLPMAtiSgh_AUfvoyFnSAAtUx4,393
14
14
  homeassistant_api/models/domains.py,sha256=0TvtRxRzAdwZyDQokfIM9siEjKRlDcK3NZ3DIVqNwFw,2210
15
- homeassistant_api/models/entity.py,sha256=s0jnDY65mTGEmA2_qXHyqO4rfR3m1K6VXMY0JHF1uHM,2706
15
+ homeassistant_api/models/entity.py,sha256=MMrVaIRBlcKJdOAmla-x3p6SeRnqIJq4_xmArooHPPU,2692
16
16
  homeassistant_api/models/events.py,sha256=zHB8dNGEkgMlS0pg6NzRstxpjCRYvaz2d9ezM04IlMw,752
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=4jTc4yOOVs9aAYiVzF88KNhEK3IZ4RyNHTAyoaNxtuw,4617
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=FKZArAgDuLppLTBFCdl-SI3VfEeA7rkEwhaoL06hoT8,5797
23
- homeassistant_api/rawclient.py,sha256=rXIPB8at78gsiCTEK20-wqAeXrMqayOjy1MAUxmFN6g,10176
24
- homeassistant_api-3.0.3.post2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
- homeassistant_api-3.0.3.post2.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
26
- homeassistant_api-3.0.3.post2.dist-info/METADATA,sha256=iQ9VKeKyFlPv5WCJI3AdScZQv7uVm8c3eUPo1aDB88o,2902
27
- homeassistant_api-3.0.3.post2.dist-info/RECORD,,
22
+ homeassistant_api/rawapi.py,sha256=Hh2k8dP3Gm0hYfVbRAVc0pCurYf-i45MZdcy4SdIps8,5790
23
+ homeassistant_api/rawclient.py,sha256=Nar1Fgm5vtpSULaBzqT5iOmnLqX2uoGT_ZoTO3HvGY8,10430
24
+ homeassistant_api-3.0.3.post4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ homeassistant_api-3.0.3.post4.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
26
+ homeassistant_api-3.0.3.post4.dist-info/METADATA,sha256=-sRqJzbl6KTHW0KuYgaRhADhoyM1LSjSWn7D32SJBgM,2902
27
+ homeassistant_api-3.0.3.post4.dist-info/RECORD,,