From 27209574d256d3205cc2bbb63c41d0cb4b116a85 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 21 Jun 2022 16:50:44 +0200 Subject: [PATCH] Use pydeconz interface controls for lock, scene, siren and switch platforms (#73748) --- homeassistant/components/deconz/lock.py | 22 ++++++++++++++++++++-- homeassistant/components/deconz/scene.py | 5 ++++- homeassistant/components/deconz/siren.py | 14 ++++++++++---- homeassistant/components/deconz/switch.py | 10 ++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/deconz/lock.py b/homeassistant/components/deconz/lock.py index 78ccae30441..cf4bd7f14f5 100644 --- a/homeassistant/components/deconz/lock.py +++ b/homeassistant/components/deconz/lock.py @@ -62,8 +62,26 @@ class DeconzLock(DeconzDevice, LockEntity): async def async_lock(self, **kwargs: Any) -> None: """Lock the lock.""" - await self._device.lock() + if isinstance(self._device, DoorLock): + await self.gateway.api.sensors.door_lock.set_config( + id=self._device.resource_id, + lock=True, + ) + else: + await self.gateway.api.lights.locks.set_state( + id=self._device.resource_id, + lock=True, + ) async def async_unlock(self, **kwargs: Any) -> None: """Unlock the lock.""" - await self._device.unlock() + if isinstance(self._device, DoorLock): + await self.gateway.api.sensors.door_lock.set_config( + id=self._device.resource_id, + lock=False, + ) + else: + await self.gateway.api.lights.locks.set_state( + id=self._device.resource_id, + lock=False, + ) diff --git a/homeassistant/components/deconz/scene.py b/homeassistant/components/deconz/scene.py index dfbb6ae828b..236389cc100 100644 --- a/homeassistant/components/deconz/scene.py +++ b/homeassistant/components/deconz/scene.py @@ -43,4 +43,7 @@ class DeconzScene(DeconzSceneMixin, Scene): async def async_activate(self, **kwargs: Any) -> None: """Activate the scene.""" - await self._device.recall() + await self.gateway.api.scenes.recall( + self._device.group_id, + self._device.id, + ) diff --git a/homeassistant/components/deconz/siren.py b/homeassistant/components/deconz/siren.py index 8427b6ce75d..d44bce01aad 100644 --- a/homeassistant/components/deconz/siren.py +++ b/homeassistant/components/deconz/siren.py @@ -59,11 +59,17 @@ class DeconzSiren(DeconzDevice, SirenEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Turn on siren.""" - data = {} if (duration := kwargs.get(ATTR_DURATION)) is not None: - data["duration"] = duration * 10 - await self._device.turn_on(**data) + duration *= 10 + await self.gateway.api.lights.sirens.set_state( + id=self._device.resource_id, + on=True, + duration=duration, + ) async def async_turn_off(self, **kwargs: Any) -> None: """Turn off siren.""" - await self._device.turn_off() + await self.gateway.api.lights.sirens.set_state( + id=self._device.resource_id, + on=False, + ) diff --git a/homeassistant/components/deconz/switch.py b/homeassistant/components/deconz/switch.py index d54ff1f36ba..b21ec929909 100644 --- a/homeassistant/components/deconz/switch.py +++ b/homeassistant/components/deconz/switch.py @@ -56,8 +56,14 @@ class DeconzPowerPlug(DeconzDevice, SwitchEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Turn on switch.""" - await self._device.set_state(on=True) + await self.gateway.api.lights.lights.set_state( + id=self._device.resource_id, + on=True, + ) async def async_turn_off(self, **kwargs: Any) -> None: """Turn off switch.""" - await self._device.set_state(on=False) + await self.gateway.api.lights.lights.set_state( + id=self._device.resource_id, + on=False, + )