1 """Support for Fibaro lights."""
3 from __future__
import annotations
5 from contextlib
import suppress
8 from pyfibaro.fibaro_device
import DeviceModel
25 from .
import FibaroController
26 from .const
import DOMAIN
27 from .entity
import FibaroEntity
33 """Scale the input value from 0-100 to 0-255."""
40 return round(value * 2.55)
44 """Scale the input value from 0-255 to 0-99."""
50 return min(round(value / 2.55), 99)
56 async_add_entities: AddEntitiesCallback,
58 """Perform the setup for Fibaro controller devices."""
59 controller: FibaroController = hass.data[DOMAIN][entry.entry_id]
61 [
FibaroLight(device)
for device
in controller.fibaro_devices[Platform.LIGHT]],
67 """Representation of a Fibaro Light, including dimmable."""
69 def __init__(self, fibaro_device: DeviceModel) ->
None:
70 """Initialize the light."""
72 "color" in fibaro_device.properties
73 or "colorComponents" in fibaro_device.properties
74 or "RGB" in fibaro_device.type
75 or "rgb" in fibaro_device.type
76 or "color" in fibaro_device.base_type
78 "setColor" in fibaro_device.actions
79 or "setColorComponents" in fibaro_device.actions
82 "setW" in fibaro_device.actions
83 or "RGBW" in fibaro_device.type
84 or "rgbw" in fibaro_device.type
87 fibaro_device.has_interface(
"levelChange")
88 and "setValue" in fibaro_device.actions
91 if supports_color
and supports_white_v:
97 elif supports_dimming:
108 """Turn the light on."""
109 if ATTR_BRIGHTNESS
in kwargs:
114 if ATTR_RGB_COLOR
in kwargs:
116 rgb = kwargs[ATTR_RGB_COLOR]
121 if ATTR_RGBW_COLOR
in kwargs:
123 rgbw = kwargs[ATTR_RGBW_COLOR]
132 """Turn the light off."""
136 """Update the state."""
143 with suppress(TypeError):
146 with suppress(TypeError):
149 with suppress(TypeError):
165 if rgbw == (0, 0, 0, 0)
and self.
fibaro_devicefibaro_device.last_color_set.has_color:
166 rgbw = self.
fibaro_devicefibaro_device.last_color_set.rgbw_color
bool current_binary_state(self)
None call_set_color(self, int red, int green, int blue, int white)
None set_level(self, int level)
None __init__(self, DeviceModel fibaro_device)
None turn_off(self, **Any kwargs)
_attr_supported_color_modes
None turn_on(self, **Any kwargs)
set[ColorMode]|set[str]|None supported_color_modes(self)
ColorMode|str|None color_mode(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
int scaleto99(int|None value)
int scaleto255(int|None value)
bool color_supported(Iterable[ColorMode|str]|None color_modes)
bool brightness_supported(Iterable[ColorMode|str]|None color_modes)