1 """Support for Velbus light."""
3 from __future__
import annotations
7 from velbusaio.channels
import (
8 Button
as VelbusButton,
9 Channel
as VelbusChannel,
10 Dimmer
as VelbusDimmer,
29 from .const
import DOMAIN
30 from .entity
import VelbusEntity, api_call
36 async_add_entities: AddEntitiesCallback,
38 """Set up Velbus switch based on config_entry."""
39 await hass.data[DOMAIN][entry.entry_id][
"tsk"]
40 cntrl = hass.data[DOMAIN][entry.entry_id][
"cntrl"]
41 entities: list[Entity] = [
42 VelbusLight(channel)
for channel
in cntrl.get_all(
"light")
49 """Representation of a Velbus light."""
51 _channel: VelbusDimmer
52 _attr_color_mode = ColorMode.BRIGHTNESS
53 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
54 _attr_supported_features = LightEntityFeature.TRANSITION
58 """Return true if the light is on."""
63 """Return the brightness of the light."""
64 return int((self.
_channel_channel.get_dimmer_state() * 255) / 100)
68 """Instruct the Velbus light to turn on."""
69 if ATTR_BRIGHTNESS
in kwargs:
71 if kwargs[ATTR_BRIGHTNESS] == 0:
74 brightness =
max(
int((kwargs[ATTR_BRIGHTNESS] * 100) / 255), 1)
78 kwargs.get(ATTR_TRANSITION, 0),
82 "restore_dimmer_state",
83 kwargs.get(ATTR_TRANSITION, 0),
85 await getattr(self.
_channel_channel, attr)(*args)
89 """Instruct the velbus light to turn off."""
93 kwargs.get(ATTR_TRANSITION, 0),
95 await getattr(self.
_channel_channel, attr)(*args)
99 """Representation of a Velbus light."""
101 _channel: VelbusButton
102 _attr_entity_registry_enabled_default =
False
103 _attr_entity_category = EntityCategory.CONFIG
104 _attr_color_mode = ColorMode.ONOFF
105 _attr_supported_color_modes = {ColorMode.ONOFF}
106 _attr_supported_features = LightEntityFeature.FLASH
108 def __init__(self, channel: VelbusChannel) ->
None:
109 """Initialize the button light (led)."""
115 """Return true if the light is on."""
120 """Instruct the Velbus light to turn on."""
121 if ATTR_FLASH
in kwargs:
122 if kwargs[ATTR_FLASH] == FLASH_LONG:
123 attr, *args =
"set_led_state",
"slow"
124 elif kwargs[ATTR_FLASH] == FLASH_SHORT:
125 attr, *args =
"set_led_state",
"fast"
127 attr, *args =
"set_led_state",
"on"
129 attr, *args =
"set_led_state",
"on"
130 await getattr(self.
_channel_channel, attr)(*args)
134 """Instruct the velbus light to turn off."""
135 attr, *args =
"set_led_state",
"off"
136 await getattr(self.
_channel_channel, attr)(*args)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)