mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Enable Google Assistant OnOffTrait for climate devices that support them (#18544)
* Enable Google Assistant OnOffTrait for climate devices that support them This commit enables the OnOffTrait for climate devices that have the SUPPORT_ON_OFF feature. I have tested this locally with a Sensibo device which supports ON_OFF and a nest device that does not. * Update trait.py * Add tests for onoff_climate * Add OnOff trait to climate.heatpump * Add on status to heatpump in google_assistant tests
This commit is contained in:
parent
2f07e92cc2
commit
02309cc318
@ -197,6 +197,8 @@ class OnOffTrait(_Trait):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def supported(domain, features):
|
def supported(domain, features):
|
||||||
"""Test if state is supported."""
|
"""Test if state is supported."""
|
||||||
|
if domain == climate.DOMAIN:
|
||||||
|
return features & climate.SUPPORT_ON_OFF != 0
|
||||||
return domain in (
|
return domain in (
|
||||||
group.DOMAIN,
|
group.DOMAIN,
|
||||||
input_boolean.DOMAIN,
|
input_boolean.DOMAIN,
|
||||||
|
@ -225,7 +225,10 @@ DEMO_DEVICES = [{
|
|||||||
'name': {
|
'name': {
|
||||||
'name': 'HeatPump'
|
'name': 'HeatPump'
|
||||||
},
|
},
|
||||||
'traits': ['action.devices.traits.TemperatureSetting'],
|
'traits': [
|
||||||
|
'action.devices.traits.OnOff',
|
||||||
|
'action.devices.traits.TemperatureSetting'
|
||||||
|
],
|
||||||
'type': 'action.devices.types.THERMOSTAT',
|
'type': 'action.devices.types.THERMOSTAT',
|
||||||
'willReportState': False
|
'willReportState': False
|
||||||
}, {
|
}, {
|
||||||
|
@ -204,6 +204,7 @@ def test_query_climate_request(hass_fixture, assistant_client, auth_header):
|
|||||||
devices = body['payload']['devices']
|
devices = body['payload']['devices']
|
||||||
assert len(devices) == 3
|
assert len(devices) == 3
|
||||||
assert devices['climate.heatpump'] == {
|
assert devices['climate.heatpump'] == {
|
||||||
|
'on': True,
|
||||||
'online': True,
|
'online': True,
|
||||||
'thermostatTemperatureSetpoint': 20.0,
|
'thermostatTemperatureSetpoint': 20.0,
|
||||||
'thermostatTemperatureAmbient': 25.0,
|
'thermostatTemperatureAmbient': 25.0,
|
||||||
@ -260,6 +261,7 @@ def test_query_climate_request_f(hass_fixture, assistant_client, auth_header):
|
|||||||
devices = body['payload']['devices']
|
devices = body['payload']['devices']
|
||||||
assert len(devices) == 3
|
assert len(devices) == 3
|
||||||
assert devices['climate.heatpump'] == {
|
assert devices['climate.heatpump'] == {
|
||||||
|
'on': True,
|
||||||
'online': True,
|
'online': True,
|
||||||
'thermostatTemperatureSetpoint': -6.7,
|
'thermostatTemperatureSetpoint': -6.7,
|
||||||
'thermostatTemperatureAmbient': -3.9,
|
'thermostatTemperatureAmbient': -3.9,
|
||||||
|
@ -388,6 +388,47 @@ async def test_onoff_media_player(hass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_onoff_climate(hass):
|
||||||
|
"""Test OnOff trait support for climate domain."""
|
||||||
|
assert trait.OnOffTrait.supported(climate.DOMAIN, climate.SUPPORT_ON_OFF)
|
||||||
|
|
||||||
|
trt_on = trait.OnOffTrait(hass, State('climate.bla', STATE_ON),
|
||||||
|
BASIC_CONFIG)
|
||||||
|
|
||||||
|
assert trt_on.sync_attributes() == {}
|
||||||
|
|
||||||
|
assert trt_on.query_attributes() == {
|
||||||
|
'on': True
|
||||||
|
}
|
||||||
|
|
||||||
|
trt_off = trait.OnOffTrait(hass, State('climate.bla', STATE_OFF),
|
||||||
|
BASIC_CONFIG)
|
||||||
|
|
||||||
|
assert trt_off.query_attributes() == {
|
||||||
|
'on': False
|
||||||
|
}
|
||||||
|
|
||||||
|
on_calls = async_mock_service(hass, climate.DOMAIN, SERVICE_TURN_ON)
|
||||||
|
await trt_on.execute(trait.COMMAND_ONOFF, {
|
||||||
|
'on': True
|
||||||
|
})
|
||||||
|
assert len(on_calls) == 1
|
||||||
|
assert on_calls[0].data == {
|
||||||
|
ATTR_ENTITY_ID: 'climate.bla',
|
||||||
|
}
|
||||||
|
|
||||||
|
off_calls = async_mock_service(hass, climate.DOMAIN,
|
||||||
|
SERVICE_TURN_OFF)
|
||||||
|
|
||||||
|
await trt_on.execute(trait.COMMAND_ONOFF, {
|
||||||
|
'on': False
|
||||||
|
})
|
||||||
|
assert len(off_calls) == 1
|
||||||
|
assert off_calls[0].data == {
|
||||||
|
ATTR_ENTITY_ID: 'climate.bla',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_dock_vacuum(hass):
|
async def test_dock_vacuum(hass):
|
||||||
"""Test dock trait support for vacuum domain."""
|
"""Test dock trait support for vacuum domain."""
|
||||||
assert trait.DockTrait.supported(vacuum.DOMAIN, 0)
|
assert trait.DockTrait.supported(vacuum.DOMAIN, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user