Bridge configuration and lifecycle¶
AferoBridgeV1 is the main entry point (from aioafero import v1). Login happens
first via Authentication; the bridge takes username, refresh_token, and session.
Construction¶
Required:
usernamerefresh_token— from login or storagesession—aiohttp.ClientSession
Common options (afero_client, hide_secrets, and client_name also apply to
AferoAuth — Authentication):
token/token_expiration— skip initial refresh if the bearer is still validafero_client—"hubspace"(default)polling_interval— state poll interval in seconds (default30)discovery_interval— discovery poll interval in seconds (default3600)temperature_unit—TemperatureUnit.CELSIUSorFAHRENHEIThide_secrets— redact sensitive log values (defaultTrue)poll_version— fetch firmware version metadata (defaultTrue)client_name— User-Agent token (default"aioafero")
bridge.refresh_token tracks the current refresh token (including rotation).
bridge.set_token_data(token_data) restores or updates tokens.
Lifecycle¶
Log in and get
token_data(Authentication).bridge = v1.AferoBridgeV1(username, token_data.refresh_token, session=session).await bridge.initialize()— start controllers and background polling.await bridge.async_block_until_done()— wait for the first discovery poll.Read and command via controllers.
await bridge.close(). If you passedsession, close it yourself afterward.
Shorthand¶
async with runs initialize on enter and close on exit:
async with v1.AferoBridgeV1(username, refresh_token, session=session) as bridge:
await bridge.async_block_until_done()
await bridge.lights.turn_on(device_id)
await session.close()
open() can create a session when you omit session.
In that case close() closes it:
bridge = await v1.AferoBridgeV1.open(username, refresh_token)
await bridge.async_block_until_done()
await bridge.lights.turn_on(device_id)
await bridge.close()
Events¶
There is no WebSocket from the cloud. EventStream polls the REST API every
polling_interval seconds, merges changes into controller models, and runs your
callbacks in-process:
fetch_all_device_states()runs on the timer.Changes queue on
bridge.events.Controllers update their models.
Callbacks receive
(event_type, item).
item is the typed model (Fan, Light, …) after the merge. Callbacks can be
sync or async def.
bridge.subscribe(callback)— all controllerscontroller.subscribe(callback, id_filter=..., event_filter=...)— one controller or device
See Examples.
Manual API access¶
await bridge.fetch_discovery_data()await bridge.fetch_device_states(device_id)await bridge.fetch_all_device_states()await bridge.send_service_request(device_id, states)— low-level write
Full API: API reference.