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 (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
ATTR_FLASH,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
|
FLASH_LONG,
|
||||||
|
FLASH_SHORT,
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
|
SUPPORT_FLASH,
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
Light,
|
Light,
|
||||||
)
|
)
|
||||||
|
@ -36,11 +40,27 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
class VelbusLight(VelbusEntity, Light):
|
class VelbusLight(VelbusEntity, Light):
|
||||||
"""Representation of a Velbus 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
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
|
if self._module.light_is_buttonled(self._channel):
|
||||||
|
return SUPPORT_FLASH
|
||||||
return SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
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
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if the light is on."""
|
"""Return true if the light is on."""
|
||||||
|
@ -53,25 +73,47 @@ class VelbusLight(VelbusEntity, Light):
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Instruct the Velbus light to turn on."""
|
"""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:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
self._module.set_dimmer_state(
|
attr, *args = (
|
||||||
|
"set_dimmer_state",
|
||||||
self._channel,
|
self._channel,
|
||||||
kwargs[ATTR_BRIGHTNESS],
|
kwargs[ATTR_BRIGHTNESS],
|
||||||
kwargs.get(ATTR_TRANSITION, 0),
|
kwargs.get(ATTR_TRANSITION, 0),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._module.restore_dimmer_state(
|
attr, *args = (
|
||||||
self._channel, kwargs.get(ATTR_TRANSITION, 0),
|
"restore_dimmer_state",
|
||||||
|
self._channel,
|
||||||
|
kwargs.get(ATTR_TRANSITION, 0),
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
getattr(self._module, attr)(*args)
|
||||||
except VelbusException as err:
|
except VelbusException as err:
|
||||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Instruct the velbus light to turn off."""
|
"""Instruct the velbus light to turn off."""
|
||||||
try:
|
if self._module.light_is_buttonled(self._channel):
|
||||||
self._module.set_dimmer_state(
|
attr, *args = "set_led_state", self._channel, "off"
|
||||||
self._channel, 0, kwargs.get(ATTR_TRANSITION, 0),
|
else:
|
||||||
|
attr, *args = (
|
||||||
|
"set_dimmer_state",
|
||||||
|
self._channel,
|
||||||
|
0,
|
||||||
|
kwargs.get(ATTR_TRANSITION, 0),
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
getattr(self._module, attr)(*args)
|
||||||
except VelbusException as err:
|
except VelbusException as err:
|
||||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Velbus",
|
"name": "Velbus",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/velbus",
|
"documentation": "https://www.home-assistant.io/integrations/velbus",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"python-velbus==2.0.32"
|
"python-velbus==2.0.35"
|
||||||
],
|
],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
|
|
|
@ -1635,7 +1635,7 @@ python-telnet-vlc==1.0.4
|
||||||
python-twitch-client==0.6.0
|
python-twitch-client==0.6.0
|
||||||
|
|
||||||
# homeassistant.components.velbus
|
# homeassistant.components.velbus
|
||||||
python-velbus==2.0.32
|
python-velbus==2.0.35
|
||||||
|
|
||||||
# homeassistant.components.vlc
|
# homeassistant.components.vlc
|
||||||
python-vlc==1.1.2
|
python-vlc==1.1.2
|
||||||
|
|
|
@ -534,7 +534,7 @@ python-miio==0.4.8
|
||||||
python-nest==4.1.0
|
python-nest==4.1.0
|
||||||
|
|
||||||
# homeassistant.components.velbus
|
# homeassistant.components.velbus
|
||||||
python-velbus==2.0.32
|
python-velbus==2.0.35
|
||||||
|
|
||||||
# homeassistant.components.awair
|
# homeassistant.components.awair
|
||||||
python_awair==0.0.4
|
python_awair==0.0.4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue