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: 16 additions & 11 deletions homeassistant/components/blebox/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
Expand All @@ -22,6 +22,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import color as color_util

from . import BleBoxConfigEntry
from .entity import BleBoxEntity
Expand Down Expand Up @@ -58,8 +59,8 @@ async def async_setup_entry(
class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity):
"""Representation of BleBox lights."""

_attr_max_mireds = 370 # 1,000,000 divided by 2700 Kelvin = 370 Mireds
_attr_min_mireds = 154 # 1,000,000 divided by 6500 Kelvin = 154 Mireds
_attr_min_color_temp_kelvin = 2700 # 370 Mireds
_attr_max_color_temp_kelvin = 6500 # 154 Mireds

def __init__(self, feature: blebox_uniapi.light.Light) -> None:
"""Initialize a BleBox light."""
Expand All @@ -78,9 +79,9 @@ def brightness(self):
return self._feature.brightness

@property
def color_temp(self):
"""Return color temperature."""
return self._feature.color_temp
def color_temp_kelvin(self) -> int:
"""Return the color temperature value in Kelvin."""
return color_util.color_temperature_mired_to_kelvin(self._feature.color_temp)

@property
def color_mode(self):
Expand Down Expand Up @@ -136,17 +137,18 @@ async def async_turn_on(self, **kwargs: Any) -> None:
rgbw = kwargs.get(ATTR_RGBW_COLOR)
brightness = kwargs.get(ATTR_BRIGHTNESS)
effect = kwargs.get(ATTR_EFFECT)
color_temp = kwargs.get(ATTR_COLOR_TEMP)
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
rgbww = kwargs.get(ATTR_RGBWW_COLOR)
feature = self._feature
value = feature.sensible_on_value
rgb = kwargs.get(ATTR_RGB_COLOR)

if rgbw is not None:
value = list(rgbw)
if color_temp is not None:
if color_temp_kelvin is not None:
value = feature.return_color_temp_with_brightness(
int(color_temp), self.brightness
int(color_util.color_temperature_kelvin_to_mired(color_temp_kelvin)),
self.brightness,
)

if rgbww is not None:
Expand All @@ -158,9 +160,12 @@ async def async_turn_on(self, **kwargs: Any) -> None:
value = list(rgb)

if brightness is not None:
if self.color_mode == ATTR_COLOR_TEMP:
if self.color_mode == ColorMode.COLOR_TEMP:
value = feature.return_color_temp_with_brightness(
self.color_temp, brightness
color_util.color_temperature_kelvin_to_mired(
self.color_temp_kelvin
),
brightness,
)
else:
value = feature.apply_brightness(value, brightness)
Expand Down