diff --git a/custom_components/tahoma/const.py b/custom_components/tahoma/const.py index 620f65711..7a7d67d55 100644 --- a/custom_components/tahoma/const.py +++ b/custom_components/tahoma/const.py @@ -105,13 +105,18 @@ CORE_OCCUPANCY_STATE = "core:OccupancyState" CORE_SMOKE_STATE = "core:SmokeState" CORE_TEMPERATURE_STATE = "core:TemperatureState" -CORE_LUMINANCE_STATE = "core:LuminanceState" CORE_RELATIVE_HUMIDITY_STATE = "core:RelativeHumidityState" CORE_MEMORIZED_1_POSITION_STATE = "core:Memorized1PositionState" CORE_PEDESTRIAN_POSITION_STATE = "core:PedestrianPositionState" CORE_ELECTRIC_POWER_CONSUMPTION_STATE = "core:ElectricPowerConsumptionState" CORE_CO2_CONCENTRATION_STATE = "core:CO2ConcentrationState" +# Light core states +CORE_LUMINANCE_STATE = "core:LuminanceState" +CORE_RED_COLOR_INTENSITY_STATE = "core:RedColorIntensityState" +CORE_GREEN_COLOR_INTENSITY_STATE = "core:GreenColorIntensityState" +CORE_BLUE_COLOR_INTENSITY_STATE = "core:BlueColorIntensityState" + IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState" IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState" diff --git a/custom_components/tahoma/light.py b/custom_components/tahoma/light.py index bc31a1f92..e37b7e975 100644 --- a/custom_components/tahoma/light.py +++ b/custom_components/tahoma/light.py @@ -5,13 +5,22 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_EFFECT, + ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, + SUPPORT_COLOR, SUPPORT_EFFECT, LightEntity, ) from homeassistant.const import STATE_OFF, STATE_ON - -from .const import DOMAIN, TAHOMA_TYPES +import homeassistant.util.color as color_util + +from .const import ( + CORE_BLUE_COLOR_INTENSITY_STATE, + CORE_GREEN_COLOR_INTENSITY_STATE, + CORE_RED_COLOR_INTENSITY_STATE, + DOMAIN, + TAHOMA_TYPES, +) from .tahoma_device import TahomaDevice _LOGGER = logging.getLogger(__name__) @@ -41,10 +50,10 @@ def __init__(self, tahoma_device, controller): """Initialize a device.""" super().__init__(tahoma_device, controller) - self._skip_update = False self._effect = None self._brightness = None self._state = None + self._hs_color = [] @property def brightness(self) -> int: @@ -56,6 +65,13 @@ def is_on(self) -> bool: """Return true if light is on.""" return self._state + @property + def hs_color(self): + """Return the hue and saturation color value [float, float].""" + if self._hs_color: + return self._hs_color + return None + @property def supported_features(self) -> int: """Flag supported features.""" @@ -68,13 +84,23 @@ def supported_features(self) -> int: if "wink" in self.tahoma_device.command_definitions: supported_features |= SUPPORT_EFFECT + if "setRGB" in self.tahoma_device.command_definitions: + supported_features |= SUPPORT_COLOR + return supported_features def turn_on(self, **kwargs) -> None: """Turn the light on.""" self._state = True - self._skip_update = True + if ATTR_HS_COLOR in kwargs: + self.apply_action( + "setRGB", + *[ + int(float(c)) + for c in color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) + ], + ) if ATTR_BRIGHTNESS in kwargs: self._brightness = int(float(kwargs[ATTR_BRIGHTNESS]) / 255 * 100) self.apply_action("setIntensity", self._brightness) @@ -89,7 +115,6 @@ def turn_on(self, **kwargs) -> None: def turn_off(self, **kwargs) -> None: """Turn the light off.""" self._state = False - self._skip_update = True self.apply_action("off") self.async_write_ha_state() @@ -109,10 +134,6 @@ def update(self): This is the only method that should fetch new data for Home Assistant. """ - # Postpone the immediate state check for changes that take time. - if self._skip_update: - self._skip_update = False - return self.controller.get_states([self.tahoma_device]) @@ -125,3 +146,18 @@ def update(self): self._state = True else: self._state = False + + if CORE_RED_COLOR_INTENSITY_STATE in self.tahoma_device.active_states: + self._hs_color = color_util.color_RGB_to_hs( + [ + self.tahoma_device.active_states.get( + CORE_RED_COLOR_INTENSITY_STATE + ), + self.tahoma_device.active_states.get( + CORE_GREEN_COLOR_INTENSITY_STATE + ), + self.tahoma_device.active_states.get( + CORE_BLUE_COLOR_INTENSITY_STATE + ), + ] + )