Skip to content

Commit

Permalink
Fix home-assistant#18244 for ecobee by moving current_operation prope…
Browse files Browse the repository at this point in the history
…rty to current_operation_mode which is more accurate and defining current_operation properly, thanks @ZetaPhoenix
  • Loading branch information
nhorvath committed Feb 8, 2019
1 parent ff122b8 commit bfd9055
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
40 changes: 30 additions & 10 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,25 @@ def current_temperature(self):
@property
def target_temperature_low(self):
"""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 None

@property
def target_temperature_high(self):
"""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 None

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if self.current_operation == STATE_AUTO:
if self.current_operation_mode == STATE_AUTO:
return None
if self.current_operation == STATE_HEAT:
if self.current_operation_mode == STATE_HEAT:
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 None

Expand Down Expand Up @@ -232,7 +232,29 @@ def _current_hold_mode(self):

@property
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 \
self.operation_mode == 'heatPump':
return STATE_HEAT
Expand Down Expand Up @@ -264,9 +286,7 @@ def fan_min_on_time(self):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
# Move these to Thermostat Device and make them global
status = self.thermostat['equipmentStatus']
operation = None
if status == '':
operation = STATE_IDLE
elif 'Cool' in status:
Expand Down Expand Up @@ -382,7 +402,7 @@ def set_temp_hold(self, temp):
heatCoolMinDelta property.
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:
heat_temp = temp
cool_temp = temp
Expand All @@ -398,7 +418,7 @@ def set_temperature(self, **kwargs):
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
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):
self.set_auto_temp_hold(low_temp, high_temp)
elif temp is not None:
Expand Down
23 changes: 19 additions & 4 deletions tests/components/ecobee/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,31 @@ def test_current_hold_mode_auto_hold(self):

def test_current_operation(self):
"""Test current operation property."""
assert 'auto' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'heat'
self.ecobee['settings']['hvacMode'] = 'auto'
self.ecobee['equipmentStatus'] = ''
assert 'idle' == self.thermostat.current_operation
self.ecobee['equipmentStatus'] = 'fan,heatPump1'
assert 'heat' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'cool'
self.ecobee['equipmentStatus'] = 'fan,compCool1'
assert 'cool' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
self.ecobee['equipmentStatus'] = 'fan,auxHeat1'
assert 'heat' == self.thermostat.current_operation
self.ecobee['settings']['hvacMode'] = 'off'
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):
"""Test operation list property."""
assert ['auto', 'auxHeatOnly', 'cool',
Expand Down

0 comments on commit bfd9055

Please sign in to comment.