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.
```python
import asyncio
from pprint import pprint
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:
```python
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.
## Asynchronous library to control Philips Hue
Requires Python 3.5 and uses asyncio and aiohttp.
```python
import asyncio
from pprint import pprint
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:
```python
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.3.0.tar.gz
(4.3 kB
view details)
Built Distribution
File details
Details for the file aiohue-1.3.0.tar.gz
.
File metadata
- Download URL: aiohue-1.3.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a372b0a6f5d47770eb9f28bc4d6fb8c68138a303ac38f93ef2c9a085b296d90 |
|
MD5 | c576a809a20ad129b4f846638914d085 |
|
BLAKE2b-256 | 5a173f35b48fe2298ca29efea1ff826d9f0aded0097ed7b997c00050a9f5d0b4 |
File details
Details for the file aiohue-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: aiohue-1.3.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d394082e6c114ac651d4f8bdee311425509577ec07adb2665626d61424264d6d |
|
MD5 | 69295ea4e2cd33777f1fc06ab2608387 |
|
BLAKE2b-256 | 20d5ddd809662f42cf51992e54b28e680097e8ce7830f43f01ede907b47afe44 |