blueair-api 1.20.1__py3-none-any.whl → 1.21.0__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.
blueair_api/device_aws.py CHANGED
@@ -11,6 +11,21 @@ _LOGGER = logging.getLogger(__name__)
11
11
 
12
12
  @dataclasses.dataclass(slots=True)
13
13
  class DeviceAws(CallbacksMixin):
14
+ @classmethod
15
+ async def create_device(cls, api, uuid, name, mac, type_name, refresh=False):
16
+ _LOGGER.debug("UUID:"+uuid)
17
+ device_aws = DeviceAws(
18
+ api=api,
19
+ uuid=uuid,
20
+ name_api=name,
21
+ mac=mac,
22
+ type_name=type_name,
23
+ )
24
+ if refresh:
25
+ await device_aws.refresh()
26
+ _LOGGER.debug(f"create_device blueair device_aws: {device_aws}")
27
+ return device_aws
28
+
14
29
  api: HttpAwsBlueair
15
30
  uuid: str = None
16
31
  name: str = None
@@ -201,6 +201,29 @@ class HttpBlueair:
201
201
  )
202
202
  return await response.json()
203
203
 
204
+ async def get_data_points_since(self, device_uuid: str, seconds_ago: int = 0, sample_period: int = 300) -> dict[str, any]:
205
+ """
206
+ Fetch the list of data points between a relative timestamp (in seconds) and the current time.
207
+
208
+ An optional sample period can be provided to group data points
209
+ together. The minimum sample period size is 300 (5 minutes).
210
+
211
+ Note: the data for the most recent data point is only updated once
212
+ every 5 minutes. Calling it more often will return the same respone
213
+ from the server and should be avoided to limit server load.
214
+ """
215
+ url = f"https://{await self.get_home_host()}/v2/device/{device_uuid}/datapoint/{seconds_ago}/last/{sample_period}/"
216
+ headers = {
217
+ "X-API-KEY-TOKEN": API_KEY,
218
+ "X-AUTH-TOKEN": await self.get_auth_token(),
219
+ }
220
+ response: ClientResponse = (
221
+ await self._get_request_with_logging_and_errors_raised(
222
+ url=url, headers=headers
223
+ )
224
+ )
225
+ return await response.json()
226
+
204
227
  async def set_fan_speed(self, device_uuid, new_speed: str):
205
228
  """
206
229
  Set the fan speed per @spikeyGG comment at https://community.home-assistant.io/t/blueair-purifier-addon/154456/14
blueair_api/stub.py CHANGED
@@ -28,16 +28,16 @@ async def testing():
28
28
  password = getpass()
29
29
  try:
30
30
  api, devices = await get_aws_devices(username=username, password=password)
31
- await devices[0].refresh()
32
- await devices[0].set_child_lock(True)
33
- logger.debug(devices[0])
31
+ for device in devices:
32
+ await device.refresh()
33
+ await device.set_child_lock(True)
34
+ logger.debug(device)
34
35
  finally:
35
36
  if api:
36
37
  await api.cleanup_client_session()
37
38
  try:
38
39
  api, devices = await get_devices(username=username, password=password)
39
40
  for device in devices:
40
- await device.post_init()
41
41
  await device.refresh()
42
42
  logger.debug(device)
43
43
  finally:
@@ -25,14 +25,13 @@ async def get_devices(
25
25
  auth_token=auth_token,
26
26
  )
27
27
  api_devices = await api.get_devices()
28
-
29
28
  devices = []
30
29
  for api_device in api_devices:
31
30
  devices.append(await Device.create_device(
32
- api,
33
- api_device["uuid"],
34
- api_device["name"],
35
- api_device["mac"]
31
+ api=api,
32
+ uuid=api_device["uuid"],
33
+ name=api_device["name"],
34
+ mac=api_device["mac"]
36
35
  ))
37
36
  return (
38
37
  api,
@@ -53,18 +52,17 @@ async def get_aws_devices(
53
52
  client_session=client_session,
54
53
  )
55
54
  api_devices = await api.devices()
56
-
57
- def create_device(device):
58
- return DeviceAws(
55
+ devices = []
56
+ for api_device in api_devices:
57
+ _LOGGER.debug("api_device: %s", api_device)
58
+ devices.append(await DeviceAws.create_device(
59
59
  api=api,
60
- uuid=device["uuid"],
61
- name_api=device["name"],
62
- mac=device["mac"],
63
- type_name=device["type"],
64
- )
65
-
66
- devices = map(create_device, api_devices)
60
+ uuid=api_device["uuid"],
61
+ name=api_device["name"],
62
+ mac=api_device["mac"],
63
+ type_name=api_device["type"]
64
+ ))
67
65
  return (
68
66
  api,
69
- list(devices)
67
+ devices
70
68
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blueair_api
3
- Version: 1.20.1
3
+ Version: 1.21.0
4
4
  Summary: Blueair Api Wrapper
5
5
  Author-email: Brendan Dahl <dahl.brendan@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/dahlb/blueair_api
@@ -2,17 +2,17 @@ blueair_api/__init__.py,sha256=GucsIENhTF4AVxPn4Xyr4imUxJJ8RO8RYt1opHCF2hQ,326
2
2
  blueair_api/callbacks.py,sha256=eqgfe1qN_NNWOp2qNSP123zQJxh_Ie6vZXp5EHp6ePc,757
3
3
  blueair_api/const.py,sha256=fRth29dQT1dguM7L4ij8pDefB_vBrevAHqTdfNvSugs,1048
4
4
  blueair_api/device.py,sha256=Yz9M3-JmCUxaecVr98DcMT9hu6LAWUqarTcMwKfI064,2708
5
- blueair_api/device_aws.py,sha256=DZBE02Rae7z5qF7tdO3C1LuhTxaD-Y7jLoSuxysHdtc,5343
5
+ blueair_api/device_aws.py,sha256=bW82l0x0Avt2R2fN3O54aSh6fWm-2RsV8J7pUNkKTGg,5804
6
6
  blueair_api/errors.py,sha256=lJ_iFU_W6zQfGRi_wsMhWDw-fAVPFeCkCbT1erIlYQQ,233
7
7
  blueair_api/http_aws_blueair.py,sha256=m_qoCFOYICCu_U_maBvkmOha3YmNtxxtPYyapVBGKNc,17821
8
- blueair_api/http_blueair.py,sha256=Q-BOzObAPvfj1KqTxMR4MyhVMuH3FmKHlv7Lpd6PAEk,8335
8
+ blueair_api/http_blueair.py,sha256=Hs6U3SwO7gLgzoa55vWDaTLbw463kaS2VvGLSmAVJrQ,9409
9
9
  blueair_api/model_enum.py,sha256=85pb_SKLehDPvlW1ECRplPnhctjdxhy5e00_BiFo5Mk,2005
10
- blueair_api/stub.py,sha256=yJLfmrHjAH0XKl9HVTkKt-Ks9bG6Uhlkn3H2Jf3REJQ,1278
10
+ blueair_api/stub.py,sha256=sTWyRSDObzrXpZToAgDmZhCk3q8SsGN35h-kzMOqSOc,1272
11
11
  blueair_api/util.py,sha256=3L9-vfHfN1vUBYU0BA9ruYyNPUTmS21D-uI-Jyo5x6U,1672
12
- blueair_api/util_bootstrap.py,sha256=GSn0Ez7UQNajmPKyH3fpJdSwJYj-DbPqSc_wnYF94WM,1612
12
+ blueair_api/util_bootstrap.py,sha256=Vewg7mT1qSRgzOOJDrpXrVhGwcFPRnMrqhJVSIB-0AA,1688
13
13
  blueair_api/util_http.py,sha256=45AJG3Vb6LMVzI0WV22AoSyt64f_Jj3KpOAwF5M6EFE,1327
14
- blueair_api-1.20.1.dist-info/LICENSE,sha256=W6UV41yCe1R_Avet8VtsxwdJar18n40b3MRnbEMHZmI,1066
15
- blueair_api-1.20.1.dist-info/METADATA,sha256=UGF8BstvUBb23_Tw2wfKnAl8bq1k4ismLF_IN6dJsYw,1995
16
- blueair_api-1.20.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
- blueair_api-1.20.1.dist-info/top_level.txt,sha256=-gn0jNtmE83qEu70uMW5F4JrXnHGRfuFup1EPWF70oc,12
18
- blueair_api-1.20.1.dist-info/RECORD,,
14
+ blueair_api-1.21.0.dist-info/LICENSE,sha256=W6UV41yCe1R_Avet8VtsxwdJar18n40b3MRnbEMHZmI,1066
15
+ blueair_api-1.21.0.dist-info/METADATA,sha256=m9q98wOBkkEKBnGYACGx7eC1cStjT5art1IvMQfDgw0,1995
16
+ blueair_api-1.21.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
+ blueair_api-1.21.0.dist-info/top_level.txt,sha256=-gn0jNtmE83qEu70uMW5F4JrXnHGRfuFup1EPWF70oc,12
18
+ blueair_api-1.21.0.dist-info/RECORD,,