HomeAssistant-API 3.0.3.post2__tar.gz → 3.0.3.post4__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 (28) hide show
  1. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/PKG-INFO +1 -1
  2. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/asyncclient.py +9 -3
  3. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/models/entity.py +1 -1
  4. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/entity.py +1 -1
  5. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/processing.py +4 -0
  6. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/rawapi.py +4 -4
  7. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/rawclient.py +7 -1
  8. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/pyproject.toml +3 -3
  9. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/setup.py +1 -1
  10. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/LICENSE +0 -0
  11. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/README.md +0 -0
  12. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/__init__.py +0 -0
  13. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/__init__.py +0 -0
  14. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/models/__init__.py +0 -0
  15. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/models/domains.py +0 -0
  16. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/_async/models/events.py +0 -0
  17. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/client.py +0 -0
  18. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/const.py +0 -0
  19. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/errors.py +0 -0
  20. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/mixins.py +0 -0
  21. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/__init__.py +0 -0
  22. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/base.py +0 -0
  23. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/domains.py +0 -0
  24. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/events.py +0 -0
  25. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/history.py +0 -0
  26. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/logbook.py +0 -0
  27. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/models/states.py +0 -0
  28. {HomeAssistant-API-3.0.3.post2 → HomeAssistant-API-3.0.3.post4}/homeassistant_api/py.typed +0 -0
@@ -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,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,
@@ -17,7 +17,7 @@ name = "HomeAssistant-API"
17
17
  readme = "README.md"
18
18
  include = ["homeassistant_api/py.typed"]
19
19
  repository = "https://github.com/GrandMoff100/HomeAssistantAPI"
20
- version = "3.0.3.post2"
20
+ version = "3.0.3.post4"
21
21
  [tool.poetry.dependencies]
22
22
  aiohttp = "^3.8.1"
23
23
  aiohttp-client-cache = "^0.6.1"
@@ -27,7 +27,7 @@ requests = "^2.26.0"
27
27
  requests-cache = "^0.9.2"
28
28
  simplejson = "^3.17.6"
29
29
  [tool.poetry.dev-dependencies]
30
- black = "^21.12b0"
30
+ black = "^22.3.0"
31
31
  flake8 = "^4.0.1"
32
32
  isort = "^5.10.1"
33
33
  pre-commit = "^2.17.0"
@@ -50,4 +50,4 @@ include = "homeassistant_api"
50
50
  extension-pkg-whitelist = ["pydantic"]
51
51
  ignore-paths = ["examples"]
52
52
  [tool.pylint.messages_control]
53
- disable = ["invalid-name", "duplicate-code", "no-member", "too-few-public-methods", "too-many-arguments"]
53
+ disable = ["invalid-name", "duplicate-code", "no-member", "too-few-public-methods", "too-many-arguments", "logging-fstring-interpolation"]
@@ -20,7 +20,7 @@ install_requires = \
20
20
 
21
21
  setup_kwargs = {
22
22
  'name': 'homeassistant-api',
23
- 'version': '3.0.3.post2',
23
+ 'version': '3.0.3.post4',
24
24
  'description': "Python Wrapper for Homeassistant's REST API",
25
25
  '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',
26
26
  'author': 'GrandMoff100',