Skip to main content

Talk to the Hubspace API asynchronously

Project description

Connects to Afero cloud API and provides an easy way to interact with devices.

This project was designed to asynchronously connect to the Afero IOT API. It has the ability to retrieve the devices and set new states.

https://github.com/Expl0dingBanana/aioafero/actions/workflows/cicd.yaml/badge.svg?branch=main https://codecov.io/github/Expl0dingBanana/aioafero/graph/badge.svg?token=NP2RE4I4XK

Overview

All data is stored within a “bridge” that knows of all of the devices aligned with the Afero IOT account. This bridge contains multiple controllers for each device type. These controllers know how to interact with the Afero IOT devices. Each controller manages the device’s states. To retrieve a device, you must query bridge.<controller>.get_device(<device_id>) which will return a model containing all the states. Any changes to the model will not update Afero IOT as the correct call needs to be made.

Controllers

The following controllers are implemented:

  • bridge.devices: Top-level devices (such as a ceiling-fan, or light that

    is not associated with another device). These entities also contain their respective sensors and binary sensors. This is purely an informational controller and cannot set any states.

  • bridge.fans: Any device that matches a fan. Can perform the following actions:

    • turn_on

    • turn_off

    • set_speed

    • set_direction

    • set_preset

  • bridge.lights: Any device that matches a fan. Can perform the following actions:

    • turn_on

    • turn_off

    • set_color_temperature

    • set_brightness

    • set_rgb

    • set_effect

  • bridge.locks: Any device that matches a lock. Can perform the following actions:

    • lock

    • unlock

  • bridge.portable_acs: Any device that matches a portable-ac. Can perform the following actions:

    • Everything is done through set_state

  • bridge.switches: Any device that matches a switch. Can perform the following actions:

    • turn_on

    • turn_off

  • bridge.thermostats: Any device that matches a thermostat. Can perform the following actions:

    • set_fan_mode

    • set_hvac_mode

    • set_target_temperature

    • set_temperature_range

  • bridge.security_systems: Any device that matches a security-system. Can perform the following actions

    • alarm_trigger

    • arm_away

    • arm_home

    • disarm

  • bridge.security_systems_sensors: Sensors split from security-system. Can perform the following actions

    • Everything is done through set_state

  • bridge.valves: Any device that matches a valves. Can perform the following actions:

    • turn_on

    • turn_off

Example Usage

All examples assume you entered the shell with python -m asyncio

from aioafero import v1
import logging
logging.getLogger("aioafero").setLevel(logging.DEBUG)
USERNAME="" # Afero IOT username
PASSWORD="" # Afero IOT password
POLLING_INTERVAL=30 # Number of seconds between polling cycles
# Create the bridge
bridge = v1.AferoBridgeV1(USERNAME, PASSWORD, polling_interval=POLLING_INTERVAL, hide_secrets=False)
# Query the API and populate the controllers
await bridge.initialize()
# Turn on the light that matches id="84338ebe-7ddf-4bfa-9753-3ee8cdcc8da6"
await conn.lights.turn_off("84338ebe-7ddf-4bfa-9753-3ee8cdcc8da6")

Troubleshooting

  • Device shows incorrect model

    • Afero IoT does not always report all the pertinent information through the API. To resolve this, open a PR to src/aioafero/device.py and update the dataclass AferoDevice.__post_init__ function to correctly identify the device.

  • Afero IoT is slow to update

    • The API rate-limits request. If other things are hitting the API (such as the phone app or Home Assistant), you may need to stop using one to ensure a better connection.

Creating multiple devices from a single device

Sometimes a device can contain multiple devices that should be controlled individually for ease-of-use within other integrations. This can be done by implementing the following functionality:

  • Primary class (class of the non-split device): Fill out class attribute DEVICE_SPLIT_CALLBACKS

  • Model for the split class:

    • Initialization uses model._id instead of model._id. This should be unique and not the main class ID

    • Add the following properties to the model

      • id: Uses model._id

      • update_id: Device ID used during the update. This should match the parent class ID

      • (optional): Additional property to specify the “instance” of the split class

Custom handling of state update

If the device class has special processing for state updates (for example, one state contains multiple datapoints) you can specify a custom callback in the models Put class. This is done through the attribute callback and must specify a callable to handle the update.

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

aioafero-5.0.0.tar.gz (240.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioafero-5.0.0-py3-none-any.whl (71.4 kB view details)

Uploaded Python 3

File details

Details for the file aioafero-5.0.0.tar.gz.

File metadata

  • Download URL: aioafero-5.0.0.tar.gz
  • Upload date:
  • Size: 240.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aioafero-5.0.0.tar.gz
Algorithm Hash digest
SHA256 1e0ecbe1db2bca51b6dbfd427487a7f19c3fb621dd3596ec38c2e7fb7853a5a0
MD5 b42b95ce52457e0207f71cfcd6a7f9b9
BLAKE2b-256 6bd44316cf5e2811d2027f745f1b11e9f0e8512bceea5c9dc599986168672428

See more details on using hashes here.

Provenance

The following attestation bundles were made for aioafero-5.0.0.tar.gz:

Publisher: release.yaml on Expl0dingBanana/aioafero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aioafero-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: aioafero-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 71.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aioafero-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e890607b6d247f7f65a287be5bbd9859a223857b287b4c105cbe4e48cfe61e80
MD5 3bd1e1c89c9009b8dbabf31304abe644
BLAKE2b-256 03755381d42d8c6c9c222e3f2fbf4eeeb728596ba4508e0fccb0c8d8e66c760a

See more details on using hashes here.

Provenance

The following attestation bundles were made for aioafero-5.0.0-py3-none-any.whl:

Publisher: release.yaml on Expl0dingBanana/aioafero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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