Skip to content

Commit

Permalink
Working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Sep 18, 2021
1 parent 8ba332c commit 5092b62
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pydeconz/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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
38 changes: 38 additions & 0 deletions pydeconz/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""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"


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 @@ -8,6 +8,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 @@ -64,6 +65,7 @@ def __init__(

self.alarmsystems = AlarmSystems({}, self.request)
self.config: Optional[Config] = None
self.devices = Devices({}, self.request)
self.groups = Groups({}, self.request)
self.lights = Lights({}, self.request)
self.scenes: Dict[str, DeconzScene] = {}
Expand Down

0 comments on commit 5092b62

Please sign in to comment.