-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
54 lines (43 loc) · 1.38 KB
/
example.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""An example of using Nettigo Air Monitor package."""
import asyncio
import logging
from aiohttp import ClientConnectorError, ClientError, ClientSession
from tenacity import RetryError
from nettigo_air_monitor import (
ApiError,
AuthFailedError,
ConnectionOptions,
InvalidSensorDataError,
NettigoAirMonitor,
)
logging.basicConfig(level=logging.DEBUG)
HOST = "nam"
USERNAME = "user"
PASSWORD = "password"
async def main() -> None:
"""Run main function."""
options = ConnectionOptions(host=HOST, username=USERNAME, password=PASSWORD)
async with ClientSession() as websession:
nam = await NettigoAirMonitor.create(websession, options)
try:
data = await nam.async_update()
mac = await nam.async_get_mac_address()
except (
TimeoutError,
ApiError,
AuthFailedError,
ClientConnectorError,
ClientError,
InvalidSensorDataError,
RetryError,
) as error:
print(f"Error: {error}")
else:
print(f"Auth enabled: {nam.auth_enabled}")
print(f"Firmware: {nam.software_version}")
print(f"MAC address: {mac}")
print(f"Latitude: {nam.latitude}, Longitude: {nam.longitude}")
print(f"Data: {data}")
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()