1 """Support for Zengge lights."""
3 from __future__
import annotations
8 import voluptuous
as vol
9 from zengge
import zengge
15 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
26 _LOGGER = logging.getLogger(__name__)
28 DEVICE_SCHEMA = vol.Schema({vol.Optional(CONF_NAME): cv.string})
30 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
31 {vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA}}
38 add_entities: AddEntitiesCallback,
39 discovery_info: DiscoveryInfoType |
None =
None,
41 """Set up the Zengge platform."""
43 for address, device_config
in config[CONF_DEVICES].items():
44 light =
ZenggeLight(device_config[CONF_NAME], address)
52 """Representation of a Zengge light."""
54 _attr_supported_color_modes = {ColorMode.HS, ColorMode.WHITE}
56 def __init__(self, name: str, address: str) ->
None:
57 """Initialize the light."""
62 self.
_bulb_bulb = zengge(address)
67 if self.
_bulb_bulb.connect()
is False:
69 _LOGGER.error(
"Failed to connect to bulb %s, %s", address, name)
74 """Return the white property."""
79 """Return the current color mode."""
81 return ColorMode.WHITE
84 def _set_rgb(self, red: int, green: int, blue: int) ->
None:
85 """Set the rgb state."""
86 self.
_bulb_bulb.set_rgb(red, green, blue)
89 """Set the white state."""
90 return self.
_bulb_bulb.set_white(white)
93 """Turn the specified light on."""
97 hs_color = kwargs.get(ATTR_HS_COLOR)
98 white = kwargs.get(ATTR_WHITE)
99 brightness = kwargs.get(ATTR_BRIGHTNESS)
101 if white
is not None:
107 if hs_color
is not None:
112 if brightness
is not None:
115 if self.
_white_white != 0:
118 assert self.
hs_colorhs_color
is not None
120 rgb = color_util.color_hsv_to_RGB(
126 """Turn the specified light off."""
128 self.
_bulb_bulb.off()
131 """Synchronise internal state with the actual light state."""
132 rgb = self.
_bulb_bulb.get_colour()
133 hsv = color_util.color_RGB_to_hsv(*rgb)
int|None brightness(self)
tuple[float, float]|None hs_color(self)
ColorMode color_mode(self)
None _set_rgb(self, int red, int green, int blue)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
def _set_white(self, white)
None __init__(self, str name, str address)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)