Add LED control of push buttons and bump velbus-library (#30445)
* Add LED control * Bump python-velbus library to 2.0.35 To have LED control available in library * Apply black formating * Fix no-else-return pylint error * Changed to f-string and more dry code * Rewrite turn_on for LED control
This commit is contained in:
parent
e642d95d0f
commit
4efbe7135c
4 changed files with 52 additions and 10 deletions
|
@ -5,8 +5,12 @@ from velbus.util import VelbusException
|
|||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_FLASH,
|
||||
ATTR_TRANSITION,
|
||||
FLASH_LONG,
|
||||
FLASH_SHORT,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_FLASH,
|
||||
SUPPORT_TRANSITION,
|
||||
Light,
|
||||
)
|
||||
|
@ -36,11 +40,27 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class VelbusLight(VelbusEntity, Light):
|
||||
"""Representation of a Velbus light."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the display name of this entity."""
|
||||
if self._module.light_is_buttonled(self._channel):
|
||||
return f"LED {self._module.get_name(self._channel)}"
|
||||
return self._module.get_name(self._channel)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
if self._module.light_is_buttonled(self._channel):
|
||||
return SUPPORT_FLASH
|
||||
return SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self):
|
||||
"""Disable Button LEDs by default."""
|
||||
if self._module.light_is_buttonled(self._channel):
|
||||
return False
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the light is on."""
|
||||
|
@ -53,25 +73,47 @@ class VelbusLight(VelbusEntity, Light):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Instruct the Velbus light to turn on."""
|
||||
try:
|
||||
if self._module.light_is_buttonled(self._channel):
|
||||
if ATTR_FLASH in kwargs:
|
||||
if kwargs[ATTR_FLASH] == FLASH_LONG:
|
||||
attr, *args = "set_led_state", self._channel, "slow"
|
||||
elif kwargs[ATTR_FLASH] == FLASH_SHORT:
|
||||
attr, *args = "set_led_state", self._channel, "fast"
|
||||
else:
|
||||
attr, *args = "set_led_state", self._channel, "on"
|
||||
else:
|
||||
attr, *args = "set_led_state", self._channel, "on"
|
||||
else:
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._module.set_dimmer_state(
|
||||
attr, *args = (
|
||||
"set_dimmer_state",
|
||||
self._channel,
|
||||
kwargs[ATTR_BRIGHTNESS],
|
||||
kwargs.get(ATTR_TRANSITION, 0),
|
||||
)
|
||||
else:
|
||||
self._module.restore_dimmer_state(
|
||||
self._channel, kwargs.get(ATTR_TRANSITION, 0),
|
||||
attr, *args = (
|
||||
"restore_dimmer_state",
|
||||
self._channel,
|
||||
kwargs.get(ATTR_TRANSITION, 0),
|
||||
)
|
||||
try:
|
||||
getattr(self._module, attr)(*args)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Instruct the velbus light to turn off."""
|
||||
try:
|
||||
self._module.set_dimmer_state(
|
||||
self._channel, 0, kwargs.get(ATTR_TRANSITION, 0),
|
||||
if self._module.light_is_buttonled(self._channel):
|
||||
attr, *args = "set_led_state", self._channel, "off"
|
||||
else:
|
||||
attr, *args = (
|
||||
"set_dimmer_state",
|
||||
self._channel,
|
||||
0,
|
||||
kwargs.get(ATTR_TRANSITION, 0),
|
||||
)
|
||||
try:
|
||||
getattr(self._module, attr)(*args)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Velbus",
|
||||
"documentation": "https://www.home-assistant.io/integrations/velbus",
|
||||
"requirements": [
|
||||
"python-velbus==2.0.32"
|
||||
"python-velbus==2.0.35"
|
||||
],
|
||||
"config_flow": true,
|
||||
"dependencies": [],
|
||||
|
|
|
@ -1635,7 +1635,7 @@ python-telnet-vlc==1.0.4
|
|||
python-twitch-client==0.6.0
|
||||
|
||||
# homeassistant.components.velbus
|
||||
python-velbus==2.0.32
|
||||
python-velbus==2.0.35
|
||||
|
||||
# homeassistant.components.vlc
|
||||
python-vlc==1.1.2
|
||||
|
|
|
@ -534,7 +534,7 @@ python-miio==0.4.8
|
|||
python-nest==4.1.0
|
||||
|
||||
# homeassistant.components.velbus
|
||||
python-velbus==2.0.32
|
||||
python-velbus==2.0.35
|
||||
|
||||
# homeassistant.components.awair
|
||||
python_awair==0.0.4
|
||||
|
|
Loading…
Add table
Reference in a new issue