1 """BleBox light entities implementation."""
3 from __future__
import annotations
5 from datetime
import timedelta
26 from .
import BleBoxConfigEntry
27 from .entity
import BleBoxEntity
29 _LOGGER = logging.getLogger(__name__)
36 config_entry: BleBoxConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up a BleBox entry."""
42 for feature
in config_entry.runtime_data.features.get(
"lights", [])
48 BleboxColorMode.RGBW: ColorMode.RGBW,
49 BleboxColorMode.RGB: ColorMode.RGB,
50 BleboxColorMode.MONO: ColorMode.BRIGHTNESS,
51 BleboxColorMode.RGBorW: ColorMode.RGBW,
52 BleboxColorMode.CT: ColorMode.COLOR_TEMP,
53 BleboxColorMode.CTx2: ColorMode.COLOR_TEMP,
54 BleboxColorMode.RGBWW: ColorMode.RGBWW,
59 """Representation of BleBox lights."""
61 _attr_max_mireds = 370
62 _attr_min_mireds = 154
64 def __init__(self, feature: blebox_uniapi.light.Light) ->
None:
65 """Initialize a BleBox light."""
67 if feature.effect_list:
72 """Return if light is on."""
73 return self._feature.is_on
77 """Return the name."""
78 return self._feature.brightness
82 """Return color temperature."""
83 return self._feature.color_temp
87 """Return the color mode.
89 Set values to _attr_ibutes if needed.
91 return COLOR_MODE_MAP.get(self._feature.color_mode, ColorMode.ONOFF)
95 """Return supported color modes."""
100 """Return the list of supported effects."""
101 return self._feature.effect_list
105 """Return the current effect."""
106 return self._feature.effect
110 """Return value for rgb."""
111 if (rgb_hex := self._feature.rgb_hex)
is None:
114 blebox_uniapi.light.Light.normalise_elements_of_rgb(
115 blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgb_hex)[0:3]
121 """Return the hue and saturation."""
122 if (rgbw_hex := self._feature.rgbw_hex)
is None:
124 return tuple(blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgbw_hex)[0:4])
128 """Return value for rgbww."""
129 if (rgbww_hex := self._feature.rgbww_hex)
is None:
131 return tuple(blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgbww_hex))
134 """Turn the light on."""
136 rgbw = kwargs.get(ATTR_RGBW_COLOR)
137 brightness = kwargs.get(ATTR_BRIGHTNESS)
138 effect = kwargs.get(ATTR_EFFECT)
139 color_temp = kwargs.get(ATTR_COLOR_TEMP)
140 rgbww = kwargs.get(ATTR_RGBWW_COLOR)
141 feature = self._feature
142 value = feature.sensible_on_value
143 rgb = kwargs.get(ATTR_RGB_COLOR)
147 if color_temp
is not None:
148 value = feature.return_color_temp_with_brightness(
152 if rgbww
is not None:
160 if brightness
is not None:
162 value = feature.return_color_temp_with_brightness(
166 value = feature.apply_brightness(value, brightness)
169 await self._feature.async_on(value)
170 except ValueError
as exc:
172 f
"Turning on '{self.name}' failed: Bad value {value}"
175 if effect
is not None:
178 await self._feature.async_api_command(
"effect", effect_value)
179 except ValueError
as exc:
181 f
"Turning on with effect '{self.name}' failed: {effect} not in"
186 """Turn the light off."""
187 await self._feature.async_off()
None __init__(self, blebox_uniapi.light.Light feature)
None async_turn_off(self, **Any kwargs)
def supported_color_modes(self)
list[str] effect_list(self)
None async_turn_on(self, **Any kwargs)
list[str]|None effect_list(self)
int|None brightness(self)
int|None color_temp(self)
ColorMode|str|None color_mode(self)
None async_setup_entry(HomeAssistant hass, BleBoxConfigEntry config_entry, AddEntitiesCallback async_add_entities)