Python module to talk to Philips Hue.
Project description
Aiohue
Asynchronous library to control Philips Hue
Requires Python 3.8+ and uses asyncio and aiohttp.
import asyncio
from pprint import pprint
import aiohttp
from aiohue.discovery import discover_nupnp
async def main():
async with aiohttp.ClientSession() as session:
await run(session)
async def run(websession):
bridges = await discover_nupnp(websession)
bridge = bridges[0]
await bridge.create_user('aiophue-example')
print('Your username is', bridge.username)
await bridge.initialize()
print('Name', bridge.config.name)
print('Mac', bridge.config.mac)
print()
print('Lights:')
for id in bridge.lights:
light = bridge.lights[id]
print('{}: {}'.format(light.name, 'on' if light.state['on'] else 'off'))
# Change state of a light.
await light.set_state(on=not light.state['on'])
print()
print('Groups:')
for id in bridge.groups:
group = bridge.groups[id]
print('{}: {}'.format(group.name, 'on' if group.action['on'] else 'off'))
# Change state of a group.
await group.set_action(on=not group.state['on'])
asyncio.run(main())
Timeouts
Aiohue does not specify any timeouts for any requests. You will need to specify them in your own code. We recommend the async_timeout
package:
import async_timeout
with async_timeout.timeout(10):
await bridge.initialize()
Contribution guidelines
Object hierarchy and property/method names should match the Philips Hue API.
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
aiohue-2.4.2.tar.gz
(14.1 kB
view details)
Built Distribution
aiohue-2.4.2-py3-none-any.whl
(16.7 kB
view details)
File details
Details for the file aiohue-2.4.2.tar.gz
.
File metadata
- Download URL: aiohue-2.4.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00a8558a627c38018f93d1cc36b177a9a4037fad600366ff376e73b14648aecf |
|
MD5 | 454a1ba3741448641c9df5e91aabb561 |
|
BLAKE2b-256 | a88cc90be174dd02e2e258d009da91cd7cd33789754abc9139094043185ea351 |
File details
Details for the file aiohue-2.4.2-py3-none-any.whl
.
File metadata
- Download URL: aiohue-2.4.2-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e226fa5ed3faee31a2c3c6fdbd348777ae57f379475bc65602694bd48cf63531 |
|
MD5 | 6cf76f13789cb851c0f3b4989b48f516 |
|
BLAKE2b-256 | 1090e9c2667e20af1e9abffda815451e2ae0bb05cd27e15fbbd3106f7f39f372 |