Fix #18244 for ecobee by moving current_operation property to current_operation_mode which is more accurate and defining current_operation properly, thanks @ZetaPhoenix

This commit is contained in:
nhorvath
2019-02-08 09:17:15 -05:00
parent ff122b8d4a
commit bfd90551ef
2 changed files with 49 additions and 14 deletions

View File

@@ -159,25 +159,25 @@ class Thermostat(ClimateDevice):
@property @property
def target_temperature_low(self): def target_temperature_low(self):
"""Return the lower bound temperature we try to reach.""" """Return the lower bound temperature we try to reach."""
if self.current_operation == STATE_AUTO: if self.current_operation_mode == STATE_AUTO:
return self.thermostat['runtime']['desiredHeat'] / 10.0 return self.thermostat['runtime']['desiredHeat'] / 10.0
return None return None
@property @property
def target_temperature_high(self): def target_temperature_high(self):
"""Return the upper bound temperature we try to reach.""" """Return the upper bound temperature we try to reach."""
if self.current_operation == STATE_AUTO: if self.current_operation_mode == STATE_AUTO:
return self.thermostat['runtime']['desiredCool'] / 10.0 return self.thermostat['runtime']['desiredCool'] / 10.0
return None return None
@property @property
def target_temperature(self): def target_temperature(self):
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
if self.current_operation == STATE_AUTO: if self.current_operation_mode == STATE_AUTO:
return None return None
if self.current_operation == STATE_HEAT: if self.current_operation_mode == STATE_HEAT:
return self.thermostat['runtime']['desiredHeat'] / 10.0 return self.thermostat['runtime']['desiredHeat'] / 10.0
if self.current_operation == STATE_COOL: if self.current_operation_mode == STATE_COOL:
return self.thermostat['runtime']['desiredCool'] / 10.0 return self.thermostat['runtime']['desiredCool'] / 10.0
return None return None
@@ -232,7 +232,29 @@ class Thermostat(ClimateDevice):
@property @property
def current_operation(self): def current_operation(self):
"""Return current operation.""" """Return current operation the thermostat is calling for.
- STATE_OFF : thermostat is off
- STATE_IDLE: thermostat is on, but not actively heating or cooling
- STATE_HEAT: actively heating
- STATE_COOL: actively cooling
- None: unknown state"""
status = self.thermostat['equipmentStatus']
if self.operation_mode == STATE_OFF:
operation = STATE_OFF
elif 'Cool' in status:
operation = STATE_COOL
elif 'auxHeat' in status:
operation = STATE_HEAT
elif 'heatPump' in status:
operation = STATE_HEAT
else:
operation = STATE_IDLE
return operation
@property
def current_operation_mode(self):
"""Return current mode mapped to states."""
if self.operation_mode == 'auxHeatOnly' or \ if self.operation_mode == 'auxHeatOnly' or \
self.operation_mode == 'heatPump': self.operation_mode == 'heatPump':
return STATE_HEAT return STATE_HEAT
@@ -264,9 +286,7 @@ class Thermostat(ClimateDevice):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""
# Move these to Thermostat Device and make them global
status = self.thermostat['equipmentStatus'] status = self.thermostat['equipmentStatus']
operation = None
if status == '': if status == '':
operation = STATE_IDLE operation = STATE_IDLE
elif 'Cool' in status: elif 'Cool' in status:
@@ -382,7 +402,7 @@ class Thermostat(ClimateDevice):
heatCoolMinDelta property. heatCoolMinDelta property.
https://www.ecobee.com/home/developer/api/examples/ex5.shtml https://www.ecobee.com/home/developer/api/examples/ex5.shtml
""" """
if self.current_operation == STATE_HEAT or self.current_operation == \ if self.current_operation_mode == STATE_HEAT or self.current_operation_mode == \
STATE_COOL: STATE_COOL:
heat_temp = temp heat_temp = temp
cool_temp = temp cool_temp = temp
@@ -398,7 +418,7 @@ class Thermostat(ClimateDevice):
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH) high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
temp = kwargs.get(ATTR_TEMPERATURE) temp = kwargs.get(ATTR_TEMPERATURE)
if self.current_operation == STATE_AUTO and \ if self.current_operation_mode == STATE_AUTO and \
(low_temp is not None or high_temp is not None): (low_temp is not None or high_temp is not None):
self.set_auto_temp_hold(low_temp, high_temp) self.set_auto_temp_hold(low_temp, high_temp)
elif temp is not None: elif temp is not None:

View File

@@ -142,16 +142,31 @@ class TestEcobee(unittest.TestCase):
def test_current_operation(self): def test_current_operation(self):
"""Test current operation property.""" """Test current operation property."""
assert 'auto' == self.thermostat.current_operation self.ecobee['settings']['hvacMode'] = 'auto'
self.ecobee['settings']['hvacMode'] = 'heat' self.ecobee['equipmentStatus'] = ''
assert 'idle' == self.thermostat.current_operation
self.ecobee['equipmentStatus'] = 'fan,heatPump1'
assert 'heat' == self.thermostat.current_operation assert 'heat' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'cool' self.ecobee['equipmentStatus'] = 'fan,compCool1'
assert 'cool' == self.thermostat.current_operation assert 'cool' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly' self.ecobee['equipmentStatus'] = 'fan,auxHeat1'
assert 'heat' == self.thermostat.current_operation assert 'heat' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'off' self.ecobee['settings']['hvacMode'] = 'off'
assert 'off' == self.thermostat.current_operation assert 'off' == self.thermostat.current_operation
def test_current_operation_mode(self):
"""Test current operation mode property."""
self.ecobee['settings']['hvacMode'] = 'auto'
assert 'auto' == self.thermostat.current_operation_mode
self.ecobee['settings']['hvacMode'] = 'heat'
assert 'heat' == self.thermostat.current_operation_mode
self.ecobee['settings']['hvacMode'] = 'cool'
assert 'cool' == self.thermostat.current_operation_mode
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
assert 'heat' == self.thermostat.current_operation_mode
self.ecobee['settings']['hvacMode'] = 'off'
assert 'off' == self.thermostat.current_operation_mode
def test_operation_list(self): def test_operation_list(self):
"""Test operation list property.""" """Test operation list property."""
assert ['auto', 'auxHeatOnly', 'cool', assert ['auto', 'auxHeatOnly', 'cool',