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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74b2f6d7c740f9d59a090cf347d479d86cce22a524df9c26446a0a72fa38d63e |
|
MD5 | d5ec6caa074b3191867e9e0767f8185f |
|
BLAKE2b-256 | 65869f570ad1f4636d9d8eeee9f724cffc0a0b9cbaaa4896640019916c18e34e |
Hashes for hubitat_maker_api_client-2.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd1c202b2e916da1837ff6930121dea2b674e1f1284c4d66414e6bdef6f7af15 |
|
MD5 | eda8f97577881e2fa6a238c76c6d09ce |
|
BLAKE2b-256 | 219394254355d37449f51236d08d78bf29dfed6adeaf99766bb5891fdf1e4085 |