airthings-cloud 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: airthings_cloud
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: A python3 library to communicate with Airthings devices
5
5
  Home-page: https://github.com/Danielhiversen/pyAirthings
6
6
  Author: Daniel Hjelseth Høyer
@@ -11,7 +11,15 @@ Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
- Requires-Python: >=3.7.0
14
+ Requires-Python: >=3.13.0
15
15
  License-File: LICENSE
16
- Requires-Dist: aiohttp>=3.0.6
17
- Requires-Dist: async_timeout>=3.0.0
16
+ Requires-Dist: aiohttp>=3.13.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
@@ -7,7 +7,6 @@ import json
7
7
  import logging
8
8
 
9
9
  from aiohttp import ClientError
10
- import async_timeout
11
10
 
12
11
  _LOGGER = logging.getLogger(__name__)
13
12
 
@@ -84,14 +83,20 @@ class Airthings:
84
83
  self._locations = []
85
84
  self._devices = {}
86
85
 
86
+ async def _fetch_locations(self):
87
+ response = await self._request(API_URL + "locations")
88
+ json_data = await response.json()
89
+ self._locations = []
90
+ for location in json_data.get("locations"):
91
+ self._locations.append(AirthingsLocation.init_from_response(location))
92
+
87
93
  async def update_devices(self):
88
94
  """Update data."""
95
+ locations_fetched = False
96
+
89
97
  if not self._locations:
90
- response = await self._request(API_URL + "locations")
91
- json_data = await response.json()
92
- self._locations = []
93
- for location in json_data.get("locations"):
94
- self._locations.append(AirthingsLocation.init_from_response(location))
98
+ await self._fetch_locations()
99
+ locations_fetched = True
95
100
  if not self._devices:
96
101
  response = await self._request(API_URL + "devices")
97
102
  json_data = await response.json()
@@ -112,11 +117,16 @@ class Airthings:
112
117
  continue
113
118
  if devices := json_data.get("devices"):
114
119
  for device in devices:
115
- id = device.get('id')
116
- res[id] = AirthingsDevice.init_from_response(
120
+ if not isinstance(device, dict) or 'id' not in device:
121
+ if not locations_fetched:
122
+ _LOGGER.debug("Device has no id, fetching locations again")
123
+ await self._fetch_locations()
124
+ locations_fetched = True
125
+ device_id = device.get('id')
126
+ res[device_id] = AirthingsDevice.init_from_response(
117
127
  device,
118
128
  location.name,
119
- self._devices.get(id)
129
+ self._devices.get(device_id)
120
130
  )
121
131
  else:
122
132
  _LOGGER.debug("No devices in location '%s'", location.name)
@@ -133,7 +143,7 @@ class Airthings:
133
143
 
134
144
  headers = {"Authorization": self._access_token}
135
145
  try:
136
- async with async_timeout.timeout(TIMEOUT):
146
+ async with asyncio.timeout(TIMEOUT):
137
147
  if json_data:
138
148
  response = await self._websession.post(
139
149
  url, json=json_data, headers=headers
@@ -168,7 +178,7 @@ class Airthings:
168
178
  async def get_token(websession, client_id, secret, retry=3, timeout=10):
169
179
  """Get token for Airthings."""
170
180
  try:
171
- async with async_timeout.timeout(timeout):
181
+ async with asyncio.timeout(timeout):
172
182
  response = await websession.post(
173
183
  "https://accounts-api.airthings.com/v1/token",
174
184
  headers={
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: airthings_cloud
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: A python3 library to communicate with Airthings devices
5
5
  Home-page: https://github.com/Danielhiversen/pyAirthings
6
6
  Author: Daniel Hjelseth Høyer
@@ -11,7 +11,15 @@ Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
- Requires-Python: >=3.7.0
14
+ Requires-Python: >=3.13.0
15
15
  License-File: LICENSE
16
- Requires-Dist: aiohttp>=3.0.6
17
- Requires-Dist: async_timeout>=3.0.0
16
+ Requires-Dist: aiohttp>=3.13.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
@@ -0,0 +1 @@
1
+ aiohttp>=3.13.0
@@ -3,10 +3,10 @@ from setuptools import setup
3
3
  setup(
4
4
  name="airthings_cloud",
5
5
  packages=["airthings"],
6
- install_requires=["aiohttp>=3.0.6", "async_timeout>=3.0.0"],
7
- version="0.2.0",
6
+ install_requires=["aiohttp>=3.13.0"],
7
+ version="0.3.0",
8
8
  description="A python3 library to communicate with Airthings devices",
9
- python_requires=">=3.7.0",
9
+ python_requires=">=3.13.0",
10
10
  author="Daniel Hjelseth Høyer",
11
11
  author_email="github@dahoiv.net",
12
12
  url="https://github.com/Danielhiversen/pyAirthings",
@@ -1,2 +0,0 @@
1
- aiohttp>=3.0.6
2
- async_timeout>=3.0.0
File without changes