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
Support for zwave light transitions #6868
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
# pylint: disable=import-error | ||
from threading import Timer | ||
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, \ | ||
ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, \ | ||
SUPPORT_RGB_COLOR, DOMAIN, Light | ||
ATTR_RGB_COLOR, ATTR_TRANSITION, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, \ | ||
SUPPORT_RGB_COLOR, SUPPORT_TRANSITION, DOMAIN, Light | ||
from homeassistant.components import zwave | ||
from homeassistant.components.zwave import async_setup_platform # noqa # pylint: disable=unused-import | ||
from homeassistant.const import STATE_OFF, STATE_ON | ||
|
@@ -43,11 +43,6 @@ | |
TEMP_WARM_HASS = (HASS_COLOR_MAX - HASS_COLOR_MIN) / 3 * 2 + HASS_COLOR_MIN | ||
TEMP_COLD_HASS = (HASS_COLOR_MAX - HASS_COLOR_MIN) / 3 + HASS_COLOR_MIN | ||
|
||
SUPPORT_ZWAVE_DIMMER = SUPPORT_BRIGHTNESS | ||
SUPPORT_ZWAVE_COLOR = SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR | ||
SUPPORT_ZWAVE_COLORTEMP = (SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR | ||
| SUPPORT_COLOR_TEMP) | ||
|
||
|
||
def get_device(node, values, node_config, **kwargs): | ||
"""Create zwave entity device.""" | ||
|
@@ -72,6 +67,13 @@ def brightness_state(value): | |
return 0, STATE_OFF | ||
|
||
|
||
def ct_to_rgb(temp): | ||
"""Convert color temperature (mireds) to RGB.""" | ||
colorlist = list( | ||
color_temperature_to_rgb(color_temperature_mired_to_kelvin(temp))) | ||
return [int(val) for val in colorlist] | ||
|
||
|
||
class ZwaveDimmer(zwave.ZWaveDeviceEntity, Light): | ||
"""Representation of a Z-Wave dimmer.""" | ||
|
||
|
@@ -80,6 +82,7 @@ def __init__(self, values, refresh, delay): | |
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN) | ||
self._brightness = None | ||
self._state = None | ||
self._supported_features = None | ||
self._delay = delay | ||
self._refresh_value = refresh | ||
self._zw098 = None | ||
|
@@ -100,13 +103,20 @@ def __init__(self, values, refresh, delay): | |
self._timer = None | ||
_LOGGER.debug('self._refreshing=%s self.delay=%s', | ||
self._refresh_value, self._delay) | ||
self.value_added() | ||
self.update_properties() | ||
|
||
def update_properties(self): | ||
"""Update internal properties based on zwave values.""" | ||
# Brightness | ||
self._brightness, self._state = brightness_state(self.values.primary) | ||
|
||
def value_added(self): | ||
"""Called when a new value is added to this entity.""" | ||
self._supported_features = SUPPORT_BRIGHTNESS | ||
if self.values.dimming_duration is not None: | ||
self._supported_features |= SUPPORT_TRANSITION | ||
|
||
def value_changed(self): | ||
"""Called when a value for this entity's node has changed.""" | ||
if self._refresh_value: | ||
|
@@ -139,10 +149,43 @@ def is_on(self): | |
@property | ||
def supported_features(self): | ||
"""Flag supported features.""" | ||
return SUPPORT_ZWAVE_DIMMER | ||
return self._supported_features | ||
|
||
def _set_duration(self, **kwargs): | ||
"""Set the transition time for the brightness value. | ||
|
||
Zwave Dimming Duration values: | ||
0x00 = instant | ||
0x01-0x7F = 1 second to 127 seconds | ||
0x80-0xFE = 1 minute to 127 minutes | ||
0xFF = factory default | ||
""" | ||
if self.values.dimming_duration is None: | ||
if ATTR_TRANSITION in kwargs: | ||
_LOGGER.debug("Dimming not supported by %s.", self.entity_id) | ||
return | ||
|
||
if ATTR_TRANSITION not in kwargs: | ||
self.values.dimming_duration.data = 0xFF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check in OZW_Log.txt if this assignment causes a zwave message to be sent when data doesn't actually changes? (i.e. it was already 0xFF) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll take a look, but at least from a theoretical level it shouldn't. The dimming duration is actually just a parameter that gets sent with the multilevel switch set command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it is. You can see where the
|
||
return | ||
|
||
transition = kwargs[ATTR_TRANSITION] | ||
if transition <= 127: | ||
self.values.dimming_duration.data = int(transition) | ||
elif transition > 7620: | ||
self.values.dimming_duration.data = 0xFE | ||
_LOGGER.warning("Transition clipped to 127 minutes for %s.", | ||
self.entity_id) | ||
else: | ||
minutes = int(transition / 60) | ||
_LOGGER.debug("Transition rounded to %d minutes for %s.", | ||
minutes, self.entity_id) | ||
self.values.dimming_duration.data = minutes + 0x7F | ||
|
||
def turn_on(self, **kwargs): | ||
"""Turn the device on.""" | ||
self._set_duration(**kwargs) | ||
|
||
# Zwave multilevel switches use a range of [0, 99] to control | ||
# brightness. Level 255 means to set it to previous value. | ||
if ATTR_BRIGHTNESS in kwargs: | ||
|
@@ -156,17 +199,12 @@ def turn_on(self, **kwargs): | |
|
||
def turn_off(self, **kwargs): | ||
"""Turn the device off.""" | ||
self._set_duration(**kwargs) | ||
|
||
if self.node.set_dimmer(self.values.primary.value_id, 0): | ||
self._state = STATE_OFF | ||
|
||
|
||
def ct_to_rgb(temp): | ||
"""Convert color temperature (mireds) to RGB.""" | ||
colorlist = list( | ||
color_temperature_to_rgb(color_temperature_mired_to_kelvin(temp))) | ||
return [int(val) for val in colorlist] | ||
|
||
|
||
class ZwaveColorLight(ZwaveDimmer): | ||
"""Representation of a Z-Wave color changing light.""" | ||
|
||
|
@@ -178,6 +216,14 @@ def __init__(self, values, refresh, delay): | |
|
||
super().__init__(values, refresh, delay) | ||
|
||
def value_added(self): | ||
"""Called when a new value is added to this entity.""" | ||
super().value_added() | ||
|
||
self._supported_features |= SUPPORT_RGB_COLOR | ||
if self._zw098: | ||
self._supported_features |= SUPPORT_COLOR_TEMP | ||
|
||
def update_properties(self): | ||
"""Update internal properties based on zwave values.""" | ||
super().update_properties() | ||
|
@@ -288,11 +334,3 @@ def turn_on(self, **kwargs): | |
self.values.color.data = rgbw | ||
|
||
super().turn_on(**kwargs) | ||
|
||
@property | ||
def supported_features(self): | ||
"""Flag supported features.""" | ||
if self._zw098: | ||
return SUPPORT_ZWAVE_COLORTEMP | ||
else: | ||
return SUPPORT_ZWAVE_COLOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but I just moved this up so it's not in-between the two classes.