1 """Support for EverLights lights."""
3 from __future__
import annotations
5 from datetime
import timedelta
10 import voluptuous
as vol
16 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
30 _LOGGER = logging.getLogger(__name__)
34 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
35 {vol.Required(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string])}
40 """Return a RGB color as an integer."""
41 return red * 256 * 256 + green * 256 + blue
45 """Return an RGB tuple from an integer."""
46 return (value >> 16, (value >> 8) & 0xFF, value & 0xFF)
52 async_add_entities: AddEntitiesCallback,
53 discovery_info: DiscoveryInfoType |
None =
None,
55 """Set up the EverLights lights from configuration.yaml."""
58 for ipaddr
in config[CONF_HOSTS]:
62 status = await api.get_status()
64 effects = await api.get_all_patterns()
66 except pyeverlights.ConnectionError
as err:
67 raise PlatformNotReady
from err
69 lights.append(
EverLightsLight(api, pyeverlights.ZONE_1, status, effects))
70 lights.append(
EverLightsLight(api, pyeverlights.ZONE_2, status, effects))
76 """Representation of a Flux light."""
78 _attr_color_mode = ColorMode.HS
79 _attr_supported_color_modes = {ColorMode.HS}
80 _attr_supported_features = LightEntityFeature.EFFECT
84 api: pyeverlights.EverLights,
86 status: dict[str, Any],
89 """Initialize the light."""
94 self.
_mac_mac = status[
"mac"]
99 self.
_attr_name_attr_name = f
"EverLights {self._mac} Zone {self._channel}"
104 """Return true if device is on."""
105 return self.
_status_status[f
"ch{self._channel}Active"] == 1
108 """Turn the light on."""
109 hs_color = kwargs.get(ATTR_HS_COLOR, self.
_attr_hs_color_attr_hs_color)
110 brightness = kwargs.get(ATTR_BRIGHTNESS, self.
_attr_brightness_attr_brightness)
111 effect = kwargs.get(ATTR_EFFECT)
113 if effect
is not None:
114 colors = await self.
_api_api.set_pattern_by_id(self.
_channel_channel, effect)
117 hsv = color_util.color_RGB_to_hsv(*rgb)
119 brightness = hsv[2] / 100 * 255
122 rgb = color_util.color_hsv_to_RGB(
123 hs_color[0], hs_color[1], brightness / 255 * 100
127 await self.
_api_api.set_pattern(self.
_channel_channel, colors)
134 """Turn the light off."""
135 await self.
_api_api.clear_pattern(self.
_channel_channel)
138 """Synchronize state with control box."""
141 except pyeverlights.ConnectionError:
143 _LOGGER.warning(
"EverLights control box connection lost")
147 _LOGGER.warning(
"EverLights control box connection restored")
None async_turn_on(self, **Any kwargs)
None __init__(self, pyeverlights.EverLights api, int channel, dict[str, Any] status, effects)
None async_turn_off(self, **Any kwargs)
tuple[int, int, int] color_int_to_rgb(int value)
int color_rgb_to_int(int red, int green, int blue)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
def get_status(hass, host, port)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)