blueair-api 1.22.0__tar.gz → 1.23.0__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 (23) hide show
  1. {blueair_api-1.22.0 → blueair_api-1.23.0}/PKG-INFO +1 -1
  2. {blueair_api-1.22.0 → blueair_api-1.23.0}/pyproject.toml +1 -1
  3. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/device.py +20 -2
  4. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/http_blueair.py +2 -2
  5. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/util.py +19 -0
  6. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api.egg-info/PKG-INFO +1 -1
  7. {blueair_api-1.22.0 → blueair_api-1.23.0}/LICENSE +0 -0
  8. {blueair_api-1.22.0 → blueair_api-1.23.0}/README.md +0 -0
  9. {blueair_api-1.22.0 → blueair_api-1.23.0}/setup.cfg +0 -0
  10. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/__init__.py +0 -0
  11. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/callbacks.py +0 -0
  12. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/const.py +0 -0
  13. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/device_aws.py +0 -0
  14. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/errors.py +0 -0
  15. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/http_aws_blueair.py +0 -0
  16. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/model_enum.py +0 -0
  17. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/stub.py +0 -0
  18. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/util_bootstrap.py +0 -0
  19. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api/util_http.py +0 -0
  20. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api.egg-info/SOURCES.txt +0 -0
  21. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api.egg-info/dependency_links.txt +0 -0
  22. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api.egg-info/requires.txt +0 -0
  23. {blueair_api-1.22.0 → blueair_api-1.23.0}/src/blueair_api.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blueair_api
3
- Version: 1.22.0
3
+ Version: 1.23.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
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
8
8
 
9
9
  [project]
10
10
  name = "blueair_api"
11
- version = "1.22.0"
11
+ version = "1.23.0"
12
12
  authors = [
13
13
  { name="Brendan Dahl", email="dahl.brendan@gmail.com" },
14
14
  ]
@@ -3,6 +3,7 @@ import logging
3
3
 
4
4
  from .callbacks import CallbacksMixin
5
5
  from .http_blueair import HttpBlueair
6
+ from .util import transform_data_points, safely_get_json_value
6
7
 
7
8
  _LOGGER = logging.getLogger(__name__)
8
9
 
@@ -51,11 +52,18 @@ class Device(CallbacksMixin):
51
52
  filter_expired: bool | None = None
52
53
  wifi_working: bool | None = None
53
54
 
55
+ pm1: int | None = None
56
+ pm10: int | None = None
57
+ pm25: int | None = None
58
+ voc: int | None = None
59
+ co2: int | None = None
60
+ temperature: float | None = None
61
+ humidity: float | None = None
62
+ all_pollution: float | None = None
63
+
54
64
  async def refresh(self):
55
65
  _LOGGER.debug("Requesting current attributes...")
56
66
  attributes = await self.api.get_attributes(self.uuid)
57
- _data_points = await self.api.get_current_data_point(self.uuid)
58
- _data_points2 = await self.api.get_data_points_since(self.uuid)
59
67
  _LOGGER.debug(f"result: {attributes}")
60
68
  if "brightness" in attributes:
61
69
  self.brightness = int(attributes["brightness"])
@@ -73,6 +81,16 @@ class Device(CallbacksMixin):
73
81
  self.wifi_working = attributes["wifi_status"] == "1"
74
82
  else:
75
83
  self.wifi_working = False
84
+ for data_point in transform_data_points(await self.api.get_data_points_since(self.uuid)):
85
+ _LOGGER.debug(data_point)
86
+ self.pm25 = safely_get_json_value(data_point, "pm25", int)
87
+ self.pm10 = safely_get_json_value(data_point, "pm10", int)
88
+ self.pm1 = safely_get_json_value(data_point, "pm1", int)
89
+ self.voc = safely_get_json_value(data_point, "voc", int)
90
+ self.co2 = safely_get_json_value(data_point, "co2", int)
91
+ self.temperature = safely_get_json_value(data_point, "temperature", int)
92
+ self.humidity = safely_get_json_value(data_point, "humidity", int)
93
+ self.all_pollution = safely_get_json_value(data_point, "all_pollution", int)
76
94
  _LOGGER.debug(f"refreshed blueair device: {self}")
77
95
  self.publish_updates()
78
96
 
@@ -186,7 +186,7 @@ class HttpBlueair:
186
186
  available device information.
187
187
 
188
188
  Note: the data for this API call is only updated once every 5 minutes.
189
- Calling it more often will return the same respone from the server and
189
+ Calling it more often will return the same response from the server and
190
190
  should be avoided to limit server load.
191
191
  """
192
192
  url = f"https://{await self.get_home_host()}/v2/device/{device_uuid}/datapoint/0/last/0/"
@@ -209,7 +209,7 @@ class HttpBlueair:
209
209
  together. The minimum sample period size is 300 (5 minutes).
210
210
 
211
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
212
+ every 5 minutes. Calling it more often will return the same response
213
213
  from the server and should be avoided to limit server load.
214
214
  """
215
215
  url = f"https://{await self.get_home_host()}/v2/device/{device_uuid}/datapoint/{seconds_ago}/last/{sample_period}/"
@@ -51,3 +51,22 @@ def safely_get_json_value(json, key, callable_to_cast=None):
51
51
  if callable_to_cast is not None and value is not None:
52
52
  value = callable_to_cast(value)
53
53
  return value
54
+
55
+
56
+ def transform_data_points(data):
57
+ """Transform a measurement list response from the Blueair API to a more pythonic data structure."""
58
+ key_mapping = {
59
+ "time": "timestamp",
60
+ "pm": "pm25",
61
+ "pm1": "pm1",
62
+ "pm10": "pm10",
63
+ "tmp": "temperature",
64
+ "hum": "humidity",
65
+ "co2": "co2",
66
+ "voc": "voc",
67
+ "allpollu": "all_pollution",
68
+ }
69
+
70
+ keys = [key_mapping[key] for key in data["sensors"]]
71
+
72
+ return [dict(zip(keys, values)) for values in data["datapoints"]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blueair_api
3
- Version: 1.22.0
3
+ Version: 1.23.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
File without changes
File without changes
File without changes