Map dry and fan only states for homekit thermostats (#33682)

Homekit only has Off/Heat/Cool/Auto at this time, but
at least we can prevent the device from erroring
by mapping dry and fan to cool so it continues
to function.
This commit is contained in:
J. Nick Koston 2020-04-05 08:47:32 -05:00 committed by GitHub
parent f38011560f
commit de317fb2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -16,6 +16,8 @@ from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL,
CURRENT_HVAC_DRY,
CURRENT_HVAC_FAN,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
@ -91,6 +93,8 @@ HC_HASS_TO_HOMEKIT_ACTION = {
CURRENT_HVAC_IDLE: 0,
CURRENT_HVAC_HEAT: 1,
CURRENT_HVAC_COOL: 2,
CURRENT_HVAC_DRY: 2,
CURRENT_HVAC_FAN: 2,
}
@ -382,6 +386,7 @@ class Thermostat(HomeAccessory):
# Set current operation mode for supported thermostats
hvac_action = new_state.attributes.get(ATTR_HVAC_ACTION)
if hvac_action:
self.char_current_heat_cool.set_value(
HC_HASS_TO_HOMEKIT_ACTION[hvac_action]
)

View File

@ -17,6 +17,8 @@ from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_LOW,
ATTR_TARGET_TEMP_STEP,
CURRENT_HVAC_COOL,
CURRENT_HVAC_DRY,
CURRENT_HVAC_FAN,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
DEFAULT_MAX_TEMP,
@ -25,6 +27,7 @@ from homeassistant.components.climate.const import (
DOMAIN as DOMAIN_CLIMATE,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
@ -233,6 +236,38 @@ async def test_thermostat(hass, hk_driver, cls, events):
assert acc.char_current_temp.value == 22.0
assert acc.char_display_units.value == 0
hass.states.async_set(
entity_id,
HVAC_MODE_FAN_ONLY,
{
ATTR_TEMPERATURE: 22.0,
ATTR_CURRENT_TEMPERATURE: 22.0,
ATTR_HVAC_ACTION: CURRENT_HVAC_FAN,
},
)
await hass.async_block_till_done()
assert acc.char_target_temp.value == 22.0
assert acc.char_current_heat_cool.value == 2
assert acc.char_target_heat_cool.value == 2
assert acc.char_current_temp.value == 22.0
assert acc.char_display_units.value == 0
hass.states.async_set(
entity_id,
HVAC_MODE_DRY,
{
ATTR_TEMPERATURE: 22.0,
ATTR_CURRENT_TEMPERATURE: 22.0,
ATTR_HVAC_ACTION: CURRENT_HVAC_DRY,
},
)
await hass.async_block_till_done()
assert acc.char_target_temp.value == 22.0
assert acc.char_current_heat_cool.value == 2
assert acc.char_target_heat_cool.value == 2
assert acc.char_current_temp.value == 22.0
assert acc.char_display_units.value == 0
# Set from HomeKit
call_set_temperature = async_mock_service(hass, DOMAIN_CLIMATE, "set_temperature")
call_set_hvac_mode = async_mock_service(hass, DOMAIN_CLIMATE, "set_hvac_mode")