Hubitat Maker API Client
Project description
hubitat_maker_api_client
This library facilitates access to Hubitat's Maker API. A key innovation is the HubitatCachingClient, which is capable of maintaining a cache of all your devices in a data store of your choice. This can allow you to query device state more efficiently than using the Maker API directly. HubitatCachingClient can be attached to a process that listens to Hubitat's /eventsocket
to update the cached device states in real time.
Quick Start
Install
pip install hubitat-maker-api-client
This sample code demonstrates how to configure a HubitatCachingClient using your HOST
, APP_ID
, ACCESS_TOKEN
and HUB_ID
along with your custom implementation of DeviceCache.
from hubitat_maker_api_client import DeviceCache, HubitatAPIClient, HubitatCachingClient
class YourDeviceCache(DeviceCache):
# Override methods for reading and writing
# device state to your own datastore
_api_client = HubitatAPIClient(
host=<HOST>,
app_id=<APP_ID>,
access_token=<ACCESS_TOKEN>,
hub_id=<HUB_ID>,
)
client = HubitatCachingClient(
api_client=_api_client,
device_cache=YourDeviceCache(),
)
for switch in client.get_on_switches():
client.turn_off_switch(switch)
print(f'Turned off {switch}')
This sample code demonstrates how to update device state on your HubitatCachingClient by listening to Hubitat's /eventsocket
.
import asyncio
import websockets
from hubitat_maker_api_client import HubitatEvent
async def listen(uri: str) -> None:
async with websockets.connect(uri) as websocket:
while True:
message = await websocket.recv()
event = HubitatEvent(json.loads(message))
client.update_from_hubitat_event(event)
asyncio.get_event_loop().run_until_complete(listen('ws://<HOST_IP>/eventsocket'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hubitat_maker_api_client-2.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c3ccc408f1cbea15076bba422fc79666c3171f1e42998dd8d4d6765e1595d81 |
|
MD5 | 555b5cd867ec063a5c0a48a818525f7c |
|
BLAKE2b-256 | a95633bfffab21e97873eb12d9fd01f017e4d4a81447f41465c2b8c96c0ab1a9 |
Hashes for hubitat_maker_api_client-2.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e10e53395f16aae3fe7282efb8cd5a78a91d14cc5f174eecfc3bf6ae4e4d9528 |
|
MD5 | ba5f7606918288de5b8a489a6969098b |
|
BLAKE2b-256 | 4e9129eca8da3bfc1362d9d21cd901bb6834a59249d5a04fdccb01a2a258143a |