Skip to main content

Python Wrappers for AirThings API

Project description

airthings-api

Description

Python Wrappers for AirThings API

Installation

Usage (Jupyter)

NB: You can now use async/await at the top level in the IPython terminal and in the notebook, it should — in most of the cases — “just work”. Update IPython to version 7+, IPykernel to version 5+.

# import the library
ata = __import__('airthings-api')
import aiohttp

session = aiohttp.ClientSession()

# Create an API manager; use your dashboard's credentials
manager = ata.api.web.AirThingsManager(
    username='jdoe@gmail.com', 
    password='xxxxxxxx',
    session=session) 

# Get the 'me' instance
me = await manager.get_me_instance()

print(me.email)
# Should be 'jdoe@gmail.com' I guess

# Get the 'locations' instances
locations_instance = await manager.get_locations_instance()

# Print devices and sensor values
for location in locations_instance.locations:
    for device in location.devices:
        print('device: {0}'.format(device.room_name))

        for current_sensor_value in device.current_sensor_values:
            print('  {0}: {1} {2}'.format(
                current_sensor_value.type_,
                current_sensor_value.value,
                current_sensor_value.provided_unit))

await session.close()

# device: Wave Mini
#   temp: 21.6 c
#   humidity: 41.0 pct
#   voc: 253.0 ppb
#   mold: 0.0 riskIndex
# device: Wave
#   radonShortTermAvg: 103.0 bq
#   temp: 20.5 c
#   humidity: 47.0 pct
# device: Hub AirThings

Usage (Python file)

NB: If you run in a Python file, wrapping the call within asyncio.run(...) will do the trick.

ata = __import__('airthings-api')
import aiohttp
import asyncio


async def test():

    session = aiohttp.ClientSession()

    # Create an API manager; use your dashboard's credentials
    manager = ata.api.web.AirThingsManager(
        username='jdoe@gmail.com', 
        password='xxxxxxxx',
        session=session) 

    # Get the 'me' instance
    me = await manager.get_me_instance()

    print(me.email)
    # Should be 'jdoe@gmail.com' I guess

    # Get the 'locations' instances
    locations_instance = await manager.get_locations_instance()

    # Print devices and sensor values
    for location in locations_instance.locations:
        for device in location.devices:
            print('device: {0}'.format(device.room_name))

            for current_sensor_value in device.current_sensor_values:
                print('  {0}: {1} {2}'.format(
                    current_sensor_value.type_,
                    current_sensor_value.value,
                    current_sensor_value.provided_unit))

    await session.close()

    # device: Wave Mini
    #   temp: 21.6 c
    #   humidity: 41.0 pct
    #   voc: 253.0 ppb
    #   mold: 0.0 riskIndex
    # device: Wave
    #   radonShortTermAvg: 103.0 bq
    #   temp: 20.5 c
    #   humidity: 47.0 pct
    # device: Hub AirThings


if __name__ == '__main__':

    asyncio.run(test())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

AirThings-API-0.1.5.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

AirThings_API-0.1.5-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file AirThings-API-0.1.5.tar.gz.

File metadata

  • Download URL: AirThings-API-0.1.5.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for AirThings-API-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ad2236ea06a19c876f7da6b4b39c2a6b1c88f5f22c5e8c8ebd60e0c7ce7e9178
MD5 32e226def32e8350f6d32c17e8c4582d
BLAKE2b-256 d8fb15ee7fe2d7876a2fe64ae470fb863113f394ec871a651a6a28fe0f1c81a9

See more details on using hashes here.

File details

Details for the file AirThings_API-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: AirThings_API-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for AirThings_API-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 68466322cb18ed3993b189c178b14cc51b0a5a2143d55ab026b0b7402491b77a
MD5 d5e05934b65632c9c1b1b86c16852867
BLAKE2b-256 d8703947828d061a13321852340dc50a3ebffb0ef2d7202ab010507a9c9d744a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page