Use pydeconz interface controls for lock, scene, siren and switch platforms (#73748)

This commit is contained in:
Robert Svensson 2022-06-21 16:50:44 +02:00 committed by GitHub
parent cf9cab900e
commit 27209574d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 9 deletions

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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,
)