File: remote.py

package info (click to toggle)
python-awair 0.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,020 kB
  • sloc: python: 1,041; makefile: 15; sh: 5
file content (36 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
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
"""Remote sensors example."""

import os
import asyncio
import aiohttp
from python_awair import Awair


async def fetch_data():
    """Fetch remote data."""
    async with aiohttp.ClientSession() as session:
        # Instantiate a client with your access token, and an asyncio session:
        token = os.environ.get("AWAIR_TOKEN")
        client = Awair(access_token=token, session=session)

        # Retrieve a user object:
        user = await client.user()

        # List that user's devices:
        devices = await user.devices()

        # Get some air quality data for a user's device:
        data = await devices[0].air_data_latest()

        # Print things out!
        print(f"Device: {devices[0]}")

        # You can access sensors as dict items:
        for sensor, value in data.sensors.items():
            print(f"  {sensor}: {round(value, 2)}")

        # Or, as attributes:
        print(f"  temperature again: {round(data.sensors.temperature, 2)}")


asyncio.run(fetch_data())