Async Python client for the Homecast REST API.
pip install pyhomecastimport aiohttp
from pyhomecast import HomecastClient
async with aiohttp.ClientSession() as session:
client = HomecastClient(session)
client.authenticate("your_access_token")
# Get all device state
state = await client.get_state()
for device in state.devices.values():
print(f"{device.name} ({device.device_type}): {device.state}")
# Control a device
await client.set_state({
"my_home_0bf8": {
"living_room_a1b2": {
"ceiling_light_c3d4": {"on": True, "brightness": 80}
}
}
})
# Run a scene
await client.run_scene("my_home_0bf8", "Good Morning")authenticate(token)- Set the Bearer tokenget_state(home?, room?, device_type?, name?)- Fetch device state (returnsHomecastState)set_state(updates)- Control devicesrun_scene(home, name)- Execute a scene
HomecastState- ContainsdevicesandhomesdictsHomecastDevice- Single device withstate,settable,device_typeHomecastHome- Home withkeyandname
HomecastError- Base exceptionHomecastAuthError- 401/403 errorsHomecastConnectionError- Network/server errors
MIT