Python module to talk to Philips Hue.
Project description
Aiohue
Asynchronous library to control Philips Hue
Requires Python 3.5 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.get_event_loop().run_until_complete(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-1.10.0.tar.gz
(7.7 kB
view details)
File details
Details for the file aiohue-1.10.0.tar.gz
.
File metadata
- Download URL: aiohue-1.10.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45986da1dc8635af62f02d322d2bf2abdae3848e22f5646b2942a13ce9a739d1 |
|
MD5 | bb17176bdda8bc3052ea39e621106fb8 |
|
BLAKE2b-256 | 618d382a8eb93014501c6318c66a5e40d4dd2376cbf27cf5f73446b51a57b02e |