forked from home-assistant-ecosystem/python-luftdaten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
30 lines (20 loc) · 777 Bytes
/
example.py
File metadata and controls
30 lines (20 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Example for getting the data from a station."""
import asyncio
import aiohttp
from luftdaten import Luftdaten
SENSOR_ID = 155
async def main():
"""Sample code to retrieve the data."""
async with aiohttp.ClientSession() as session:
data = Luftdaten(SENSOR_ID, loop, session)
await data.get_data()
if not await data.validate_sensor():
print("Station is not available:", data.sensor_id)
return
if data.values and data.meta:
# Print the sensor values
print("Sensor values:", data.values)
# Print the coordinates fo the sensor
print("Location:", data.meta['latitude'], data.meta['longitude'])
loop = asyncio.get_event_loop()
loop.run_until_complete(main())