HomeAssistant-API 4.1.0__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.
Files changed (21) hide show
  1. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/PKG-INFO +1 -1
  2. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/client.py +9 -3
  3. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/errors.py +2 -2
  4. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/entity.py +2 -2
  5. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/history.py +1 -1
  6. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/processing.py +7 -7
  7. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/rawasyncclient.py +16 -11
  8. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/rawbaseclient.py +2 -2
  9. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/rawclient.py +16 -13
  10. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/pyproject.toml +10 -1
  11. homeassistant_api-4.1.0/setup.py +0 -35
  12. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/LICENSE +0 -0
  13. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/README.md +0 -0
  14. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/__init__.py +0 -0
  15. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/__init__.py +0 -0
  16. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/base.py +0 -0
  17. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/domains.py +0 -0
  18. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/events.py +0 -0
  19. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/logbook.py +0 -0
  20. {homeassistant_api-4.1.0 → homeassistant_api-4.1.1}/homeassistant_api/models/states.py +0 -0
  21. {homeassistant_api-4.1.0 → 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.1.0
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
@@ -19,8 +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__(self, *args: Any, use_async: bool = False, **kwargs: Any) -> None:
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
- RawAsyncClient.__init__(self, *args, **kwargs)
30
+ RawAsyncClient.__init__(self, *args, verify_ssl=verify_ssl, **kwargs)
25
31
  else:
26
- RawClient.__init__(self, *args, **kwargs)
32
+ RawClient.__init__(self, *args, verify_ssl=verify_ssl, **kwargs)
@@ -55,14 +55,14 @@ class InternalServerError(HomeassistantAPIError):
55
55
  class UnauthorizedError(HomeassistantAPIError):
56
56
  """Error raised when an invalid token in used to authenticate with homeassistant."""
57
57
 
58
- def __init__(self):
58
+ def __init__(self) -> None:
59
59
  super().__init__("Invalid authentication token")
60
60
 
61
61
 
62
62
  class EndpointNotFoundError(HomeassistantAPIError):
63
63
  """Error raised when a request is made to a non existing endpoint."""
64
64
 
65
- def __init__(self, path: str):
65
+ def __init__(self, path: str) -> None:
66
66
  super().__init__(f"Cannot make request to the endpoint {path!r}")
67
67
 
68
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
 
@@ -62,7 +62,7 @@ class Processing:
62
62
  mimetype = self._response.headers.get( # type: ignore [arg-type]
63
63
  "content-type",
64
64
  "text/plain",
65
- ) # type: ignore[arg-type]
65
+ )
66
66
  for processor in self._processors.get(mimetype, ()):
67
67
  if not async_ ^ inspect.iscoroutinefunction(processor):
68
68
  logger.debug("Using processor %r on %r", processor, self._response)
@@ -105,10 +105,10 @@ class Processing:
105
105
 
106
106
  # List of default processors
107
107
  @Processing.processor("application/json") # type: ignore[arg-type]
108
- def process_json(response: ResponseType) -> Dict[str, Any]:
108
+ def process_json(response: ResponseType) -> dict[str, Any]:
109
109
  """Returns the json dict content of the response."""
110
110
  try:
111
- return response.json()
111
+ return cast(dict[str, Any], response.json())
112
112
  except (json.JSONDecodeError, simplejson.JSONDecodeError) as err:
113
113
  raise MalformedDataError(
114
114
  f"Home Assistant responded with non-json response: {repr(response.text)}"
@@ -116,17 +116,17 @@ def process_json(response: ResponseType) -> Dict[str, Any]:
116
116
 
117
117
 
118
118
  @Processing.processor("text/plain") # type: ignore[arg-type]
119
- @Processing.processor("application/octet-stream") # type: ignore[arg-type]
119
+ @Processing.processor("application/octet-stream")
120
120
  def process_text(response: ResponseType) -> str:
121
121
  """Returns the plaintext of the reponse."""
122
122
  return response.text
123
123
 
124
124
 
125
125
  @Processing.processor("application/json") # type: ignore[arg-type]
126
- async def async_process_json(response: AsyncResponseType) -> Dict[str, Any]:
126
+ async def async_process_json(response: AsyncResponseType) -> dict[str, Any]:
127
127
  """Returns the json dict content of the response."""
128
128
  try:
129
- return await response.json()
129
+ return cast(dict[str, Any], await response.json())
130
130
  except (json.JSONDecodeError, simplejson.JSONDecodeError) as err:
131
131
  raise MalformedDataError(
132
132
  f"Home Assistant responded with non-json response: {repr(await response.text())}"
@@ -134,7 +134,7 @@ async def async_process_json(response: AsyncResponseType) -> Dict[str, Any]:
134
134
 
135
135
 
136
136
  @Processing.processor("text/plain") # type: ignore[arg-type]
137
- @Processing.processor("application/octet-stream") # type: ignore[arg-type]
137
+ @Processing.processor("application/octet-stream")
138
138
  async def async_process_text(response: AsyncResponseType) -> str:
139
139
  """Returns the plaintext of the reponse."""
140
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, 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,22 @@ 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,
86
89
  decode_bytes: bool = True,
87
90
  **kwargs,
88
91
  ) -> Any:
@@ -202,7 +205,7 @@ class RawClient(RawBaseClient):
202
205
  group_id, entity_slug = state.entity_id.split(".")
203
206
  if group_id not in entities:
204
207
  entities[group_id] = Group(
205
- group_id=cast(str, group_id),
208
+ group_id=group_id,
206
209
  _client=self, # type: ignore[arg-type]
207
210
  )
208
211
  entities[group_id]._add_entity(entity_slug, state)
@@ -210,9 +213,9 @@ class RawClient(RawBaseClient):
210
213
 
211
214
  def get_entity(
212
215
  self,
213
- group_id: str = None,
214
- slug: str = None,
215
- entity_id: str = None,
216
+ group_id: str | None = None,
217
+ slug: str | None = None,
218
+ entity_id: str | None = None,
216
219
  ) -> Optional[Entity]:
217
220
  """Returns an :py:class:`Entity` model for an :code:`entity_id`"""
218
221
  if group_id is not None and slug is not None:
@@ -229,11 +232,11 @@ class RawClient(RawBaseClient):
229
232
  )
230
233
  split_group_id, split_slug = state.entity_id.split(".")
231
234
  group = Group(
232
- group_id=cast(str, split_group_id),
235
+ group_id=split_group_id,
233
236
  _client=self, # type: ignore[arg-type]
234
237
  )
235
- group._add_entity(cast(str, split_slug), state)
236
- return group.get_entity(cast(str, split_slug))
238
+ group._add_entity(split_slug, state)
239
+ return group.get_entity(split_slug)
237
240
 
238
241
  # Services and domain methods
239
242
  def get_domains(self) -> Dict[str, Domain]:
@@ -326,7 +329,7 @@ class RawClient(RawBaseClient):
326
329
  method="POST",
327
330
  json=event_data,
328
331
  )
329
- return cast(dict, data).get("message")
332
+ return cast(dict[str, Any], data).get("message")
330
333
 
331
334
  def get_components(self) -> Tuple[str, ...]:
332
335
  """Returns a tuple of all registered components."""
@@ -12,7 +12,7 @@ name = "HomeAssistant-API"
12
12
  readme = "README.md"
13
13
  include = ["homeassistant_api/py.typed"]
14
14
  repository = "https://github.com/GrandMoff100/HomeAssistantAPI"
15
- version = "4.1.0"
15
+ version = "4.1.1"
16
16
  packages = [{ include = "homeassistant_api" }]
17
17
 
18
18
  [tool.poetry.dependencies]
@@ -87,3 +87,12 @@ select = [
87
87
  [tool.ruff.per-file-ignores]
88
88
  "__init__.py" = ['F401']
89
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
+ ]
@@ -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.1.0',
21
- 'description': "Python Wrapper for Homeassistant's REST API",
22
- 'long_description': '# HomeassistantAPI\n\n[![Code Coverage](https://img.shields.io/codecov/c/github/GrandMoff100/HomeAssistantAPI/dev?style=for-the-badge&token=SJFC3HX5R1)](https://codecov.io/gh/GrandMoff100/HomeAssistantAPI)\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<a href="https://home-assistant.io">\n <img src="https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true" width="60%">\n</a>\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)