HomeAssistant-API 3.0.3.post1__tar.gz → 3.0.3.post2__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.post1 → HomeAssistant-API-3.0.3.post2}/PKG-INFO +1 -1
  2. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/__init__.py +19 -1
  3. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/__init__.py +9 -0
  4. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/asyncclient.py +7 -7
  5. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/models/__init__.py +2 -0
  6. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/models/domains.py +1 -1
  7. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/models/entity.py +1 -1
  8. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/errors.py +3 -3
  9. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/__init__.py +11 -0
  10. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/domains.py +1 -1
  11. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/entity.py +4 -4
  12. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/processing.py +11 -8
  13. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/rawclient.py +3 -3
  14. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/pyproject.toml +1 -1
  15. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/setup.py +1 -1
  16. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/LICENSE +0 -0
  17. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/README.md +0 -0
  18. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/_async/models/events.py +0 -0
  19. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/client.py +0 -0
  20. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/const.py +0 -0
  21. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/mixins.py +0 -0
  22. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/base.py +0 -0
  23. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/events.py +0 -0
  24. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/history.py +0 -0
  25. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/logbook.py +0 -0
  26. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/models/states.py +0 -0
  27. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/py.typed +0 -0
  28. {HomeAssistant-API-3.0.3.post1 → HomeAssistant-API-3.0.3.post2}/homeassistant_api/rawapi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homeassistant-api
3
- Version: 3.0.3.post1
3
+ Version: 3.0.3.post2
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,4 +1,22 @@
1
1
  """Imports all library stuff for convenience."""
2
+
3
+
4
+ __all__ = (
5
+ "State",
6
+ "Service",
7
+ "History",
8
+ "Group",
9
+ "Event",
10
+ "Entity",
11
+ "Domain",
12
+ "AsyncService",
13
+ "AsyncGroup",
14
+ "AsyncEvent",
15
+ "AsyncEntity",
16
+ "AsyncDomain",
17
+ "LogbookEntry",
18
+ )
19
+
2
20
  from ._async import AsyncDomain, AsyncEntity, AsyncEvent, AsyncGroup, AsyncService
3
21
  from .client import Client
4
22
  from .errors import (
@@ -13,7 +31,7 @@ from .errors import (
13
31
  UnauthorizedError,
14
32
  UnexpectedStatusCodeError,
15
33
  )
16
- from .models import Domain, Entity, Event, Group, History, Service, State
34
+ from .models import Domain, Entity, Event, Group, History, LogbookEntry, Service, State
17
35
  from .processing import Processing
18
36
 
19
37
  Domain.update_forward_refs(**locals())
@@ -1,3 +1,12 @@
1
1
  """Imports objects from the async sub-module for convenience."""
2
2
  from .asyncclient import RawAsyncClient
3
3
  from .models import AsyncDomain, AsyncEntity, AsyncEvent, AsyncGroup, AsyncService
4
+
5
+ __all__ = (
6
+ "RawAsyncClient",
7
+ "AsyncDomain",
8
+ "AsyncEntity",
9
+ "AsyncEvent",
10
+ "AsyncGroup",
11
+ "AsyncService",
12
+ )
@@ -1,7 +1,7 @@
1
1
  """Module for interacting with Home Assistant asyncronously."""
2
2
  import asyncio
3
- from os.path import join
4
3
  from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union, cast
4
+ from urllib.parse import urljoin as join
5
5
 
6
6
  import aiohttp
7
7
  from aiohttp_client_cache import CachedSession
@@ -68,7 +68,7 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
68
68
  ) from err
69
69
 
70
70
  @staticmethod
71
- async def async_response_logic(response):
71
+ async def async_response_logic(response) -> Any:
72
72
  """Processes custom mimetype content asyncronously."""
73
73
  return await Processing(response=response).process()
74
74
 
@@ -175,9 +175,9 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
175
175
  f"Neither group and slug or entity_id provided. {help_msg}"
176
176
  )
177
177
  group_id, entity_slug = state.entity_id.split(".")
178
- group = AsyncGroup(group_id=cast(str, group_id), client=self)
179
- group.add_entity(cast(str, entity_slug), state)
180
- return group.get_entity(cast(str, entity_slug))
178
+ group = AsyncGroup(group_id=group_id, client=self)
179
+ group.add_entity(entity_slug, state)
180
+ return group.get_entity(entity_slug)
181
181
 
182
182
  # Services and domain methods
183
183
  async def async_get_domains(self) -> Tuple[Domain, ...]:
@@ -193,11 +193,11 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
193
193
  self,
194
194
  domain: str,
195
195
  service: str,
196
- **service_data,
196
+ **service_data: Union[Dict[str, Any], List[Any], str],
197
197
  ) -> List[State]:
198
198
  """Tells Home Assistant to trigger a service, returns stats changed while being called"""
199
199
  data = await self.async_request(
200
- join("services", domain, service),
200
+ join("services", domain + "/" + service),
201
201
  method="POST",
202
202
  json=service_data,
203
203
  )
@@ -2,3 +2,5 @@
2
2
  from .domains import AsyncDomain, AsyncService
3
3
  from .entity import AsyncEntity, AsyncGroup
4
4
  from .events import AsyncEvent
5
+
6
+ __all__ = ("AsyncDomain", "AsyncService", "AsyncEntity", "AsyncGroup", "AsyncEvent")
@@ -32,7 +32,7 @@ class AsyncDomain(BaseModel):
32
32
 
33
33
  def get_service(self, service_id: str):
34
34
  """Return a Service with the given service_id, returns None if no such service exists"""
35
- return self.services.get(service_id, None)
35
+ return self.services.get(service_id)
36
36
 
37
37
  def __getattr__(self, attr: str):
38
38
  """Allows services accessible as attributes"""
@@ -1,6 +1,6 @@
1
1
  """Module for Entity and entity Group data models"""
2
- from os.path import join
3
2
  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
 
@@ -8,7 +8,7 @@ class HomeassistantAPIError(BaseException):
8
8
  class RequestError(HomeassistantAPIError):
9
9
  """Error raised when an issue occurs when requesting to Homeassistant."""
10
10
 
11
- def __init__(self, body: str):
11
+ def __init__(self, body: str) -> None:
12
12
  super().__init__(f"Bad Request: {body}")
13
13
 
14
14
 
@@ -31,7 +31,7 @@ class ParameterMissingError(HomeassistantAPIError):
31
31
  class UnexpectedStatusCodeError(HomeassistantAPIError):
32
32
  """Error raised when Home Assistant returns a response with status code that was unexpected."""
33
33
 
34
- def __init__(self, code: int, content):
34
+ def __init__(self, code: int, content) -> None:
35
35
  super().__init__(
36
36
  f"Home Assistant return response with an unrecognized status code {code!r}.\n{content}"
37
37
  )
@@ -54,7 +54,7 @@ class EndpointNotFoundError(HomeassistantAPIError):
54
54
  class MethodNotAllowedError(HomeassistantAPIError):
55
55
  """Error raised when a request is made to an endpoint with a non-allowed method."""
56
56
 
57
- def __init__(self, method: str):
57
+ def __init__(self, method: str) -> None:
58
58
  super().__init__(f"Request made with invalid method {method!r}")
59
59
 
60
60
 
@@ -6,3 +6,14 @@ from .events import Event
6
6
  from .history import History
7
7
  from .logbook import LogbookEntry
8
8
  from .states import State
9
+
10
+ __all__ = (
11
+ "Domain",
12
+ "Service",
13
+ "Entity",
14
+ "Group",
15
+ "Event",
16
+ "History",
17
+ "LogbookEntry",
18
+ "State",
19
+ )
@@ -31,7 +31,7 @@ class Domain(BaseModel):
31
31
 
32
32
  def get_service(self, service_id: str):
33
33
  """Return a Service with the given service_id, returns None if no such service exists"""
34
- return self.services.get(service_id, None)
34
+ return self.services.get(service_id)
35
35
 
36
36
  def __getattr__(self, attr: str):
37
37
  """Allows services accessible as attributes"""
@@ -1,7 +1,7 @@
1
1
  """Module for Entity and entity Group data models"""
2
2
 
3
- from os.path import join
4
3
  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
 
@@ -25,7 +25,7 @@ class Group(BaseModel):
25
25
  self.entities[entity_slug] = Entity(
26
26
  slug=entity_slug,
27
27
  state=state,
28
- client=self,
28
+ client=self.client,
29
29
  )
30
30
 
31
31
  def get_entity(self, entity_slug: str) -> Optional["Entity"]:
@@ -71,9 +71,9 @@ class Entity(BaseModel):
71
71
  return self.state
72
72
 
73
73
  @property
74
- def entity_id(self):
74
+ def entity_id(self) -> str:
75
75
  """Constructs the entity_id string from its group and slug"""
76
- return self.group.group_id + "." + self.slug
76
+ return (self.group.group_id + "." + self.slug).strip()
77
77
 
78
78
  def get_history(self, *args, **kwargs) -> History:
79
79
  """Gets the previous `State`'s of the `Entity`"""
@@ -2,13 +2,14 @@
2
2
 
3
3
  import inspect
4
4
  import json
5
- from typing import Callable, ClassVar, Dict, Tuple, Union
5
+ import sys
6
+ from typing import Any, Callable, ClassVar, Dict, Tuple, Union, cast
6
7
 
7
8
  import simplejson
8
9
  from aiohttp import ClientResponse
9
10
  from aiohttp_client_cache.response import CachedResponse as AsyncCachedResponse
10
11
  from requests import Response
11
- from requests_cache import CachedResponse
12
+ from requests_cache.models.response import CachedResponse
12
13
 
13
14
  from .errors import (
14
15
  EndpointNotFoundError,
@@ -57,10 +58,9 @@ class Processing(BaseModel):
57
58
  f"No non-async response processor found for mimetype {mimetype!r}"
58
59
  )
59
60
 
60
- def process(self):
61
+ def process(self) -> Any:
61
62
  """Validates the http status code before starting to process the repsonse content"""
62
- _async = isinstance(self.response, (ClientResponse, AsyncCachedResponse))
63
- if _async:
63
+ if _async := isinstance(self.response, (ClientResponse, AsyncCachedResponse)):
64
64
  status_code = self.response.status
65
65
  elif isinstance(self.response, Response):
66
66
  status_code = self.response.status_code
@@ -77,14 +77,17 @@ class Processing(BaseModel):
77
77
  if status_code == 404:
78
78
  raise EndpointNotFoundError(self.response.url)
79
79
  if status_code == 405:
80
- raise MethodNotAllowedError(self.response.request.method)
80
+ raise MethodNotAllowedError(
81
+ cast(str, self.response.request.method),
82
+ ) # type: ignore[union-attr]
81
83
  print(
82
84
  "If this happened, "
83
85
  "please report it at https://github.com/GrandMoff100/HomeAssistantAPI/issues "
84
- "with the request status code and the request content"
86
+ "with the request status code and the request content",
87
+ file=sys.stderr,
85
88
  )
86
89
  raise UnexpectedStatusCodeError(
87
- self.response.status_code,
90
+ status_code,
88
91
  self.response.content,
89
92
  )
90
93
 
@@ -1,7 +1,7 @@
1
1
  """Module for all interaction with homeassistant."""
2
2
 
3
- from os.path import join
4
3
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union, cast
4
+ from urllib.parse import urljoin as join
5
5
 
6
6
  import requests
7
7
  from requests_cache import CachedSession
@@ -44,7 +44,7 @@ class RawClient(RawWrapper, JsonProcessingMixin):
44
44
  method="GET",
45
45
  headers: Dict[str, str] = None,
46
46
  **kwargs,
47
- ) -> Union[dict, list, str]:
47
+ ) -> Union[Dict[str, Any], list, str]:
48
48
  """Base method for making requests to the api"""
49
49
  try:
50
50
  if self.global_request_kwargs is not None:
@@ -203,7 +203,7 @@ class RawClient(RawWrapper, JsonProcessingMixin):
203
203
  ) -> Tuple[State, ...]:
204
204
  """Tells Home Assistant to trigger a service, returns stats changed while being called"""
205
205
  data = self.request(
206
- join("services", domain, service),
206
+ join("services", domain + "/" + service),
207
207
  method="POST",
208
208
  json=service_data,
209
209
  )
@@ -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.post1"
20
+ version = "3.0.3.post2"
21
21
  [tool.poetry.dependencies]
22
22
  aiohttp = "^3.8.1"
23
23
  aiohttp-client-cache = "^0.6.1"
@@ -20,7 +20,7 @@ install_requires = \
20
20
 
21
21
  setup_kwargs = {
22
22
  'name': 'homeassistant-api',
23
- 'version': '3.0.3.post1',
23
+ 'version': '3.0.3.post2',
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',