1 """Zerproc light platform."""
3 from __future__
import annotations
5 from datetime
import timedelta
25 from .const
import DATA_ADDRESSES, DATA_DISCOVERY_SUBSCRIPTION, DOMAIN
27 _LOGGER = logging.getLogger(__name__)
33 """Attempt to discover new lights."""
34 lights = await pyzerproc.discover()
40 if light.address
not in hass.data[DOMAIN][DATA_ADDRESSES]
44 for light
in new_lights:
45 hass.data[DOMAIN][DATA_ADDRESSES].
add(light.address)
53 config_entry: ConfigEntry,
54 async_add_entities: AddEntitiesCallback,
56 """Set up Zerproc light devices."""
60 """Wrap discovery to include params."""
66 except pyzerproc.ZerprocException:
68 _LOGGER.warning(
"Error discovering Zerproc lights", exc_info=
True)
76 hass, discover, DISCOVERY_INTERVAL
81 """Representation of a Zerproc Light."""
83 _attr_color_mode = ColorMode.HS
84 _attr_supported_color_modes = {ColorMode.HS}
85 _attr_has_entity_name =
True
87 _attr_translation_key =
"light"
90 """Initialize a Zerproc light."""
94 identifiers={(DOMAIN, light.address)},
95 manufacturer=
"Zerproc",
100 """Run when entity about to be added to hass."""
102 self.
hasshass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.
_hass_stop_hass_stop)
106 """Run on EVENT_HOMEASSISTANT_STOP."""
110 """Run when entity will be removed from hass."""
112 await self.
_light_light.disconnect()
113 except pyzerproc.ZerprocException:
115 "Exception disconnecting from %s", self.
_light_light.address, exc_info=
True
119 """Instruct the light to turn on."""
120 if ATTR_BRIGHTNESS
in kwargs
or ATTR_HS_COLOR
in kwargs:
121 default_hs = (0, 0)
if self.
hs_colorhs_color
is None else self.
hs_colorhs_color
122 hue_sat = kwargs.get(ATTR_HS_COLOR, default_hs)
125 brightness = kwargs.get(ATTR_BRIGHTNESS, default_brightness)
127 rgb = color_util.color_hsv_to_RGB(
128 hue_sat[0], hue_sat[1], brightness / 255 * 100
130 await self.
_light_light.set_color(*rgb)
135 """Instruct the light to turn off."""
139 """Fetch new state data for this light."""
142 await self.
_light_light.connect()
144 except pyzerproc.ZerprocException:
146 _LOGGER.warning(
"Unable to connect to %s", self.
_light_light.address)
150 _LOGGER.warning(
"Reconnected to %s", self.
_light_light.address)
153 hsv = color_util.color_RGB_to_hsv(*state.color)
int|None brightness(self)
tuple[float, float]|None hs_color(self)
None async_turn_off(self, **Any kwargs)
None async_added_to_hass(self)
None async_turn_on(self, **Any kwargs)
None async_will_remove_from_hass(self)
None _hass_stop(self, Event event)
None __init__(self, light)
None async_will_remove_from_hass(self)
None async_on_remove(self, CALLBACK_TYPE func)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
bool add(self, _T matcher)
str|float get_state(dict[str, float] data, str key)
list[tuple[str, int]] discover(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[ZerprocLight] discover_entities(HomeAssistant hass)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)