mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Fix Fritzbox light setup (#105232)
This commit is contained in:
parent
b29e9e2df0
commit
a09ccddaa3
@ -38,11 +38,9 @@ async def async_setup_entry(
|
|||||||
FritzboxLight(
|
FritzboxLight(
|
||||||
coordinator,
|
coordinator,
|
||||||
ain,
|
ain,
|
||||||
device.get_colors(),
|
|
||||||
device.get_color_temps(),
|
|
||||||
)
|
)
|
||||||
for ain in coordinator.new_devices
|
for ain in coordinator.new_devices
|
||||||
if (device := coordinator.data.devices[ain]).has_lightbulb
|
if (coordinator.data.devices[ain]).has_lightbulb
|
||||||
)
|
)
|
||||||
|
|
||||||
entry.async_on_unload(coordinator.async_add_listener(_add_entities))
|
entry.async_on_unload(coordinator.async_add_listener(_add_entities))
|
||||||
@ -57,27 +55,10 @@ class FritzboxLight(FritzBoxDeviceEntity, LightEntity):
|
|||||||
self,
|
self,
|
||||||
coordinator: FritzboxDataUpdateCoordinator,
|
coordinator: FritzboxDataUpdateCoordinator,
|
||||||
ain: str,
|
ain: str,
|
||||||
supported_colors: dict,
|
|
||||||
supported_color_temps: list[int],
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the FritzboxLight entity."""
|
"""Initialize the FritzboxLight entity."""
|
||||||
super().__init__(coordinator, ain, None)
|
super().__init__(coordinator, ain, None)
|
||||||
|
|
||||||
if supported_color_temps:
|
|
||||||
# only available for color bulbs
|
|
||||||
self._attr_max_color_temp_kelvin = int(max(supported_color_temps))
|
|
||||||
self._attr_min_color_temp_kelvin = int(min(supported_color_temps))
|
|
||||||
|
|
||||||
# Fritz!DECT 500 only supports 12 values for hue, with 3 saturations each.
|
|
||||||
# Map supported colors to dict {hue: [sat1, sat2, sat3]} for easier lookup
|
|
||||||
self._supported_hs: dict[int, list[int]] = {}
|
self._supported_hs: dict[int, list[int]] = {}
|
||||||
for values in supported_colors.values():
|
|
||||||
hue = int(values[0][0])
|
|
||||||
self._supported_hs[hue] = [
|
|
||||||
int(values[0][1]),
|
|
||||||
int(values[1][1]),
|
|
||||||
int(values[2][1]),
|
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
@ -173,3 +154,28 @@ class FritzboxLight(FritzBoxDeviceEntity, LightEntity):
|
|||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
await self.hass.async_add_executor_job(self.data.set_state_off)
|
await self.hass.async_add_executor_job(self.data.set_state_off)
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Get light attributes from device after entity is added to hass."""
|
||||||
|
await super().async_added_to_hass()
|
||||||
|
supported_colors = await self.hass.async_add_executor_job(
|
||||||
|
self.coordinator.data.devices[self.ain].get_colors
|
||||||
|
)
|
||||||
|
supported_color_temps = await self.hass.async_add_executor_job(
|
||||||
|
self.coordinator.data.devices[self.ain].get_color_temps
|
||||||
|
)
|
||||||
|
|
||||||
|
if supported_color_temps:
|
||||||
|
# only available for color bulbs
|
||||||
|
self._attr_max_color_temp_kelvin = int(max(supported_color_temps))
|
||||||
|
self._attr_min_color_temp_kelvin = int(min(supported_color_temps))
|
||||||
|
|
||||||
|
# Fritz!DECT 500 only supports 12 values for hue, with 3 saturations each.
|
||||||
|
# Map supported colors to dict {hue: [sat1, sat2, sat3]} for easier lookup
|
||||||
|
for values in supported_colors.values():
|
||||||
|
hue = int(values[0][0])
|
||||||
|
self._supported_hs[hue] = [
|
||||||
|
int(values[0][1]),
|
||||||
|
int(values[1][1]),
|
||||||
|
int(values[2][1]),
|
||||||
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user