Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions homeassistant/components/hive/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR,
ColorMode,
LightEntity,
Expand Down Expand Up @@ -43,6 +43,9 @@ async def async_setup_entry(
class HiveDeviceLight(HiveEntity, LightEntity):
"""Hive Active Light Device."""

_attr_min_color_temp_kelvin = 2700 # 370 Mireds
_attr_max_color_temp_kelvin = 6500 # 153 Mireds

def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
"""Initialise hive light."""
super().__init__(hive, hive_device)
Expand All @@ -56,9 +59,6 @@ def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
self._attr_color_mode = ColorMode.UNKNOWN

self._attr_min_mireds = 153
self._attr_max_mireds = 370

@refresh_system
async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
Expand All @@ -71,9 +71,8 @@ async def async_turn_on(self, **kwargs: Any) -> None:
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
if new_brightness == 0:
new_brightness = 5
if ATTR_COLOR_TEMP in kwargs:
tmp_new_color_temp = kwargs[ATTR_COLOR_TEMP]
new_color_temp = round(1000000 / tmp_new_color_temp)
if ATTR_COLOR_TEMP_KELVIN in kwargs:
new_color_temp = kwargs[ATTR_COLOR_TEMP_KELVIN]
if ATTR_HS_COLOR in kwargs:
get_new_color = kwargs[ATTR_HS_COLOR]
hue = int(get_new_color[0])
Expand Down Expand Up @@ -102,12 +101,22 @@ async def async_update(self) -> None:
self._attr_is_on = self.device["status"]["state"]
self._attr_brightness = self.device["status"]["brightness"]
if self.device["hiveType"] == "tuneablelight":
self._attr_color_temp = self.device["status"].get("color_temp")
color_temp = self.device["status"].get("color_temp")
self._attr_color_temp_kelvin = (
None
if color_temp is None
else color_util.color_temperature_mired_to_kelvin(color_temp)
)

if self.device["hiveType"] == "colourtuneablelight":
if self.device["status"]["mode"] == "COLOUR":
rgb = self.device["status"]["hs_color"]
self._attr_hs_color = color_util.color_RGB_to_hs(*rgb)
self._attr_color_mode = ColorMode.HS
else:
self._attr_color_temp = self.device["status"].get("color_temp")
self._attr_color_temp_kelvin = (
None
if color_temp is None
else color_util.color_temperature_mired_to_kelvin(color_temp)
)
self._attr_color_mode = ColorMode.COLOR_TEMP