Improve deCONZ lights supported_color_modes and tests (#51933)

* Improve deconz lights tests

* Simplify attribute definition

* Bump pydeconz to v80
pull/52096/head
Robert Svensson 2021-06-22 19:29:58 +02:00 committed by GitHub
parent 5795e76826
commit 6814e9607a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 827 additions and 330 deletions

View File

@ -2,9 +2,6 @@
from __future__ import annotations
from pydeconz.group import DeconzGroup as Group
from pydeconz.light import Light
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
@ -112,26 +109,21 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
super().__init__(device, gateway)
self._attr_supported_color_modes = set()
self.update_features(self._device)
def update_features(self, device: Light | Group) -> None:
"""Calculate supported features of device."""
supported_color_modes = self._attr_supported_color_modes
if device.ct is not None:
supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
self._attr_supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
if device.hue is not None and device.sat is not None:
supported_color_modes.add(COLOR_MODE_HS)
self._attr_supported_color_modes.add(COLOR_MODE_HS)
if device.xy is not None:
supported_color_modes.add(COLOR_MODE_XY)
self._attr_supported_color_modes.add(COLOR_MODE_XY)
if not supported_color_modes and device.brightness is not None:
supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
if not self._attr_supported_color_modes and device.brightness is not None:
self._attr_supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
if not supported_color_modes:
supported_color_modes.add(COLOR_MODE_ONOFF)
if not self._attr_supported_color_modes:
self._attr_supported_color_modes.add(COLOR_MODE_ONOFF)
if device.brightness is not None:
self._attr_supported_features |= SUPPORT_FLASH
@ -270,29 +262,8 @@ class DeconzGroup(DeconzBaseLight):
def __init__(self, device, gateway):
"""Set up group and create an unique id."""
self._unique_id = f"{gateway.bridgeid}-{device.deconz_id}"
super().__init__(device, gateway)
for light_id in device.lights:
light = gateway.api.lights[light_id]
if light.ZHATYPE == Light.ZHATYPE:
self.update_features(light)
for exclusive_color_mode in [COLOR_MODE_ONOFF, COLOR_MODE_BRIGHTNESS]:
if (
exclusive_color_mode in self._attr_supported_color_modes
and len(self._attr_supported_color_modes) > 1
):
self._attr_supported_color_modes.remove(exclusive_color_mode)
@property
def hs_color(self) -> tuple | None:
"""Return the hs color value."""
try:
return super().hs_color
except TypeError:
return None
@property
def unique_id(self):
"""Return a unique identifier for this device."""

View File

@ -3,7 +3,7 @@
"name": "deCONZ",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/deconz",
"requirements": ["pydeconz==79"],
"requirements": ["pydeconz==80"],
"ssdp": [
{
"manufacturer": "Royal Philips Electronics"

View File

@ -1369,7 +1369,7 @@ pydaikin==2.4.3
pydanfossair==0.1.0
# homeassistant.components.deconz
pydeconz==79
pydeconz==80
# homeassistant.components.delijn
pydelijn==0.6.1

View File

@ -761,7 +761,7 @@ pycoolmasternet-async==0.1.2
pydaikin==2.4.3
# homeassistant.components.deconz
pydeconz==79
pydeconz==80
# homeassistant.components.dexcom
pydexcom==0.2.0

File diff suppressed because it is too large Load Diff