From e6e5b98bc711c2b3f02df2622815f12a0d220155 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 4 Aug 2022 09:13:20 +0200 Subject: [PATCH] Allow climate operation mode fan_only as custom mode in Alexa (#76148) * Add support for FAN_ONLY mode * Tests for fan_only as custom mode --- homeassistant/components/alexa/const.py | 7 +++++-- tests/components/alexa/test_capabilities.py | 19 ++++++++++++++++++- tests/components/alexa/test_smart_home.py | 16 ++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/alexa/const.py b/homeassistant/components/alexa/const.py index c6ac3071d94..d51409a5a1c 100644 --- a/homeassistant/components/alexa/const.py +++ b/homeassistant/components/alexa/const.py @@ -73,11 +73,14 @@ API_THERMOSTAT_MODES = OrderedDict( (climate.HVACMode.HEAT_COOL, "AUTO"), (climate.HVACMode.AUTO, "AUTO"), (climate.HVACMode.OFF, "OFF"), - (climate.HVACMode.FAN_ONLY, "OFF"), + (climate.HVACMode.FAN_ONLY, "CUSTOM"), (climate.HVACMode.DRY, "CUSTOM"), ] ) -API_THERMOSTAT_MODES_CUSTOM = {climate.HVACMode.DRY: "DEHUMIDIFY"} +API_THERMOSTAT_MODES_CUSTOM = { + climate.HVACMode.DRY: "DEHUMIDIFY", + climate.HVACMode.FAN_ONLY: "FAN", +} API_THERMOSTAT_PRESETS = {climate.PRESET_ECO: "ECO"} # AlexaModeController does not like a single mode for the fan preset, we add PRESET_MODE_NA if a fan has only one preset_mode diff --git a/tests/components/alexa/test_capabilities.py b/tests/components/alexa/test_capabilities.py index ea6c96bbaef..10ad5f7ebd2 100644 --- a/tests/components/alexa/test_capabilities.py +++ b/tests/components/alexa/test_capabilities.py @@ -590,7 +590,7 @@ async def test_report_climate_state(hass): {"value": 34.0, "scale": "CELSIUS"}, ) - for off_modes in (climate.HVAC_MODE_OFF, climate.HVAC_MODE_FAN_ONLY): + for off_modes in [climate.HVAC_MODE_OFF]: hass.states.async_set( "climate.downstairs", off_modes, @@ -626,6 +626,23 @@ async def test_report_climate_state(hass): "Alexa.TemperatureSensor", "temperature", {"value": 34.0, "scale": "CELSIUS"} ) + # assert fan_only is reported as CUSTOM + hass.states.async_set( + "climate.downstairs", + "fan_only", + { + "friendly_name": "Climate Downstairs", + "supported_features": 91, + climate.ATTR_CURRENT_TEMPERATURE: 31, + ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, + }, + ) + properties = await reported_properties(hass, "climate.downstairs") + properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "CUSTOM") + properties.assert_equal( + "Alexa.TemperatureSensor", "temperature", {"value": 31.0, "scale": "CELSIUS"} + ) + hass.states.async_set( "climate.heat", "heat", diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 0169eeff9d5..df45d90358b 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -2030,7 +2030,7 @@ async def test_thermostat(hass): "current_temperature": 75.0, "friendly_name": "Test Thermostat", "supported_features": 1 | 2 | 4 | 128, - "hvac_modes": ["off", "heat", "cool", "auto", "dry"], + "hvac_modes": ["off", "heat", "cool", "auto", "dry", "fan_only"], "preset_mode": None, "preset_modes": ["eco"], "min_temp": 50, @@ -2220,7 +2220,7 @@ async def test_thermostat(hass): properties = ReportedProperties(msg["context"]["properties"]) properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "HEAT") - # Assert we can call custom modes + # Assert we can call custom modes for dry and fan_only call, msg = await assert_request_calls_service( "Alexa.ThermostatController", "SetThermostatMode", @@ -2233,6 +2233,18 @@ async def test_thermostat(hass): properties = ReportedProperties(msg["context"]["properties"]) properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "CUSTOM") + call, msg = await assert_request_calls_service( + "Alexa.ThermostatController", + "SetThermostatMode", + "climate#test_thermostat", + "climate.set_hvac_mode", + hass, + payload={"thermostatMode": {"value": "CUSTOM", "customName": "FAN"}}, + ) + assert call.data["hvac_mode"] == "fan_only" + properties = ReportedProperties(msg["context"]["properties"]) + properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "CUSTOM") + # assert unsupported custom mode msg = await assert_request_fails( "Alexa.ThermostatController",