1 """Platform for UPB link integration."""
11 from .const
import DOMAIN, UPB_BLINK_RATE_SCHEMA, UPB_BRIGHTNESS_RATE_SCHEMA
12 from .entity
import UpbEntity
14 SERVICE_LINK_DEACTIVATE =
"link_deactivate"
15 SERVICE_LINK_FADE_STOP =
"link_fade_stop"
16 SERVICE_LINK_GOTO =
"link_goto"
17 SERVICE_LINK_FADE_START =
"link_fade_start"
18 SERVICE_LINK_BLINK =
"link_blink"
23 config_entry: ConfigEntry,
24 async_add_entities: AddEntitiesCallback,
26 """Set up the UPB link based on a config entry."""
27 upb = hass.data[DOMAIN][config_entry.entry_id][
"upb"]
28 unique_id = config_entry.entry_id
31 platform = entity_platform.async_get_current_platform()
33 platform.async_register_entity_service(
34 SERVICE_LINK_DEACTIVATE,
None,
"async_link_deactivate"
36 platform.async_register_entity_service(
37 SERVICE_LINK_FADE_STOP,
None,
"async_link_fade_stop"
39 platform.async_register_entity_service(
40 SERVICE_LINK_GOTO, UPB_BRIGHTNESS_RATE_SCHEMA,
"async_link_goto"
42 platform.async_register_entity_service(
43 SERVICE_LINK_FADE_START, UPB_BRIGHTNESS_RATE_SCHEMA,
"async_link_fade_start"
45 platform.async_register_entity_service(
46 SERVICE_LINK_BLINK, UPB_BLINK_RATE_SCHEMA,
"async_link_blink"
51 """Representation of a UPB Link."""
54 """Initialize the base of all UPB devices."""
55 super().
__init__(element, unique_id, upb)
59 """Activate the task."""
63 """Activate the task."""
67 """Activate the task."""
68 if brightness
is not None:
69 brightness_pct = round(brightness / 2.55)
70 self.
_element_element.goto(brightness_pct, rate)
73 """Start dimming a link."""
74 if brightness
is not None:
75 brightness_pct = round(brightness / 2.55)
76 self.
_element_element.fade_start(brightness_pct, rate)
79 """Stop dimming a link."""
84 blink_rate =
int(blink_rate * 60)
85 self.
_element_element.blink(blink_rate)
None activate(self, **Any kwargs)
None async_activate(self, **Any kwargs)
def async_link_blink(self, blink_rate)
def __init__(self, element, unique_id, upb)
def async_link_deactivate(self)
def async_link_fade_start(self, rate, brightness=None, brightness_pct=None)
def async_link_fade_stop(self)
def async_link_goto(self, rate, brightness=None, brightness_pct=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)