From 0eb3e49880f87408bcaee77ba5771ce98ba3de4d Mon Sep 17 00:00:00 2001 From: Michael Wei Date: Wed, 18 Apr 2018 11:19:05 -0700 Subject: [PATCH] Alexa thermostat fails to properly parse 'value' field for climate (#13958) * Fix thermostat payload issue * fix test payload * style issue * handle both string and value object --- homeassistant/components/alexa/smart_home.py | 1 + tests/components/alexa/test_smart_home.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/alexa/smart_home.py b/homeassistant/components/alexa/smart_home.py index 707f8d02958..c5c68f1af40 100644 --- a/homeassistant/components/alexa/smart_home.py +++ b/homeassistant/components/alexa/smart_home.py @@ -1471,6 +1471,7 @@ async def async_api_adjust_target_temp(hass, config, request, entity): async def async_api_set_thermostat_mode(hass, config, request, entity): """Process a set thermostat mode request.""" mode = request[API_PAYLOAD]['thermostatMode'] + mode = mode if isinstance(mode, str) else mode['value'] operation_list = entity.attributes.get(climate.ATTR_OPERATION_LIST) # Work around a pylint false positive due to diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index dd404b7d57a..afa4d19b5d9 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -807,15 +807,23 @@ async def test_thermostat(hass): 'Alexa.ThermostatController', 'SetThermostatMode', 'climate#test_thermostat', 'climate.set_operation_mode', hass, - payload={'thermostatMode': 'HEAT'} + payload={'thermostatMode': {'value': 'HEAT'}} ) assert call.data['operation_mode'] == 'heat' + call, _ = await assert_request_calls_service( + 'Alexa.ThermostatController', 'SetThermostatMode', + 'climate#test_thermostat', 'climate.set_operation_mode', + hass, + payload={'thermostatMode': 'HEAT'} + ) + + assert call.data['operation_mode'] == 'heat' msg = await assert_request_fails( 'Alexa.ThermostatController', 'SetThermostatMode', 'climate#test_thermostat', 'climate.set_operation_mode', hass, - payload={'thermostatMode': 'INVALID'} + payload={'thermostatMode': {'value': 'INVALID'}} ) assert msg['event']['payload']['type'] == 'UNSUPPORTED_THERMOSTAT_MODE'