zwave refactor, don't use ozw values directly in properties. (#5961)

* First round of not using values directly

* Round two

* lint

* Round four

* Conflict

* Round five

* Update zwave.py

* round six

* Docstring

* flakywakie

* Fetch values in constructor

* Blank line removal

* Set attributes in callback

* Docstring

* Round seven

* Ughgit add homeassistant/components/lock/zwave.py!

* Sloppy code
This commit is contained in:
John Arild Berentsen 2017-02-18 08:56:05 +01:00 committed by Paulus Schoutsen
parent c1eed148cc
commit 799fbe42f8
8 changed files with 78 additions and 76 deletions

View file

@ -50,13 +50,18 @@ class ZWaveBinarySensor(BinarySensorDevice, zwave.ZWaveDeviceEntity):
def __init__(self, value, device_class):
"""Initialize the sensor."""
self._sensor_type = device_class
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
self._sensor_type = device_class
self._state = self._value.data
def update_properties(self):
"""Callback on data changes for node values."""
self._state = self._value.data
@property
def is_on(self):
"""Return True if the binary sensor is on."""
return self._value.data
return self._state
@property
def device_class(self):
@ -80,26 +85,23 @@ class ZWaveTriggerSensor(ZWaveBinarySensor):
self.invalidate_after = dt_util.utcnow() + datetime.timedelta(
seconds=self.re_arm_sec)
# If it's active make sure that we set the timeout tracker
if value.data:
track_point_in_time(
self._hass, self.async_update_ha_state,
self.invalidate_after)
track_point_in_time(
self._hass, self.async_update_ha_state,
self.invalidate_after)
def value_changed(self, value):
def update_properties(self):
"""Called when a value for this entity's node has changed."""
if self._value.value_id == value.value_id:
self.schedule_update_ha_state()
if value.data:
# only allow this value to be true for re_arm secs
self.invalidate_after = dt_util.utcnow() + datetime.timedelta(
seconds=self.re_arm_sec)
track_point_in_time(
self._hass, self.async_update_ha_state,
self.invalidate_after)
self._state = self._value.data
# only allow this value to be true for re_arm secs
self.invalidate_after = dt_util.utcnow() + datetime.timedelta(
seconds=self.re_arm_sec)
track_point_in_time(
self._hass, self.async_update_ha_state,
self.invalidate_after)
@property
def is_on(self):
"""Return True if movement has happened within the rearm time."""
return self._value.data and \
return self._state and \
(self.invalidate_after is None or
self.invalidate_after > dt_util.utcnow())