Fix off_delay for zwave trigger sensors (#8864)

This commit is contained in:
John Arild Berentsen 2017-08-06 17:31:32 +02:00 committed by Andrey
parent 3723f67dc1
commit 99a20c845c
3 changed files with 17 additions and 7 deletions

View File

@ -23,9 +23,7 @@ def get_device(values, **kwargs):
"""Create Z-Wave entity device.""" """Create Z-Wave entity device."""
device_mapping = workaround.get_device_mapping(values.primary) device_mapping = workaround.get_device_mapping(values.primary)
if device_mapping == workaround.WORKAROUND_NO_OFF_EVENT: if device_mapping == workaround.WORKAROUND_NO_OFF_EVENT:
# Default the multiplier to 4 return ZWaveTriggerSensor(values, "motion")
re_arm_multiplier = zwave.get_config_value(values.primary.node, 9) or 4
return ZWaveTriggerSensor(values, "motion", re_arm_multiplier * 8)
if workaround.get_device_component_mapping(values.primary) == DOMAIN: if workaround.get_device_component_mapping(values.primary) == DOMAIN:
return ZWaveBinarySensor(values, None) return ZWaveBinarySensor(values, None)
@ -62,15 +60,21 @@ class ZWaveBinarySensor(BinarySensorDevice, zwave.ZWaveDeviceEntity):
class ZWaveTriggerSensor(ZWaveBinarySensor): class ZWaveTriggerSensor(ZWaveBinarySensor):
"""Representation of a stateless sensor within Z-Wave.""" """Representation of a stateless sensor within Z-Wave."""
def __init__(self, values, device_class, re_arm_sec=60): def __init__(self, values, device_class):
"""Initialize the sensor.""" """Initialize the sensor."""
super(ZWaveTriggerSensor, self).__init__(values, device_class) super(ZWaveTriggerSensor, self).__init__(values, device_class)
self.re_arm_sec = re_arm_sec # Set default off delay to 60 sec
self.re_arm_sec = 60
self.invalidate_after = None self.invalidate_after = None
def update_properties(self): def update_properties(self):
"""Handle value changes for this entity's node.""" """Handle value changes for this entity's node."""
self._state = self.values.primary.data self._state = self.values.primary.data
_LOGGER.debug('off_delay=%s', self.values.off_delay)
# Set re_arm_sec if off_delay is provided from the sensor
if self.values.off_delay:
_LOGGER.debug('off_delay.data=%s', self.values.off_delay.data)
self.re_arm_sec = self.values.off_delay.data * 8
# only allow this value to be true for re_arm secs # only allow this value to be true for re_arm secs
if not self.hass: if not self.hass:
return return

View File

@ -28,7 +28,12 @@ DISCOVERY_SCHEMAS = [
const.DISC_PRIMARY: { const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SENSOR_BINARY], const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SENSOR_BINARY],
const.DISC_TYPE: const.TYPE_BOOL, const.DISC_TYPE: const.TYPE_BOOL,
const.DISC_GENRE: const.GENRE_USER const.DISC_GENRE: const.GENRE_USER,
},
'off_delay': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_CONFIGURATION],
const.DISC_INDEX: [9],
const.DISC_OPTIONAL: True,
}})}, }})},
{const.DISC_COMPONENT: 'climate', {const.DISC_COMPONENT: 'climate',
const.DISC_GENERIC_DEVICE_CLASS: [const.GENERIC_TYPE_THERMOSTAT], const.DISC_GENERIC_DEVICE_CLASS: [const.GENERIC_TYPE_THERMOSTAT],

View File

@ -77,7 +77,8 @@ def test_trigger_sensor_value_changed(hass, mock_openzwave):
node = MockNode( node = MockNode(
manufacturer_id='013c', product_type='0002', product_id='0002') manufacturer_id='013c', product_type='0002', product_id='0002')
value = MockValue(data=False, node=node) value = MockValue(data=False, node=node)
values = MockEntityValues(primary=value) value_off_delay = MockValue(data=15, node=node)
values = MockEntityValues(primary=value, off_delay=value_off_delay)
device = zwave.get_device(node=node, values=values, node_config={}) device = zwave.get_device(node=node, values=values, node_config={})
assert not device.is_on assert not device.is_on