File: test_rest_api.py

package info (click to toggle)
python-aioambient 2024.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 472 kB
  • sloc: python: 755; sh: 41; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 930 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
"""Run an example script to quickly test."""
import asyncio
import logging

from aiohttp import ClientSession

from aioambient import API
from aioambient.errors import AmbientError

_LOGGER = logging.getLogger()

API_KEY = "<YOUR API KEY>"
APP_KEY = "<YOUR APPLICATION KEY>"


async def main() -> None:
    """Create the aiohttp session and run the example."""
    logging.basicConfig(level=logging.INFO)
    async with ClientSession() as session:
        try:
            api = API(APP_KEY, API_KEY, session=session)

            devices = await api.get_devices()
            _LOGGER.info("Devices: %s", devices)

            for device in devices:
                details = await api.get_device_details(device["macAddress"])
                _LOGGER.info("Device Details (%s): %s", device["macAddress"], details)

        except AmbientError as err:
            _LOGGER.error("There was an error: %s", err)


asyncio.run(main())