Report correct thermostat mode to Alexa (#18053)
We were erroneously reporting the _previous_ mode. So if the thermostat was off and the user asks, "Alexa, set the thermostat to heat", the thermostat would be set to heat but Alexa would respond, "The thermostat is off." Bug caught by @Thunderbird2086 at https://github.com/home-assistant/home-assistant/pull/17969#issuecomment-434654345pull/17604/head^2
parent
b763c0f902
commit
93706fa568
|
@ -1839,11 +1839,17 @@ async def async_api_set_thermostat_mode(hass, config, directive, context):
|
||||||
climate.ATTR_OPERATION_MODE: ha_mode,
|
climate.ATTR_OPERATION_MODE: ha_mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response = directive.response()
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
entity.domain, climate.SERVICE_SET_OPERATION_MODE, data,
|
entity.domain, climate.SERVICE_SET_OPERATION_MODE, data,
|
||||||
blocking=False, context=context)
|
blocking=False, context=context)
|
||||||
|
response.add_context_property({
|
||||||
|
'name': 'thermostatMode',
|
||||||
|
'namespace': 'Alexa.ThermostatController',
|
||||||
|
'value': mode,
|
||||||
|
})
|
||||||
|
|
||||||
return directive.response()
|
return response
|
||||||
|
|
||||||
|
|
||||||
@HANDLERS.register(('Alexa', 'ReportState'))
|
@HANDLERS.register(('Alexa', 'ReportState'))
|
||||||
|
|
|
@ -873,22 +873,41 @@ async def test_thermostat(hass):
|
||||||
)
|
)
|
||||||
assert msg['event']['payload']['type'] == 'TEMPERATURE_VALUE_OUT_OF_RANGE'
|
assert msg['event']['payload']['type'] == 'TEMPERATURE_VALUE_OUT_OF_RANGE'
|
||||||
|
|
||||||
call, _ = await assert_request_calls_service(
|
# Setting mode, the payload can be an object with a value attribute...
|
||||||
|
call, msg = await assert_request_calls_service(
|
||||||
'Alexa.ThermostatController', 'SetThermostatMode',
|
'Alexa.ThermostatController', 'SetThermostatMode',
|
||||||
'climate#test_thermostat', 'climate.set_operation_mode',
|
'climate#test_thermostat', 'climate.set_operation_mode',
|
||||||
hass,
|
hass,
|
||||||
payload={'thermostatMode': {'value': 'HEAT'}}
|
payload={'thermostatMode': {'value': 'HEAT'}}
|
||||||
)
|
)
|
||||||
assert call.data['operation_mode'] == 'heat'
|
assert call.data['operation_mode'] == 'heat'
|
||||||
|
properties = _ReportedProperties(msg['context']['properties'])
|
||||||
|
properties.assert_equal(
|
||||||
|
'Alexa.ThermostatController', 'thermostatMode', 'HEAT')
|
||||||
|
|
||||||
call, _ = await assert_request_calls_service(
|
call, msg = await assert_request_calls_service(
|
||||||
|
'Alexa.ThermostatController', 'SetThermostatMode',
|
||||||
|
'climate#test_thermostat', 'climate.set_operation_mode',
|
||||||
|
hass,
|
||||||
|
payload={'thermostatMode': {'value': 'COOL'}}
|
||||||
|
)
|
||||||
|
assert call.data['operation_mode'] == 'cool'
|
||||||
|
properties = _ReportedProperties(msg['context']['properties'])
|
||||||
|
properties.assert_equal(
|
||||||
|
'Alexa.ThermostatController', 'thermostatMode', 'COOL')
|
||||||
|
|
||||||
|
# ...it can also be just the mode.
|
||||||
|
call, msg = await assert_request_calls_service(
|
||||||
'Alexa.ThermostatController', 'SetThermostatMode',
|
'Alexa.ThermostatController', 'SetThermostatMode',
|
||||||
'climate#test_thermostat', 'climate.set_operation_mode',
|
'climate#test_thermostat', 'climate.set_operation_mode',
|
||||||
hass,
|
hass,
|
||||||
payload={'thermostatMode': 'HEAT'}
|
payload={'thermostatMode': 'HEAT'}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert call.data['operation_mode'] == 'heat'
|
assert call.data['operation_mode'] == 'heat'
|
||||||
|
properties = _ReportedProperties(msg['context']['properties'])
|
||||||
|
properties.assert_equal(
|
||||||
|
'Alexa.ThermostatController', 'thermostatMode', 'HEAT')
|
||||||
|
|
||||||
msg = await assert_request_fails(
|
msg = await assert_request_fails(
|
||||||
'Alexa.ThermostatController', 'SetThermostatMode',
|
'Alexa.ThermostatController', 'SetThermostatMode',
|
||||||
'climate#test_thermostat', 'climate.set_operation_mode',
|
'climate#test_thermostat', 'climate.set_operation_mode',
|
||||||
|
|
Loading…
Reference in New Issue