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:
1 parent
c1eed148cc
commit
799fbe42f8
8 files changed
+78
-76
No files matched your search
@@ -53,6 +53,12 @@ class ZWaveSensor(zwave.ZWaveDeviceEntity):
|
||||
def __init__(self, value):
|
||||
"""Initialize the sensor."""
|
||||
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
||||
self.update_properties()
|
||||
|
||||
def update_properties(self):
|
||||
"""Callback on data changes for node values."""
|
||||
self._state = self._value.data
|
||||
self._units = self._value.units
|
||||
|
||||
@property
|
||||
def force_update(self):
|
||||
@@ -62,12 +68,12 @@ class ZWaveSensor(zwave.ZWaveDeviceEntity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._value.data
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement the value is expressed in."""
|
||||
return self._value.units
|
||||
return self._units
|
||||
|
||||
|
||||
class ZWaveMultilevelSensor(ZWaveSensor):
|
||||
@@ -76,26 +82,22 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
value = self._value.data
|
||||
if self._units in ('C', 'F'):
|
||||
return round(self._state, 1)
|
||||
elif isinstance(self._state, float):
|
||||
return round(self._state, 2)
|
||||
|
||||
if self._value.units in ('C', 'F'):
|
||||
return round(value, 1)
|
||||
elif isinstance(value, float):
|
||||
return round(value, 2)
|
||||
|
||||
return value
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
unit = self._value.units
|
||||
|
||||
if unit == 'C':
|
||||
if self._units == 'C':
|
||||
return TEMP_CELSIUS
|
||||
elif unit == 'F':
|
||||
elif self._units == 'F':
|
||||
return TEMP_FAHRENHEIT
|
||||
else:
|
||||
return unit
|
||||
return self._units
|
||||
|
||||
|
||||
class ZWaveAlarmSensor(ZWaveSensor):
|
||||
|
||||
Reference in new issue
Block a user