1 """Support for Overkiz lights."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pyoverkiz.enums
import OverkizCommand, OverkizCommandParam, OverkizState
20 from .
import HomeAssistantOverkizData
21 from .const
import DOMAIN
22 from .coordinator
import OverkizDataUpdateCoordinator
23 from .entity
import OverkizEntity
29 async_add_entities: AddEntitiesCallback,
31 """Set up the Overkiz lights from a config entry."""
32 data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
36 for device
in data.platforms[Platform.LIGHT]
41 """Representation of an Overkiz Light."""
44 self, device_url: str, coordinator: OverkizDataUpdateCoordinator
46 """Initialize a device."""
47 super().
__init__(device_url, coordinator)
51 if self.
executorexecutor.has_command(OverkizCommand.SET_RGB):
53 elif self.
executorexecutor.has_command(OverkizCommand.SET_INTENSITY):
61 """Return true if light is on."""
63 self.
executorexecutor.select_state(OverkizState.CORE_ON_OFF)
64 == OverkizCommandParam.ON
69 """Return the rgb color value [int, int, int] (0-255)."""
70 red = self.
executorexecutor.select_state(OverkizState.CORE_RED_COLOR_INTENSITY)
71 green = self.
executorexecutor.select_state(OverkizState.CORE_GREEN_COLOR_INTENSITY)
72 blue = self.
executorexecutor.select_state(OverkizState.CORE_BLUE_COLOR_INTENSITY)
74 if red
is None or green
is None or blue
is None:
77 return (cast(int, red), cast(int, green), cast(int, blue))
81 """Return the brightness of this light (0-255)."""
82 value = self.
executorexecutor.select_state(OverkizState.CORE_LIGHT_INTENSITY)
84 return round(cast(int, value) * 255 / 100)
89 """Turn the light on."""
90 rgb_color = kwargs.get(ATTR_RGB_COLOR)
91 brightness = kwargs.get(ATTR_BRIGHTNESS)
93 if rgb_color
is not None:
94 await self.
executorexecutor.async_execute_command(
95 OverkizCommand.SET_RGB,
96 *[round(
float(c))
for c
in kwargs[ATTR_RGB_COLOR]],
100 if brightness
is not None:
101 await self.
executorexecutor.async_execute_command(
102 OverkizCommand.SET_INTENSITY, round(
float(brightness) / 255 * 100)
106 await self.
executorexecutor.async_execute_command(OverkizCommand.ON)
109 """Turn the light off."""
110 await self.
executorexecutor.async_execute_command(OverkizCommand.OFF)
int|None brightness(self)
tuple[int, int, int]|None rgb_color(self)
_attr_supported_color_modes
None __init__(self, str device_url, OverkizDataUpdateCoordinator coordinator)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)