Skip to content

Commit

Permalink
Merge pull request #200 from JiriBalcar/master
Browse files Browse the repository at this point in the history
fix issue with HA 2025.1
  • Loading branch information
LaggAt authored Jan 6, 2025
2 parents 52d3bc0 + 38cb4fa commit b860ded
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
4 changes: 1 addition & 3 deletions custom_components/govee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
raise PlatformNotReady()

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
await hass.config_entries.async_forward_entry_setup(entry, component)

return True

Expand Down
1 change: 0 additions & 1 deletion custom_components/govee/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class GoveeOptionsFlowHandler(config_entries.OptionsFlow):

def __init__(self, config_entry):
"""Initialize options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options)

async def async_step_init(self, user_input=None):
Expand Down
58 changes: 29 additions & 29 deletions custom_components/govee/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from datetime import timedelta, datetime
import logging

from propcache import cached_property

from govee_api_laggat import Govee, GoveeDevice, GoveeError
from govee_api_laggat.govee_dtos import GoveeSource

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
ColorMode,
LightEntity,
)
from homeassistant.const import CONF_DELAY
Expand Down Expand Up @@ -156,17 +156,21 @@ def _state(self):
"""Lights internal state."""
return self._device # self._hub.state(self._device)

@property
def supported_features(self):
"""Flag supported features."""
support_flags = 0
if self._device.support_brightness:
support_flags |= SUPPORT_BRIGHTNESS
@cached_property
def supported_color_modes(self) -> set[ColorMode]:
"""Get supported color modes."""
color_mode = set()
if self._device.support_color:
support_flags |= SUPPORT_COLOR
color_mode.add(ColorMode.HS)
if self._device.support_color_tem:
support_flags |= SUPPORT_COLOR_TEMP
return support_flags
color_mode.add(ColorMode.COLOR_TEMP)
if not color_mode:
# brightness or on/off must be the only supported mode
if self._device.support_brightness:
color_mode.add(ColorMode.BRIGHTNESS)
else:
color_mode.add(ColorMode.ONOFF)
return color_mode

async def async_turn_on(self, **kwargs):
"""Turn device on."""
Expand All @@ -186,15 +190,14 @@ async def async_turn_on(self, **kwargs):
just_turn_on = False
bright_set = brightness - 1
_, err = await self._hub.set_brightness(self._device, bright_set)
if ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs.pop(ATTR_COLOR_TEMP)
if ATTR_COLOR_TEMP_KELVIN in kwargs:
color_temp = kwargs.pop(ATTR_COLOR_TEMP_KELVIN)
just_turn_on = False
color_temp_kelvin = color.color_temperature_mired_to_kelvin(color_temp)
if color_temp_kelvin > COLOR_TEMP_KELVIN_MAX:
color_temp_kelvin = COLOR_TEMP_KELVIN_MAX
elif color_temp_kelvin < COLOR_TEMP_KELVIN_MIN:
color_temp_kelvin = COLOR_TEMP_KELVIN_MIN
_, err = await self._hub.set_color_temp(self._device, color_temp_kelvin)
if color_temp > COLOR_TEMP_KELVIN_MAX:
color_temp = COLOR_TEMP_KELVIN_MAX
elif color_temp < COLOR_TEMP_KELVIN_MIN:
color_temp = COLOR_TEMP_KELVIN_MIN
_, err = await self._hub.set_color_temp(self._device, color_temp)

# if there is no known specific command - turn on
if just_turn_on:
Expand Down Expand Up @@ -241,7 +244,6 @@ def device_info(self):
"name": self.name,
"manufacturer": "Govee",
"model": self._device.model,
"via_device": (DOMAIN, "Govee API (cloud)"),
}

@property
Expand Down Expand Up @@ -293,19 +295,17 @@ def brightness(self):
@property
def color_temp(self):
"""Return the color_temp of the light."""
if not self._device.color_temp:
return None
return color.color_temperature_kelvin_to_mired(self._device.color_temp)
return self._device.color_temp

@property
def min_mireds(self):
def min_color_temp_kelvin(self):
"""Return the coldest color_temp that this light supports."""
return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MAX)
return COLOR_TEMP_KELVIN_MAX

@property
def max_mireds(self):
def max_color_temp_kelvin(self):
"""Return the warmest color_temp that this light supports."""
return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MIN)
return COLOR_TEMP_KELVIN_MIN

@property
def extra_state_attributes(self):
Expand Down

0 comments on commit b860ded

Please sign in to comment.