Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LED control of push buttons and bump velbus-library #30445

Merged
merged 6 commits into from Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 49 additions & 7 deletions homeassistant/components/velbus/light.py
Expand Up @@ -5,8 +5,12 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_FLASH,
ATTR_TRANSITION,
FLASH_LONG,
FLASH_SHORT,
SUPPORT_BRIGHTNESS,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
Light,
)
Expand Down Expand Up @@ -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."""
Expand All @@ -53,25 +73,47 @@ def brightness(self):

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)
2 changes: 1 addition & 1 deletion homeassistant/components/velbus/manifest.json
Expand Up @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Expand Up @@ -530,7 +530,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
Expand Down