HomeAssistant-API 3.0.3.post4__py3-none-any.whl → 3.0.3.post5__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,6 +1,7 @@
1
1
  """Module for interacting with Home Assistant asyncronously."""
2
2
  import asyncio
3
3
  import logging
4
+ from datetime import datetime
4
5
  from posixpath import join
5
6
  from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple, Union, cast
6
7
 
@@ -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,4 +1,5 @@
1
1
  """Module for Entity and entity Group data models"""
2
+ from datetime import datetime
2
3
  from posixpath import join
3
4
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
4
5
 
@@ -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,5 +1,6 @@
1
1
  """Module for Entity and entity Group data models"""
2
2
 
3
+ from datetime import datetime
3
4
  from posixpath import join
4
5
  from typing import TYPE_CHECKING, Any, Dict, Optional, cast
5
6
 
@@ -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
@@ -3,11 +3,17 @@
3
3
  import re
4
4
  from datetime import datetime
5
5
  from posixpath import join
6
- from typing import Dict, Optional, Tuple, Union
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,6 +1,7 @@
1
1
  """Module for all interaction with homeassistant."""
2
2
 
3
3
  import logging
4
+ from datetime import datetime
4
5
  from posixpath import join
5
6
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union, cast
6
7
 
@@ -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),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homeassistant-api
3
- Version: 3.0.3.post4
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,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=UsSszq48oCy_j3S8hCvPu0CX96OBH283NG1kwOmeGp4,10974
3
+ homeassistant_api/_async/asyncclient.py,sha256=BRP9LGvy_GQXiTfpExa5aMd2SM_M6lkCKBSaIJOMTHQ,11536
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=89To595nV9wloVN9G5GCDzspL-qQjDc3wZuBInpX-0A,2307
6
+ homeassistant_api/_async/models/entity.py,sha256=vNLs3OU7gVyklaQPhHc1LMH1t0pqJJySEQdaNEwTD_k,2774
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=MMrVaIRBlcKJdOAmla-x3p6SeRnqIJq4_xmArooHPPU,2692
15
+ homeassistant_api/models/entity.py,sha256=BkhgRentgWIypLIs3cs25X2BqL9jwru4k1E1WytHCAY,3151
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
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=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,,
22
+ homeassistant_api/rawapi.py,sha256=ScPe4pRy32iwOqpQFplzyZXcS1O4v6-3AhQOoecUS_I,6023
23
+ homeassistant_api/rawclient.py,sha256=JCaH8e8ufDCPYatlBj4yRXcpNcGkfMWPP-0Ow88lbk0,11018
24
+ homeassistant_api-3.0.3.post5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ homeassistant_api-3.0.3.post5.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
26
+ homeassistant_api-3.0.3.post5.dist-info/METADATA,sha256=H1Tc07AKvzApXlbhcvtFzelh1QBnvDQV9Kk8UndzNpY,2902
27
+ homeassistant_api-3.0.3.post5.dist-info/RECORD,,