|
| 1 | +# Device control |
| 2 | + |
| 3 | +## List devices |
| 4 | + |
| 5 | +```python |
| 6 | +import asyncio |
| 7 | + |
| 8 | +from pyoverkiz.auth.credentials import UsernamePasswordCredentials |
| 9 | +from pyoverkiz.client import OverkizClient |
| 10 | +from pyoverkiz.enums import Server |
| 11 | + |
| 12 | + |
| 13 | +async def main() -> None: |
| 14 | + async with OverkizClient( |
| 15 | + server=Server.SOMFY_EUROPE, |
| 16 | + credentials=UsernamePasswordCredentials( "[email protected]", "password"), |
| 17 | + ) as client: |
| 18 | + await client.login() |
| 19 | + devices = await client.get_devices() |
| 20 | + for device in devices: |
| 21 | + print(device.label, device.controllable_name) |
| 22 | + |
| 23 | + |
| 24 | +asyncio.run(main()) |
| 25 | +``` |
| 26 | + |
| 27 | +## Read a state value |
| 28 | + |
| 29 | +```python |
| 30 | +import asyncio |
| 31 | + |
| 32 | +from pyoverkiz.auth.credentials import UsernamePasswordCredentials |
| 33 | +from pyoverkiz.client import OverkizClient |
| 34 | +from pyoverkiz.enums import Server |
| 35 | + |
| 36 | + |
| 37 | +async def main() -> None: |
| 38 | + async with OverkizClient( |
| 39 | + server=Server.SOMFY_EUROPE, |
| 40 | + credentials=UsernamePasswordCredentials( "[email protected]", "password"), |
| 41 | + ) as client: |
| 42 | + await client.login() |
| 43 | + devices = await client.get_devices() |
| 44 | + device = devices[0] |
| 45 | + closure_state = next( |
| 46 | + (state for state in device.states if state.name == "core:ClosureState"), |
| 47 | + None, |
| 48 | + ) |
| 49 | + print(closure_state.value if closure_state else None) |
| 50 | + |
| 51 | + |
| 52 | +asyncio.run(main()) |
| 53 | +``` |
| 54 | + |
| 55 | +## Send a command |
| 56 | + |
| 57 | +```python |
| 58 | +import asyncio |
| 59 | + |
| 60 | +from pyoverkiz.auth.credentials import UsernamePasswordCredentials |
| 61 | +from pyoverkiz.client import OverkizClient |
| 62 | +from pyoverkiz.enums import OverkizCommand, Server |
| 63 | +from pyoverkiz.models import Action, Command |
| 64 | + |
| 65 | + |
| 66 | +async def main() -> None: |
| 67 | + async with OverkizClient( |
| 68 | + server=Server.SOMFY_EUROPE, |
| 69 | + credentials=UsernamePasswordCredentials( "[email protected]", "password"), |
| 70 | + ) as client: |
| 71 | + await client.login() |
| 72 | + await client.execute_action_group( |
| 73 | + actions=[ |
| 74 | + Action( |
| 75 | + device_url="io://1234-5678-1234/12345678", |
| 76 | + commands=[ |
| 77 | + Command( |
| 78 | + name=OverkizCommand.SET_CLOSURE, |
| 79 | + parameters=[50], |
| 80 | + ) |
| 81 | + ], |
| 82 | + ) |
| 83 | + ], |
| 84 | + label="Set closure", |
| 85 | + ) |
| 86 | + |
| 87 | + |
| 88 | +asyncio.run(main()) |
| 89 | +``` |
| 90 | + |
| 91 | +## Action groups and common patterns |
| 92 | + |
| 93 | +- Use a single action group to batch multiple device commands. |
| 94 | +- Parameters vary by device. Many closure-style devices use 0–100. |
| 95 | +- Thermostat-style devices commonly accept target temperatures. |
| 96 | + |
| 97 | +```python |
| 98 | +import asyncio |
| 99 | + |
| 100 | +from pyoverkiz.auth.credentials import UsernamePasswordCredentials |
| 101 | +from pyoverkiz.client import OverkizClient |
| 102 | +from pyoverkiz.enums import OverkizCommand, Server |
| 103 | +from pyoverkiz.models import Action, Command |
| 104 | + |
| 105 | + |
| 106 | +async def main() -> None: |
| 107 | + async with OverkizClient( |
| 108 | + server=Server.SOMFY_EUROPE, |
| 109 | + credentials=UsernamePasswordCredentials( "[email protected]", "password"), |
| 110 | + ) as client: |
| 111 | + await client.login() |
| 112 | + await client.execute_action_group( |
| 113 | + actions=[ |
| 114 | + Action( |
| 115 | + device_url="io://1234-5678-1234/12345678", |
| 116 | + commands=[ |
| 117 | + Command( |
| 118 | + name=OverkizCommand.SET_TARGET_TEMPERATURE, |
| 119 | + parameters=[21.5], |
| 120 | + ) |
| 121 | + ], |
| 122 | + ) |
| 123 | + ], |
| 124 | + label="Set temperature", |
| 125 | + ) |
| 126 | + |
| 127 | + |
| 128 | +asyncio.run(main()) |
| 129 | +``` |
| 130 | + |
| 131 | +## Polling vs event-driven |
| 132 | + |
| 133 | +Polling `get_devices()` is simple but can be slower. Event listeners provide faster updates; see the event handling guide for details. |
0 commit comments