airbeld-api-sdk 0.2.0__tar.gz → 0.4.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.
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/CHANGELOG.md +48 -0
- airbeld_api_sdk-0.4.0/PKG-INFO +564 -0
- airbeld_api_sdk-0.4.0/README.md +533 -0
- airbeld_api_sdk-0.4.0/examples/get_all_readings.py +103 -0
- airbeld_api_sdk-0.4.0/examples/get_historical_readings.py +101 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/examples/get_latest_readings.py +1 -1
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/examples/quickstart.py +2 -9
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/pyproject.toml +1 -1
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/__init__.py +4 -2
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/client.py +69 -22
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/models.py +31 -3
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/tests/test_client.py +161 -13
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/tests/test_models.py +93 -21
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/uv.lock +1 -1
- airbeld_api_sdk-0.2.0/PKG-INFO +0 -289
- airbeld_api_sdk-0.2.0/README.md +0 -258
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/.env.example +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/.gitignore +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/.ruff.toml +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/CONTRIBUTING.md +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/DEVELOPER.md +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/LICENSE +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/examples/.env.example +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/examples/login_and_list.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/mypy.ini +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/auth.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/exceptions.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/py.typed +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/src/airbeld/version.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/tests/test_auth.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.4.0}/tests/test_exceptions.py +0 -0
|
@@ -2,6 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2025-10-14
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- **Renamed `TelemetryBundle` → `Readings`** for naming consistency with API methods and clearer semantics
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **New endpoint `async_get_all_readings_by_date()`** - Fetch telemetry readings for all user devices in a single API call
|
|
14
|
+
- **New model `DeviceReadings`** - Device object with metadata and sensor readings, returned by `async_get_all_readings_by_date()`
|
|
15
|
+
- New example `examples/get_all_readings.py` demonstrating how to fetch readings for all devices
|
|
16
|
+
- Comprehensive API documentation for the new endpoint in README
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- API Reference documentation updated with `async_get_all_readings_by_date()` method and `DeviceReadings` model
|
|
21
|
+
- Model naming improved for consistency: `TelemetryBundle` → `Readings`
|
|
22
|
+
|
|
23
|
+
## [0.3.0] - 2025-10-14
|
|
24
|
+
|
|
25
|
+
### Breaking Changes
|
|
26
|
+
|
|
27
|
+
- **Query parameter names updated** to match actual API specification:
|
|
28
|
+
- `start` → `start_date` (now accepts `YYYY-MM-DD` string format or `'today'`, not datetime objects)
|
|
29
|
+
- `end` → `end_date` (now accepts `YYYY-MM-DD` string format or `'today'`, not datetime objects)
|
|
30
|
+
- `sensors` → `sensor` (now accepts single sensor name string, not a list)
|
|
31
|
+
- `aggregate` → `period` (values: `'hour'` or `'day'`)
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
|
|
35
|
+
- **Removed `device_uid` field** from `TelemetryBundle` model - the API response does not include device identifiers; the device is known from request context
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- New example `examples/get_historical_readings.py` demonstrating how to fetch multiple readings for a date range with hourly/daily aggregation
|
|
40
|
+
- Comprehensive documentation for historical readings in README
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- Updated all examples to use correct API parameter names
|
|
45
|
+
- Updated API contract documentation to reflect actual Swagger specification
|
|
46
|
+
- Simplified `TelemetryBundle` to match actual API response structure (sensors only)
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
|
|
50
|
+
- Query parameters now match the actual API specification from Swagger
|
|
51
|
+
- Date format changed from ISO 8601 timestamps to `YYYY-MM-DD` strings as required by the API
|
|
52
|
+
|
|
5
53
|
## [0.2.0] - 2025-10-13
|
|
6
54
|
|
|
7
55
|
### Added
|
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airbeld-api-sdk
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Async Python SDK for the Airbeld backend
|
|
5
|
+
Project-URL: Changelog, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/CHANGELOG.md
|
|
6
|
+
Project-URL: Documentation, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/README.md
|
|
7
|
+
Project-URL: Homepage, https://github.com/Embio-Diagnostics/airbeld-api-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/Embio-Diagnostics/airbeld-api-sdk/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/Embio-Diagnostics/airbeld-api-sdk
|
|
10
|
+
Author-email: Embio Diagnostics Ltd <l.dougiakis@embiodiagnostics.eu>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: air-quality,airbeld,home-assistant
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: httpx>=0.28.1
|
|
20
|
+
Requires-Dist: pydantic>=2.11.7
|
|
21
|
+
Requires-Dist: tenacity>=9.1.2
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
24
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
25
|
+
Requires-Dist: pydantic>=2.7; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
29
|
+
Requires-Dist: tenacity>=8.2; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Airbeld Python SDK
|
|
33
|
+
|
|
34
|
+
[](https://pypi.org/project/airbeld-api-sdk/)
|
|
35
|
+
[](https://pypi.org/project/airbeld-api-sdk/)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
Async Python SDK for the Airbeld API, providing access to air quality devices and telemetry data.
|
|
39
|
+
|
|
40
|
+
> If you want to **contribute**, read [CONTRIBUTING](CONTRIBUTING.md) and [DEVELOPER](DEVELOPER.md).
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Using pip
|
|
48
|
+
pip install airbeld-api-sdk
|
|
49
|
+
|
|
50
|
+
# Using uv (recommended)
|
|
51
|
+
uv add airbeld-api-sdk
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Examples
|
|
55
|
+
|
|
56
|
+
### Running Examples
|
|
57
|
+
|
|
58
|
+
All examples require setting environment variables before running:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Export required environment variables
|
|
62
|
+
export AIRBELD_API_BASE="https://api.airbeld.com"
|
|
63
|
+
export AIRBELD_API_TOKEN="your-jwt-token-here"
|
|
64
|
+
|
|
65
|
+
# Run an example
|
|
66
|
+
python examples/quickstart.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Environment Variables:**
|
|
70
|
+
|
|
71
|
+
- `AIRBELD_API_BASE`: API base URL (default: `https://api.airbeld.com`)
|
|
72
|
+
- `AIRBELD_API_TOKEN`: JWT access token for authentication
|
|
73
|
+
|
|
74
|
+
### Quickstart Example
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import asyncio
|
|
78
|
+
import os
|
|
79
|
+
from airbeld import AirbeldClient
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
# Initialize client (JWT token obtained outside SDK)
|
|
83
|
+
base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
|
|
84
|
+
token = os.environ["AIRBELD_API_TOKEN"]
|
|
85
|
+
|
|
86
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
87
|
+
# Get all devices
|
|
88
|
+
devices = await client.async_get_devices()
|
|
89
|
+
print(f"Found {len(devices)} devices")
|
|
90
|
+
|
|
91
|
+
if devices:
|
|
92
|
+
device = devices[0]
|
|
93
|
+
print(f"Device: {device.name} ({device.status})")
|
|
94
|
+
|
|
95
|
+
# Get latest telemetry readings (no date range)
|
|
96
|
+
readings = await client.async_get_readings_by_date(
|
|
97
|
+
device_id=device.id,
|
|
98
|
+
sensor="temperature" # Optional: filter to single sensor
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Print latest temperature reading
|
|
102
|
+
if "temperature" in readings.sensors:
|
|
103
|
+
latest_temp = readings.get_latest_value("temperature")
|
|
104
|
+
print(f"Latest temperature: {latest_temp}°C")
|
|
105
|
+
|
|
106
|
+
if __name__ == "__main__":
|
|
107
|
+
asyncio.run(main())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Note:** JWT token acquisition happens outside the SDK. The SDK only handles API requests with a ready token.
|
|
111
|
+
|
|
112
|
+
### Getting Latest Readings
|
|
113
|
+
|
|
114
|
+
You can fetch the latest sensor readings without specifying a date range:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import asyncio
|
|
118
|
+
import os
|
|
119
|
+
from airbeld import AirbeldClient
|
|
120
|
+
|
|
121
|
+
async def main():
|
|
122
|
+
base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
|
|
123
|
+
token = os.environ["AIRBELD_API_TOKEN"]
|
|
124
|
+
|
|
125
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
126
|
+
devices = await client.async_get_devices()
|
|
127
|
+
|
|
128
|
+
if devices:
|
|
129
|
+
device = devices[0]
|
|
130
|
+
|
|
131
|
+
# Get latest readings without specifying start_date/end_date
|
|
132
|
+
readings = await client.async_get_readings_by_date(device_id=device.id)
|
|
133
|
+
|
|
134
|
+
# Display latest values
|
|
135
|
+
for sensor_name, metric in readings.sensors.items():
|
|
136
|
+
latest = readings.get_latest_value(sensor_name)
|
|
137
|
+
print(f"{metric.display_name}: {latest} {metric.unit}")
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
asyncio.run(main())
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Getting Historical Readings
|
|
144
|
+
|
|
145
|
+
Fetch sensor readings for a specific date range with hourly or daily aggregation:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import asyncio
|
|
149
|
+
import os
|
|
150
|
+
from airbeld import AirbeldClient
|
|
151
|
+
|
|
152
|
+
async def main():
|
|
153
|
+
base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
|
|
154
|
+
token = os.environ["AIRBELD_API_TOKEN"]
|
|
155
|
+
|
|
156
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
157
|
+
devices = await client.async_get_devices()
|
|
158
|
+
|
|
159
|
+
if devices:
|
|
160
|
+
device = devices[0]
|
|
161
|
+
|
|
162
|
+
# Get hourly readings for a specific date range
|
|
163
|
+
readings = await client.async_get_readings_by_date(
|
|
164
|
+
device_id=device.id,
|
|
165
|
+
start_date="2025-09-19", # Format: YYYY-MM-DD or 'today'
|
|
166
|
+
end_date="2025-09-19", # Same day = 24 hours of data
|
|
167
|
+
period="hour", # Aggregation: 'hour' or 'day'
|
|
168
|
+
sensor="temperature" # Optional: single sensor filter
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Access all temperature values
|
|
172
|
+
if "temperature" in readings.sensors:
|
|
173
|
+
temp_metric = readings.sensors["temperature"]
|
|
174
|
+
print(f"Temperature readings: {len(temp_metric.values)} values")
|
|
175
|
+
|
|
176
|
+
for reading in temp_metric.values:
|
|
177
|
+
print(f" {reading.timestamp}: {reading.value}°C")
|
|
178
|
+
|
|
179
|
+
if __name__ == "__main__":
|
|
180
|
+
asyncio.run(main())
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## API Reference
|
|
184
|
+
|
|
185
|
+
### Client Methods
|
|
186
|
+
|
|
187
|
+
#### `AirbeldClient(token, base_url, timeout)`
|
|
188
|
+
|
|
189
|
+
Initialize the Airbeld API client.
|
|
190
|
+
|
|
191
|
+
**Parameters:**
|
|
192
|
+
- `token` (str, required): JWT access token for authentication
|
|
193
|
+
- `base_url` (str, optional): API base URL. Default: `"https://api.airbeld.com"`
|
|
194
|
+
- `timeout` (float, optional): Request timeout in seconds. Default: `10.0`
|
|
195
|
+
|
|
196
|
+
**Usage:**
|
|
197
|
+
```python
|
|
198
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
199
|
+
# Use client...
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
#### `async_get_devices()`
|
|
205
|
+
|
|
206
|
+
Get list of all devices.
|
|
207
|
+
|
|
208
|
+
**Parameters:** None
|
|
209
|
+
|
|
210
|
+
**Returns:** `list[DeviceSummary]` - List of device objects
|
|
211
|
+
|
|
212
|
+
**Raises:**
|
|
213
|
+
- `AuthError`: Authentication failed (401/403)
|
|
214
|
+
- `ApiError`: Other API errors (4xx/5xx)
|
|
215
|
+
- `NetworkError`: Network connectivity issues
|
|
216
|
+
|
|
217
|
+
**Example:**
|
|
218
|
+
```python
|
|
219
|
+
devices = await client.async_get_devices()
|
|
220
|
+
for device in devices:
|
|
221
|
+
print(f"{device.name} - {device.status}")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
#### `async_get_readings_by_date(device_id, start_date, end_date, sensor, period)`
|
|
227
|
+
|
|
228
|
+
Get telemetry readings for a device.
|
|
229
|
+
|
|
230
|
+
**Parameters:**
|
|
231
|
+
- `device_id` (int, required): Device ID
|
|
232
|
+
- `start_date` (str, optional): Start date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
233
|
+
- `end_date` (str, optional): End date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
234
|
+
- `sensor` (str, optional): Single sensor name to filter (e.g., `"temperature"`, `"pm2p5"`). If omitted, returns all sensors.
|
|
235
|
+
- `period` (str, optional): Data aggregation period. Values: `"hour"` or `"day"`.
|
|
236
|
+
|
|
237
|
+
**Returns:** `Readings` - Object containing sensor readings
|
|
238
|
+
|
|
239
|
+
**Raises:**
|
|
240
|
+
- `AuthError`: Authentication failed (401/403)
|
|
241
|
+
- `ApiError`: API errors including 404 (device not found), 413 (range too large)
|
|
242
|
+
- `RateLimitError`: Rate limit exceeded (429)
|
|
243
|
+
- `NetworkError`: Network connectivity issues
|
|
244
|
+
|
|
245
|
+
**Examples:**
|
|
246
|
+
```python
|
|
247
|
+
# Get latest readings (no date range)
|
|
248
|
+
readings = await client.async_get_readings_by_date(device_id=123)
|
|
249
|
+
|
|
250
|
+
# Get historical readings with date range
|
|
251
|
+
readings = await client.async_get_readings_by_date(
|
|
252
|
+
device_id=123,
|
|
253
|
+
start_date="2025-09-19",
|
|
254
|
+
end_date="2025-09-19",
|
|
255
|
+
period="hour"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# Filter to single sensor
|
|
259
|
+
readings = await client.async_get_readings_by_date(
|
|
260
|
+
device_id=123,
|
|
261
|
+
sensor="temperature"
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
#### `async_get_all_readings_by_date(start_date, end_date, sensor, period)`
|
|
268
|
+
|
|
269
|
+
Get telemetry readings for all user devices.
|
|
270
|
+
|
|
271
|
+
**Parameters:**
|
|
272
|
+
- `start_date` (str, optional): Start date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
273
|
+
- `end_date` (str, optional): End date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
274
|
+
- `sensor` (str, optional): Single sensor name to filter (e.g., `"temperature"`, `"pm2p5"`). If omitted, returns all sensors.
|
|
275
|
+
- `period` (str, optional): Data aggregation period. Values: `"hour"` or `"day"`.
|
|
276
|
+
|
|
277
|
+
**Returns:** `list[DeviceReadings]` - List of device objects with metadata and sensor readings
|
|
278
|
+
|
|
279
|
+
**Raises:**
|
|
280
|
+
- `AuthError`: Authentication failed (401/403)
|
|
281
|
+
- `ApiError`: API errors including 413 (range too large)
|
|
282
|
+
- `RateLimitError`: Rate limit exceeded (429)
|
|
283
|
+
- `NetworkError`: Network connectivity issues
|
|
284
|
+
|
|
285
|
+
**Examples:**
|
|
286
|
+
```python
|
|
287
|
+
# Get latest readings for all devices
|
|
288
|
+
devices = await client.async_get_all_readings_by_date()
|
|
289
|
+
for device in devices:
|
|
290
|
+
print(f"Device: {device.display_name or device.name}")
|
|
291
|
+
temp = device.get_latest_value("temperature")
|
|
292
|
+
print(f" Temperature: {temp}°C")
|
|
293
|
+
|
|
294
|
+
# Get historical readings with date range
|
|
295
|
+
devices = await client.async_get_all_readings_by_date(
|
|
296
|
+
start_date="2025-10-14",
|
|
297
|
+
end_date="2025-10-14",
|
|
298
|
+
period="hour"
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
# Filter to single sensor
|
|
302
|
+
devices = await client.async_get_all_readings_by_date(
|
|
303
|
+
sensor="pm2p5"
|
|
304
|
+
)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
#### `set_token(new_token)`
|
|
310
|
+
|
|
311
|
+
Update the authorization token at runtime.
|
|
312
|
+
|
|
313
|
+
**Parameters:**
|
|
314
|
+
- `new_token` (str, required): New JWT access token
|
|
315
|
+
|
|
316
|
+
**Returns:** None
|
|
317
|
+
|
|
318
|
+
**Example:**
|
|
319
|
+
```python
|
|
320
|
+
client.set_token(refreshed_token)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Authentication Functions
|
|
324
|
+
|
|
325
|
+
#### `async_login(base_url, email, password, timeout)`
|
|
326
|
+
|
|
327
|
+
Authenticate with email and password to obtain JWT tokens.
|
|
328
|
+
|
|
329
|
+
**Parameters:**
|
|
330
|
+
- `base_url` (str, required): API base URL
|
|
331
|
+
- `email` (str, required): User email address
|
|
332
|
+
- `password` (str, required): User password
|
|
333
|
+
- `timeout` (float, optional): Request timeout in seconds. Default: `10.0`
|
|
334
|
+
|
|
335
|
+
**Returns:** `TokenSet` - Object containing access token, refresh token, expires_in, and token_type
|
|
336
|
+
|
|
337
|
+
**Raises:**
|
|
338
|
+
- `AuthError`: Invalid credentials (401)
|
|
339
|
+
- `RateLimitError`: Rate limit exceeded (429)
|
|
340
|
+
- `ApiError`: Other API errors (4xx/5xx)
|
|
341
|
+
- `NetworkError`: Network connectivity issues
|
|
342
|
+
|
|
343
|
+
**Example:**
|
|
344
|
+
```python
|
|
345
|
+
from airbeld import async_login
|
|
346
|
+
|
|
347
|
+
token_set = await async_login(
|
|
348
|
+
base_url="https://api.airbeld.com",
|
|
349
|
+
email="user@example.com",
|
|
350
|
+
password="password"
|
|
351
|
+
)
|
|
352
|
+
print(f"Access token: {token_set.access_token}")
|
|
353
|
+
print(f"Expires in: {token_set.expires_in} seconds")
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Data Models
|
|
357
|
+
|
|
358
|
+
#### `DeviceSummary`
|
|
359
|
+
|
|
360
|
+
Device information object.
|
|
361
|
+
|
|
362
|
+
**Attributes:**
|
|
363
|
+
- `uid` (str): Unique device identifier
|
|
364
|
+
- `id` (int): Device ID
|
|
365
|
+
- `name` (str): Device name
|
|
366
|
+
- `display_name` (str | None): Custom display name
|
|
367
|
+
- `description` (str): Device description
|
|
368
|
+
- `type` (str | None): Device type
|
|
369
|
+
- `is_locked` (bool): Whether device is locked
|
|
370
|
+
- `status` (str): Device status - `"online"` or `"offline"`
|
|
371
|
+
- `sector` (str | None): Sector name
|
|
372
|
+
- `sector_id` (int | None): Sector ID
|
|
373
|
+
- `location` (str | None): Location name
|
|
374
|
+
- `location_id` (int | None): Location ID
|
|
375
|
+
- `timezone` (str): IANA timezone
|
|
376
|
+
|
|
377
|
+
#### `DeviceReadings`
|
|
378
|
+
|
|
379
|
+
Device with telemetry readings (returned by `async_get_all_readings_by_date`).
|
|
380
|
+
|
|
381
|
+
**Attributes:**
|
|
382
|
+
- `id` (int): Device ID
|
|
383
|
+
- `uid` (str): Unique device identifier
|
|
384
|
+
- `name` (str): Device name
|
|
385
|
+
- `display_name` (str | None): Custom display name
|
|
386
|
+
- `location` (str | None): Location name
|
|
387
|
+
- `sector` (str | None): Sector name
|
|
388
|
+
- `timezone` (str): IANA timezone
|
|
389
|
+
- `sensors` (dict[str, TelemetryMetric]): Dictionary of sensor metrics by sensor name
|
|
390
|
+
|
|
391
|
+
**Methods:**
|
|
392
|
+
- `get_latest_value(metric_name: str) -> float | None`: Get the latest value for a specific sensor
|
|
393
|
+
- `pm2_5` (property): Shortcut to access PM 2.5 metric (returns `TelemetryMetric | None`)
|
|
394
|
+
|
|
395
|
+
#### `Readings`
|
|
396
|
+
|
|
397
|
+
Container for sensor readings.
|
|
398
|
+
|
|
399
|
+
**Attributes:**
|
|
400
|
+
- `sensors` (dict[str, TelemetryMetric]): Dictionary of sensor metrics by sensor name
|
|
401
|
+
|
|
402
|
+
**Methods:**
|
|
403
|
+
- `get_latest_value(metric_name: str) -> float | None`: Get the latest value for a specific sensor
|
|
404
|
+
- `pm2_5` (property): Shortcut to access PM 2.5 metric (returns `TelemetryMetric | None`)
|
|
405
|
+
|
|
406
|
+
#### `TelemetryMetric`
|
|
407
|
+
|
|
408
|
+
Individual sensor metric with metadata and values.
|
|
409
|
+
|
|
410
|
+
**Attributes:**
|
|
411
|
+
- `name` (str): Sensor name
|
|
412
|
+
- `display_name` (str | None): Display name
|
|
413
|
+
- `unit` (str): Measurement unit
|
|
414
|
+
- `description` (str | None): Sensor description
|
|
415
|
+
- `values` (list[TelemetryValue]): List of readings
|
|
416
|
+
|
|
417
|
+
#### `TelemetryValue`
|
|
418
|
+
|
|
419
|
+
Single sensor reading.
|
|
420
|
+
|
|
421
|
+
**Attributes:**
|
|
422
|
+
- `timestamp` (datetime): Reading timestamp
|
|
423
|
+
- `value` (float | None): Measured value
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## Authentication Options
|
|
428
|
+
|
|
429
|
+
The SDK supports two authentication paths depending on your use case:
|
|
430
|
+
|
|
431
|
+
### Home Assistant Integration
|
|
432
|
+
|
|
433
|
+
For Home Assistant users, authentication is handled by the integration:
|
|
434
|
+
|
|
435
|
+
- Home Assistant performs OAuth2 flow automatically
|
|
436
|
+
- SDK receives a ready JWT token from the integration
|
|
437
|
+
- See [docs/home-assistant-auth.md](docs/home-assistant-auth.md) for details
|
|
438
|
+
|
|
439
|
+
### Standalone Applications (CLI, Scripts, etc.)
|
|
440
|
+
|
|
441
|
+
For standalone applications, use the built-in authentication:
|
|
442
|
+
|
|
443
|
+
```python
|
|
444
|
+
import asyncio
|
|
445
|
+
import os
|
|
446
|
+
from airbeld import async_login, AirbeldClient
|
|
447
|
+
|
|
448
|
+
async def main():
|
|
449
|
+
# Authenticate with email/password
|
|
450
|
+
token_set = await async_login(
|
|
451
|
+
base_url="https://api.airbeld.com",
|
|
452
|
+
email=os.environ["AIRBELD_USER_EMAIL"],
|
|
453
|
+
password=os.environ["AIRBELD_USER_PASSWORD"]
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
# Create client with access token
|
|
457
|
+
async with AirbeldClient(token=token_set.access_token) as client:
|
|
458
|
+
# List devices
|
|
459
|
+
devices = await client.async_get_devices()
|
|
460
|
+
print(f"Found {len(devices)} devices:")
|
|
461
|
+
|
|
462
|
+
for device in devices:
|
|
463
|
+
print(f" - {device.name} ({device.status})")
|
|
464
|
+
|
|
465
|
+
if __name__ == "__main__":
|
|
466
|
+
asyncio.run(main())
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
**⚠️ Security Warning:** Never commit real credentials or tokens to version control. Use environment variables or secure secret storage systems.
|
|
470
|
+
|
|
471
|
+
### Token Management
|
|
472
|
+
|
|
473
|
+
For applications requiring token refresh or runtime token updates:
|
|
474
|
+
|
|
475
|
+
```python
|
|
476
|
+
# Update token at runtime
|
|
477
|
+
client.set_token(new_token)
|
|
478
|
+
|
|
479
|
+
# Or use refresh token (if implemented)
|
|
480
|
+
new_token_set = await async_login(...)
|
|
481
|
+
client.set_token(new_token_set.access_token)
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
---
|
|
485
|
+
|
|
486
|
+
## Development
|
|
487
|
+
|
|
488
|
+
### Installation
|
|
489
|
+
|
|
490
|
+
Using uv (recommended):
|
|
491
|
+
```bash
|
|
492
|
+
# Clone the repository
|
|
493
|
+
git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
|
|
494
|
+
cd airbeld-api-sdk
|
|
495
|
+
|
|
496
|
+
# Create virtual environment and install dependencies
|
|
497
|
+
uv sync
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Using pip:
|
|
501
|
+
```bash
|
|
502
|
+
# Clone the repository
|
|
503
|
+
git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
|
|
504
|
+
cd airbeld-api-sdk
|
|
505
|
+
|
|
506
|
+
# Create and activate virtual environment
|
|
507
|
+
python -m venv .venv
|
|
508
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
509
|
+
|
|
510
|
+
# Install package with dev dependencies
|
|
511
|
+
pip install -e ".[dev]"
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Running Tests
|
|
515
|
+
|
|
516
|
+
```bash
|
|
517
|
+
# Using uv
|
|
518
|
+
uv run pytest
|
|
519
|
+
|
|
520
|
+
# Or with pip
|
|
521
|
+
pytest
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Linting and Formatting
|
|
525
|
+
|
|
526
|
+
```bash
|
|
527
|
+
# Check code style
|
|
528
|
+
uv run ruff check .
|
|
529
|
+
|
|
530
|
+
# Format code
|
|
531
|
+
uv run ruff format .
|
|
532
|
+
|
|
533
|
+
# Or with pip
|
|
534
|
+
ruff check .
|
|
535
|
+
ruff format .
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Type Checking
|
|
539
|
+
|
|
540
|
+
```bash
|
|
541
|
+
# Using uv
|
|
542
|
+
uv run mypy src
|
|
543
|
+
|
|
544
|
+
# Or with pip
|
|
545
|
+
mypy src
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Building the Package
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
# Using uv
|
|
552
|
+
uv build
|
|
553
|
+
|
|
554
|
+
# Or with pip
|
|
555
|
+
python -m build
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
## Resources
|
|
561
|
+
|
|
562
|
+
- **Contributing:** See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines
|
|
563
|
+
- **Changelog:** See [CHANGELOG.md](CHANGELOG.md) for version history
|
|
564
|
+
- **License:** This project is licensed under the MIT License - see [LICENSE](LICENSE) file for details
|