HomeAssistant-API 3.0.3.post3__tar.gz → 3.0.3.post5__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.post3 → HomeAssistant-API-3.0.3.post5}/PKG-INFO +1 -1
  2. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/asyncclient.py +15 -4
  3. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/models/entity.py +14 -4
  4. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/entity.py +15 -5
  5. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/rawapi.py +13 -7
  6. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/rawclient.py +18 -3
  7. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/pyproject.toml +1 -1
  8. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/setup.py +1 -1
  9. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/LICENSE +0 -0
  10. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/README.md +0 -0
  11. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/__init__.py +0 -0
  12. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/__init__.py +0 -0
  13. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/models/__init__.py +0 -0
  14. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/models/domains.py +0 -0
  15. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/_async/models/events.py +0 -0
  16. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/client.py +0 -0
  17. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/const.py +0 -0
  18. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/errors.py +0 -0
  19. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/mixins.py +0 -0
  20. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/__init__.py +0 -0
  21. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/base.py +0 -0
  22. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/domains.py +0 -0
  23. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/events.py +0 -0
  24. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/history.py +0 -0
  25. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/logbook.py +0 -0
  26. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/models/states.py +0 -0
  27. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/homeassistant_api/processing.py +0 -0
  28. {HomeAssistant-API-3.0.3.post3 → HomeAssistant-API-3.0.3.post5}/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.post3
3
+ Version: 3.0.3.post5
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,8 +1,9 @@
1
1
  """Module for interacting with Home Assistant asyncronously."""
2
2
  import asyncio
3
3
  import logging
4
+ from datetime import datetime
5
+ from posixpath import join
4
6
  from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union, cast
5
- from urllib.parse import urljoin as join
6
7
 
7
8
  import aiohttp
8
9
  from aiohttp_client_cache import CachedSession
@@ -100,13 +101,23 @@ class RawAsyncClient(RawWrapper, JsonProcessingMixin):
100
101
 
101
102
  async def async_get_entity_histories(
102
103
  self,
103
- *args,
104
- **kwargs,
104
+ entities: Optional[Tuple[AsyncEntity, ...]] = None,
105
+ start_timestamp: Optional[datetime] = None,
106
+ # Defaults to 1 day before. https://developers.home-assistant.io/docs/api/rest/
107
+ end_timestamp: Optional[datetime] = None,
108
+ minimal_state_data: bool = False,
109
+ significant_changes_only: bool = False,
105
110
  ) -> AsyncGenerator[History, None]:
106
111
  """
107
112
  Returns a generator of entity state histories from homeassistant.
108
113
  """
109
- params, url = self.prepare_get_entity_histories_params(*args, **kwargs)
114
+ params, url = self.prepare_get_entity_histories_params(
115
+ entities=entities,
116
+ start_timestamp=start_timestamp,
117
+ end_timestamp=end_timestamp,
118
+ minimal_state_data=minimal_state_data,
119
+ significant_changes_only=significant_changes_only,
120
+ )
110
121
  data = await self.async_request(
111
122
  url,
112
123
  params=self.construct_params(params),
@@ -1,6 +1,7 @@
1
1
  """Module for Entity and entity Group data models"""
2
+ from datetime import datetime
3
+ from posixpath import join
2
4
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
3
- from urllib.parse import urljoin as join
4
5
 
5
6
  from pydantic import Field
6
7
 
@@ -59,13 +60,22 @@ class AsyncEntity(BaseModel):
59
60
  """Constructs the entity_id string from its group and slug"""
60
61
  return self.group.group_id + "." + self.slug
61
62
 
62
- async def async_get_history(self, *args, **kwargs) -> Optional[History]:
63
+ async def async_get_history(
64
+ self,
65
+ start_timestamp: Optional[datetime] = None,
66
+ # Defaults to 1 day before. https://developers.home-assistant.io/docs/api/rest/
67
+ end_timestamp: Optional[datetime] = None,
68
+ minimal_state_data: bool = False,
69
+ significant_changes_only: bool = False,
70
+ ) -> Optional[History]:
63
71
  """Gets the previous `State`'s of the `Entity`."""
64
72
  history: Optional[History] = None
65
73
  async for history in self.group.client.async_get_entity_histories(
66
74
  entities=(self,),
67
- *args,
68
- **kwargs,
75
+ start_timestamp=start_timestamp,
76
+ end_timestamp=end_timestamp,
77
+ minimal_state_data=minimal_state_data,
78
+ significant_changes_only=significant_changes_only,
69
79
  ):
70
80
  break
71
81
  return history
@@ -1,7 +1,8 @@
1
1
  """Module for Entity and entity Group data models"""
2
2
 
3
+ from datetime import datetime
4
+ from posixpath import join
3
5
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
4
- from urllib.parse import urljoin as join
5
6
 
6
7
  from pydantic import Field
7
8
 
@@ -25,7 +26,7 @@ class Group(BaseModel):
25
26
  self.entities[entity_slug] = Entity(
26
27
  slug=entity_slug,
27
28
  state=state,
28
- client=self.client,
29
+ group=self,
29
30
  )
30
31
 
31
32
  def get_entity(self, entity_slug: str) -> Optional["Entity"]:
@@ -75,13 +76,22 @@ class Entity(BaseModel):
75
76
  """Constructs the entity_id string from its group and slug"""
76
77
  return (self.group.group_id + "." + self.slug).strip()
77
78
 
78
- def get_history(self, *args, **kwargs) -> History:
79
+ def get_history(
80
+ self,
81
+ start_timestamp: Optional[datetime] = None,
82
+ # Defaults to 1 day before. https://developers.home-assistant.io/docs/api/rest/
83
+ end_timestamp: Optional[datetime] = None,
84
+ minimal_state_data: bool = False,
85
+ significant_changes_only: bool = False,
86
+ ) -> History:
79
87
  """Gets the previous `State`'s of the `Entity`"""
80
88
  history = None
81
89
  for history in self.group.client.get_entity_histories(
82
90
  entities=(self,),
83
- *args,
84
- **kwargs,
91
+ start_timestamp=start_timestamp,
92
+ end_timestamp=end_timestamp,
93
+ minimal_state_data=minimal_state_data,
94
+ significant_changes_only=significant_changes_only,
85
95
  ):
86
96
  break
87
97
  return history
@@ -2,12 +2,18 @@
2
2
 
3
3
  import re
4
4
  from datetime import datetime
5
- from typing import Dict, Optional, Tuple, Union
6
- from urllib.parse import urljoin as join
5
+ from posixpath import join
6
+ from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
7
+ from urllib.parse import quote as url_quote
7
8
 
8
9
  from .const import DATE_FMT
9
10
  from .models import Entity
10
11
 
12
+ if TYPE_CHECKING:
13
+ from ._async.models.entity import AsyncEntity
14
+ else:
15
+ AsyncEntity = None # pylint: disable=invalid-name
16
+
11
17
 
12
18
  class RawWrapper:
13
19
  """Builds, and makes requests to the API"""
@@ -101,7 +107,7 @@ class RawWrapper:
101
107
 
102
108
  @staticmethod
103
109
  def prepare_get_entity_histories_params(
104
- entities: Optional[Tuple[Entity, ...]] = None,
110
+ entities: Optional[Tuple[Union[Entity, AsyncEntity], ...]] = None,
105
111
  start_timestamp: Optional[datetime] = None,
106
112
  # Defaults to 1 day before. https://developers.home-assistant.io/docs/api/rest/
107
113
  end_timestamp: Optional[datetime] = None,
@@ -114,7 +120,7 @@ class RawWrapper:
114
120
  if entities is not None:
115
121
  params["filter_entity_id"] = ",".join([ent.entity_id for ent in entities])
116
122
  if end_timestamp is not None:
117
- params["end_time"] = end_timestamp.strftime(DATE_FMT)
123
+ params["end_time"] = url_quote(end_timestamp.strftime(DATE_FMT))
118
124
  if minimal_state_data:
119
125
  params["minimal_response"] = None
120
126
  if significant_changes_only:
@@ -122,7 +128,7 @@ class RawWrapper:
122
128
  if start_timestamp is not None:
123
129
  if isinstance(start_timestamp, datetime):
124
130
  formatted_timestamp = start_timestamp.strftime(DATE_FMT)
125
- url = join("history/period", formatted_timestamp)
131
+ url = join("history/period/", formatted_timestamp)
126
132
  else:
127
133
  raise TypeError(f"timestamp needs to be of type {datetime!r}")
128
134
  else:
@@ -143,12 +149,12 @@ class RawWrapper:
143
149
  params.update(entity=filter_entity.entity_id)
144
150
  if end_timestamp is not None:
145
151
  if isinstance(end_timestamp, datetime):
146
- end_timestamp = end_timestamp.strftime(DATE_FMT)
152
+ end_timestamp = url_quote(end_timestamp.strftime(DATE_FMT))
147
153
  params.update(end_time=end_timestamp)
148
154
  if start_timestamp is not None:
149
155
  if isinstance(start_timestamp, datetime):
150
156
  formatted_timestamp = start_timestamp.strftime(DATE_FMT)
151
- url = join("logbook", formatted_timestamp)
157
+ url = join("logbook/", formatted_timestamp)
152
158
  else:
153
159
  url = "logbook"
154
160
  return params, url
@@ -1,8 +1,9 @@
1
1
  """Module for all interaction with homeassistant."""
2
2
 
3
3
  import logging
4
+ from datetime import datetime
5
+ from posixpath import join
4
6
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union, cast
5
- from urllib.parse import urljoin as join
6
7
 
7
8
  import requests
8
9
  from requests_cache import CachedSession
@@ -100,11 +101,25 @@ class RawClient(RawWrapper, JsonProcessingMixin):
100
101
  for entry in data:
101
102
  yield LogbookEntry.parse_obj(entry)
102
103
 
103
- def get_entity_histories(self, *args, **kwargs) -> Generator[History, None, None]:
104
+ def get_entity_histories(
105
+ self,
106
+ entities: Optional[Tuple[Entity, ...]] = None,
107
+ start_timestamp: Optional[datetime] = None,
108
+ # Defaults to 1 day before. https://developers.home-assistant.io/docs/api/rest/
109
+ end_timestamp: Optional[datetime] = None,
110
+ minimal_state_data: bool = False,
111
+ significant_changes_only: bool = False,
112
+ ) -> Generator[History, None, None]:
104
113
  """
105
114
  Yields entity state histories. See docs on the `History` model.
106
115
  """
107
- params, url = self.prepare_get_entity_histories_params(*args, **kwargs)
116
+ params, url = self.prepare_get_entity_histories_params(
117
+ entities=entities,
118
+ start_timestamp=start_timestamp,
119
+ end_timestamp=end_timestamp,
120
+ minimal_state_data=minimal_state_data,
121
+ significant_changes_only=significant_changes_only,
122
+ )
108
123
  data = self.request(
109
124
  url,
110
125
  params=self.construct_params(params),
@@ -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.post3"
20
+ version = "3.0.3.post5"
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.post3',
23
+ 'version': '3.0.3.post5',
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',