1 """Platform for UPB light integration."""
18 from .const
import DOMAIN, UPB_BLINK_RATE_SCHEMA, UPB_BRIGHTNESS_RATE_SCHEMA
19 from .entity
import UpbAttachedEntity
21 SERVICE_LIGHT_FADE_START =
"light_fade_start"
22 SERVICE_LIGHT_FADE_STOP =
"light_fade_stop"
23 SERVICE_LIGHT_BLINK =
"light_blink"
28 config_entry: ConfigEntry,
29 async_add_entities: AddEntitiesCallback,
31 """Set up the UPB light based on a config entry."""
33 upb = hass.data[DOMAIN][config_entry.entry_id][
"upb"]
34 unique_id = config_entry.entry_id
36 UpbLight(upb.devices[dev], unique_id, upb)
for dev
in upb.devices
39 platform = entity_platform.async_get_current_platform()
41 platform.async_register_entity_service(
42 SERVICE_LIGHT_FADE_START, UPB_BRIGHTNESS_RATE_SCHEMA,
"async_light_fade_start"
44 platform.async_register_entity_service(
45 SERVICE_LIGHT_FADE_STOP,
None,
"async_light_fade_stop"
47 platform.async_register_entity_service(
48 SERVICE_LIGHT_BLINK, UPB_BLINK_RATE_SCHEMA,
"async_light_blink"
53 """Representation of a UPB Light."""
55 _attr_has_entity_name =
True
59 """Initialize an UpbLight."""
60 super().
__init__(element, unique_id, upb)
65 """Return the color mode of the light."""
67 return ColorMode.BRIGHTNESS
68 return ColorMode.ONOFF
72 """Flag supported color modes."""
77 """Flag supported features."""
79 return LightEntityFeature.TRANSITION | LightEntityFeature.FLASH
80 return LightEntityFeature.FLASH
84 """Get the current brightness."""
88 """Turn on the light."""
89 if flash := kwargs.get(ATTR_FLASH):
92 rate = kwargs.get(ATTR_TRANSITION, -1)
93 brightness = round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)
97 """Turn off the device."""
98 rate = kwargs.get(ATTR_TRANSITION, -1)
102 """Start dimming of device."""
103 if brightness
is not None:
104 brightness_pct = round(brightness / 2.55)
105 self.
_element_element.fade_start(brightness_pct, rate)
108 """Stop dimming of device."""
112 """Request device to blink."""
113 blink_rate =
int(blink_rate * 60)
114 self.
_element_element.blink(blink_rate)
117 """Request the device to update its status."""
118 self.
_element_element.update_status()
121 status = self.
_element_element.status
ColorMode|str|None color_mode(self)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
def async_light_fade_start(self, rate, brightness=None, brightness_pct=None)
ColorMode color_mode(self)
LightEntityFeature supported_features(self)
set[str] supported_color_modes(self)
def __init__(self, element, unique_id, upb)
def async_light_blink(self, blink_rate)
def async_light_fade_stop(self)
def _element_changed(self, element, changeset)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)