Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def set_auto_temp_hold(self, heat_temp, cool_temp):
cool_temp_setpoint,
heat_temp_setpoint,
self.hold_preference(),
self.hold_hours(),
)
_LOGGER.debug(
"Setting ecobee hold_temp to: heat=%s, is=%s, cool=%s, is=%s",
Expand Down Expand Up @@ -717,15 +718,32 @@ def resume_program(self, resume_all):

def hold_preference(self):
"""Return user preference setting for hold time."""
# Values returned from thermostat are 'useEndTime4hour',
# 'useEndTime2hour', 'nextTransition', 'indefinite', 'askMe'
default = self.thermostat["settings"]["holdAction"]
if default == "nextTransition":
return default
# add further conditions if other hold durations should be
# supported; note that this should not include 'indefinite'
# as an indefinite away hold is interpreted as away_mode
return "nextTransition"
# Values returned from thermostat are:
# "useEndTime2hour", "useEndTime4hour"
# "nextPeriod", "askMe"
# "indefinite"
device_preference = self.thermostat["settings"]["holdAction"]
# Currently supported pyecobee holdTypes:
# dateTime, nextTransition, indefinite, holdHours
hold_pref_map = {
"useEndTime2hour": "holdHours",
"useEndTime4hour": "holdHours",
"indefinite": "indefinite",
}
return hold_pref_map.get(device_preference, "nextTransition")

def hold_hours(self):
"""Return user preference setting for hold duration in hours."""
# Values returned from thermostat are:
# "useEndTime2hour", "useEndTime4hour"
# "nextPeriod", "askMe"
# "indefinite"
device_preference = self.thermostat["settings"]["holdAction"]
hold_hours_map = {
"useEndTime2hour": 2,
"useEndTime4hour": 4,
}
return hold_hours_map.get(device_preference, 0)

def create_vacation(self, service_data):
"""Create a vacation with user-specified parameters."""
Expand Down
38 changes: 30 additions & 8 deletions tests/components/ecobee/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,32 @@ async def test_set_temperature(ecobee_fixture, thermostat, data):
# Auto -> Auto
data.reset_mock()
thermostat.set_temperature(target_temp_low=20, target_temp_high=30)
data.ecobee.set_hold_temp.assert_has_calls([mock.call(1, 30, 20, "nextTransition")])
data.ecobee.set_hold_temp.assert_has_calls(
[mock.call(1, 30, 20, "nextTransition", 0)]
)

# Auto -> Hold
data.reset_mock()
thermostat.set_temperature(temperature=20)
data.ecobee.set_hold_temp.assert_has_calls([mock.call(1, 25, 15, "nextTransition")])
data.ecobee.set_hold_temp.assert_has_calls(
[mock.call(1, 25, 15, "nextTransition", 0)]
)

# Cool -> Hold
data.reset_mock()
ecobee_fixture["settings"]["hvacMode"] = "cool"
thermostat.set_temperature(temperature=20.5)
data.ecobee.set_hold_temp.assert_has_calls(
[mock.call(1, 20.5, 20.5, "nextTransition")]
[mock.call(1, 20.5, 20.5, "nextTransition", 0)]
)

# Heat -> Hold
data.reset_mock()
ecobee_fixture["settings"]["hvacMode"] = "heat"
thermostat.set_temperature(temperature=20)
data.ecobee.set_hold_temp.assert_has_calls([mock.call(1, 20, 20, "nextTransition")])
data.ecobee.set_hold_temp.assert_has_calls(
[mock.call(1, 20, 20, "nextTransition", 0)]
)

# Heat -> Auto
data.reset_mock()
Expand Down Expand Up @@ -280,18 +286,34 @@ async def test_resume_program(thermostat, data):

async def test_hold_preference(ecobee_fixture, thermostat):
"""Test hold preference."""
assert thermostat.hold_preference() == "nextTransition"
ecobee_fixture["settings"]["holdAction"] = "indefinite"
assert thermostat.hold_preference() == "indefinite"
for action in ["useEndTime2hour", "useEndTime4hour"]:
ecobee_fixture["settings"]["holdAction"] = action
assert thermostat.hold_preference() == "holdHours"
for action in [
"useEndTime4hour",
"useEndTime2hour",
"nextPeriod",
"indefinite",
"askMe",
]:
ecobee_fixture["settings"]["holdAction"] = action
assert thermostat.hold_preference() == "nextTransition"


def test_hold_hours(ecobee_fixture, thermostat):
"""Test hold hours preference."""
ecobee_fixture["settings"]["holdAction"] = "useEndTime2hour"
assert thermostat.hold_hours() == 2
ecobee_fixture["settings"]["holdAction"] = "useEndTime4hour"
assert thermostat.hold_hours() == 4
for action in [
"nextPeriod",
"indefinite",
"askMe",
]:
ecobee_fixture["settings"]["holdAction"] = action
assert thermostat.hold_hours() == 0


async def test_set_fan_mode_on(thermostat, data):
"""Test set fan mode to on."""
data.reset_mock()
Expand Down