diff --git a/pydeconz/__main__.py b/pydeconz/__main__.py index 091e2fd1..106cee13 100644 --- a/pydeconz/__main__.py +++ b/pydeconz/__main__.py @@ -67,6 +67,17 @@ async def main(host: str, port: int, api_key: str) -> None: await gateway.refresh_state() gateway.start() + ##### + from pprint import pprint + + model_unique_ids = { + sensor.modelid: sensor.uniqueid + for sensor in gateway.sensors.values() + if sensor.type == "ZHASwitch" + } + button_events = await gateway.devices.introspect_button_event(model_unique_ids) + pprint(button_events) + ##### try: while True: await asyncio.sleep(1) diff --git a/pydeconz/device.py b/pydeconz/device.py new file mode 100644 index 00000000..8bb1a343 --- /dev/null +++ b/pydeconz/device.py @@ -0,0 +1,59 @@ +"""Expose device and introspection capabilities from deCONZ.""" + +import logging +from typing import Callable, Dict, Optional, Tuple, Union + +from .api import APIItem, APIItems + +# from .deconzdevice import DeconzDevice + +LOGGER = logging.getLogger(__name__) +# RESOURCE_TYPE = "devices" +URL = "/devices" + +BUTTON_ACTION_INITIAL_PRESS = "INITIAL_PRESS" +BUTTON_ACTION_SHORT_RELEASE = "SHORT_RELEASE" +BUTTON_ACTION_DOUBLE_PRESS = "DOUBLE_PRESS" +BUTTON_ACTION_TREBLE_PRESS = "TREBLE_PRESS" +BUTTON_ACTION_HOLD = "HOLD" +BUTTON_ACTION_LONG_RELEASE = "LONG_RELEASE" + +BUTTON_NAME_BUTTON_1 = "Button 1" +BUTTON_NAME_CLOSE = "Close" +BUTTON_NAME_DIM_DOWN = "Dim Down" +BUTTON_NAME_DIM_UP = "Dim Up" +BUTTON_NAME_NEXT = "Next Scene" +BUTTON_NAME_OFF = "Off" +BUTTON_NAME_ON = "On" +BUTTON_NAME_ONOFF = "On/OFF" +BUTTON_NAME_OPEN = "Open" +BUTTON_NAME_PREVIOUS = "Previous Scene" +BUTTON_NAME_ROTATE_CLOCKWISE = "Rotate clockwise" +BUTTON_NAME_ROTATE_COUNTER_CLOCKWISE = "Rotate counter clockwise" + + +class Device(APIItem): + pass + + +class Devices(APIItems): + """Represent deCONZ devices.""" + + def __init__( + self, + raw: dict, + request: Callable[..., Optional[dict]], + ) -> None: + """Initialize device manager.""" + super().__init__(raw, request, URL, Device) + + async def introspect_button_event(self, model_unique_ids: Dict[str, str]) -> dict: + """Introspect button event for unique ID.""" + button_events = {} + + for model_id, unique_id in model_unique_ids.items(): + path = f"/{URL}/{unique_id}/state/buttonevent/introspect" + raw = await self._request("get", path) + button_events[model_id] = raw + + return button_events diff --git a/pydeconz/gateway.py b/pydeconz/gateway.py index ffd1a4a8..1b59bfc3 100644 --- a/pydeconz/gateway.py +++ b/pydeconz/gateway.py @@ -11,6 +11,7 @@ from .alarm_system import RESOURCE_TYPE as ALARM_SYSTEM_RESOURCE, AlarmSystems from .config import RESOURCE_TYPE as CONFIG_RESOURCE, Config +from .device import Devices from .errors import RequestError, ResponseError, raise_error from .group import RESOURCE_TYPE as GROUP_RESOURCE, DeconzScene, Groups from .light import RESOURCE_TYPE as LIGHT_RESOURCE, Light, Lights @@ -67,6 +68,7 @@ def __init__( self.alarmsystems = AlarmSystems({}, self.request) self.config: Config | None = None + self.devices = Devices({}, self.request) self.groups = Groups({}, self.request) self.lights = Lights({}, self.request) self.scenes: dict[str, DeconzScene] = {} diff --git a/tests/test_devices.py b/tests/test_devices.py new file mode 100644 index 00000000..e69de29b