Skip to content

Commit

Permalink
update to support color_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiří Balcar committed Jan 6, 2025
1 parent 2e9e5f0 commit 54a29d7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions custom_components/govee/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 54a29d7

Please sign in to comment.