Skip to content

Commit

Permalink
Zwave climate Bugfix: if some setpoints have different units, we shou…
Browse files Browse the repository at this point in the history
…ld 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
  • Loading branch information
turbokongen authored and robbiet480 committed Sep 2, 2016
1 parent 49ed9e6 commit 1bdb51d
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions homeassistant/components/climate/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.components.zwave import (
ATTR_NODE_ID, ATTR_VALUE_ID, ZWaveDeviceEntity)
from homeassistant.components import zwave
from homeassistant.const import (TEMP_FAHRENHEIT, TEMP_CELSIUS)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,11 +58,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.debug("No discovery_info=%s or no NETWORK=%s",
discovery_info, zwave.NETWORK)
return

temp_unit = hass.config.units.temperature_unit
node = zwave.NETWORK.nodes[discovery_info[ATTR_NODE_ID]]
value = node.values[discovery_info[ATTR_VALUE_ID]]
value.set_change_verified(False)
add_devices([ZWaveClimate(value)])
add_devices([ZWaveClimate(value, temp_unit)])
_LOGGER.debug("discovery_info=%s and zwave.NETWORK=%s",
discovery_info, zwave.NETWORK)

Expand All @@ -73,7 +72,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
"""Represents a ZWave Climate device."""

# 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."""
from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher
Expand All @@ -87,7 +86,8 @@ def __init__(self, value):
self._fan_list = None
self._current_swing_mode = 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.update_properties()
# register listener
Expand Down Expand Up @@ -115,18 +115,6 @@ def value_changed(self, value):

def update_properties(self):
"""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
for value in self._node.get_values(
class_id=COMMAND_CLASS_THERMOSTAT_MODE).values():
Expand Down Expand Up @@ -158,6 +146,17 @@ def update_properties(self):
_LOGGER.debug("self._swing_list=%s", self._swing_list)
_LOGGER.debug("self._current_swing_mode=%s",
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
def should_poll(self):
Expand Down Expand Up @@ -187,14 +186,7 @@ def swing_list(self):
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
unit = 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)
return self._unit

@property
def current_temperature(self):
Expand Down

0 comments on commit 1bdb51d

Please sign in to comment.