Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introspect button events #126

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pydeconz/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 59 additions & 0 deletions pydeconz/device.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions pydeconz/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = {}
Expand Down
Empty file added tests/test_devices.py
Empty file.