Zwave climate Bugfix: if some setpoints have different units, we should fetch the o… (#3078)

* Bugfix: if some setpoints have different units, we should fetch the one that are active.

* Move order of population for first time detection

* Default to config if None unit_of_measurement
This commit is contained in:
John Arild Berentsen 2016-08-31 21:50:03 +02:00 committed by GitHub
parent 705b3571f4
commit e5b6592870

View File

@ -12,7 +12,6 @@ from homeassistant.components.climate import ClimateDevice
from homeassistant.components.zwave import ( from homeassistant.components.zwave import (
ATTR_NODE_ID, ATTR_VALUE_ID, ZWaveDeviceEntity) ATTR_NODE_ID, ATTR_VALUE_ID, ZWaveDeviceEntity)
from homeassistant.components import zwave from homeassistant.components import zwave
from homeassistant.const import (TEMP_FAHRENHEIT, TEMP_CELSIUS)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -59,11 +58,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.debug("No discovery_info=%s or no NETWORK=%s", _LOGGER.debug("No discovery_info=%s or no NETWORK=%s",
discovery_info, zwave.NETWORK) discovery_info, zwave.NETWORK)
return return
temp_unit = hass.config.units.temperature_unit
node = zwave.NETWORK.nodes[discovery_info[ATTR_NODE_ID]] node = zwave.NETWORK.nodes[discovery_info[ATTR_NODE_ID]]
value = node.values[discovery_info[ATTR_VALUE_ID]] value = node.values[discovery_info[ATTR_VALUE_ID]]
value.set_change_verified(False) value.set_change_verified(False)
add_devices([ZWaveClimate(value)]) add_devices([ZWaveClimate(value, temp_unit)])
_LOGGER.debug("discovery_info=%s and zwave.NETWORK=%s", _LOGGER.debug("discovery_info=%s and zwave.NETWORK=%s",
discovery_info, zwave.NETWORK) discovery_info, zwave.NETWORK)
@ -73,7 +72,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
"""Represents a ZWave Climate device.""" """Represents a ZWave Climate device."""
# pylint: disable=too-many-public-methods, too-many-instance-attributes # pylint: disable=too-many-public-methods, too-many-instance-attributes
def __init__(self, value): def __init__(self, value, temp_unit):
"""Initialize the zwave climate device.""" """Initialize the zwave climate device."""
from openzwave.network import ZWaveNetwork from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher from pydispatch import dispatcher
@ -87,7 +86,8 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
self._fan_list = None self._fan_list = None
self._current_swing_mode = None self._current_swing_mode = None
self._swing_list = None self._swing_list = None
self._unit = None self._unit = temp_unit
_LOGGER.debug("temp_unit is %s", self._unit)
self._zxt_120 = None self._zxt_120 = None
self.update_properties() self.update_properties()
# register listener # register listener
@ -115,18 +115,6 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
def update_properties(self): def update_properties(self):
"""Callback on data change for the registered node/value pair.""" """Callback on data change for the registered node/value pair."""
# Set point
for value in self._node.get_values(
class_id=COMMAND_CLASS_THERMOSTAT_SETPOINT).values():
self._unit = value.units
if self.current_operation is not None:
if SET_TEMP_TO_INDEX.get(self._current_operation) \
!= value.index:
continue
if self._zxt_120:
continue
self._target_temperature = int(value.data)
# Operation Mode # Operation Mode
for value in self._node.get_values( for value in self._node.get_values(
class_id=COMMAND_CLASS_THERMOSTAT_MODE).values(): class_id=COMMAND_CLASS_THERMOSTAT_MODE).values():
@ -158,6 +146,17 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
_LOGGER.debug("self._swing_list=%s", self._swing_list) _LOGGER.debug("self._swing_list=%s", self._swing_list)
_LOGGER.debug("self._current_swing_mode=%s", _LOGGER.debug("self._current_swing_mode=%s",
self._current_swing_mode) self._current_swing_mode)
# Set point
for value in self._node.get_values(
class_id=COMMAND_CLASS_THERMOSTAT_SETPOINT).values():
if self.current_operation is not None:
if SET_TEMP_TO_INDEX.get(self._current_operation) \
!= value.index:
continue
self._unit = value.units
if self._zxt_120:
continue
self._target_temperature = int(value.data)
@property @property
def should_poll(self): def should_poll(self):
@ -187,14 +186,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
unit = self._unit return self._unit
if unit == 'C':
return TEMP_CELSIUS
elif unit == 'F':
return TEMP_FAHRENHEIT
else:
_LOGGER.exception("unit_of_measurement=%s is not valid",
unit)
@property @property
def current_temperature(self): def current_temperature(self):