From 54a29d7226af8fed38866026d844523b8030b9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Balcar?= Date: Mon, 6 Jan 2025 23:42:09 +0100 Subject: [PATCH] update to support color_mode --- custom_components/govee/light.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/custom_components/govee/light.py b/custom_components/govee/light.py index 95231ec..704c9a6 100644 --- a/custom_components/govee/light.py +++ b/custom_components/govee/light.py @@ -3,6 +3,7 @@ from datetime import timedelta, datetime import logging +from homeassistant.util.color import value_to_brightness from propcache import cached_property from govee_api_laggat import Govee, GoveeDevice, GoveeError @@ -156,6 +157,18 @@ def _state(self): """Lights internal state.""" return self._device # self._hub.state(self._device) + @property + def color_mode(self) -> ColorMode: + """Get color mode.""" + current = list(self._device.color) + if self._device.color_temp > 0: + return ColorMode.COLOR_TEMP + if list([0, 0, 0]) != current: + return ColorMode.HS + if self._device.brightness > 0: + return ColorMode.BRIGHTNESS + return ColorMode.ONOFF + @cached_property def supported_color_modes(self) -> set[ColorMode]: """Get supported color modes.""" @@ -290,22 +303,23 @@ def rgb_color(self): def brightness(self): """Return the brightness value.""" # govee is reporting 0 to 254 - home assistant uses 1 to 255 - return self._device.brightness + 1 + scale = (0, 254) + return value_to_brightness(scale,self._device.brightness) @property - def color_temp(self): + def color_temp_kelvin(self): """Return the color_temp of the light.""" return self._device.color_temp @property def min_color_temp_kelvin(self): """Return the coldest color_temp that this light supports.""" - return COLOR_TEMP_KELVIN_MAX + return COLOR_TEMP_KELVIN_MIN @property def max_color_temp_kelvin(self): """Return the warmest color_temp that this light supports.""" - return COLOR_TEMP_KELVIN_MIN + return COLOR_TEMP_KELVIN_MAX @property def extra_state_attributes(self):