Add Google Assistant support for setting climate temperature and operation mode. (#10174)

Fixes #10025.
This commit is contained in:
Eitan Mosenkis authored and Paulus Schoutsen committed 2017-11-01 07:44:59 -07:00
1 parent fb34f94d9c
commit 4da8ec0a05
5 files changed
+120 -17

No files matched your search

@@ -202,4 +202,32 @@ DEMO_DEVICES = [{
'traits': ['action.devices.traits.Scene'],
'type': 'action.devices.types.SCENE',
'willReportState': False
}, {
'id': 'climate.hvac',
'name': {
'name': 'Hvac'
},
'traits': ['action.devices.traits.TemperatureSetting'],
'type': 'action.devices.types.THERMOSTAT',
'willReportState': False,
'attributes': {
'availableThermostatModes': 'heat,cool,off',
'thermostatTemperatureUnit': 'C',
},
}, {
'id': 'climate.heatpump',
'name': {
'name': 'HeatPump'
},
'traits': ['action.devices.traits.TemperatureSetting'],
'type': 'action.devices.types.THERMOSTAT',
'willReportState': False
}, {
'id': 'climate.ecobee',
'name': {
'name': 'Ecobee'
},
'traits': ['action.devices.traits.TemperatureSetting'],
'type': 'action.devices.types.THERMOSTAT',
'willReportState': False
}]
@@ -6,7 +6,7 @@ import pytest
from homeassistant import setup, const, core
from homeassistant.components import (
http, async_setup, light, cover, media_player, fan, switch
http, async_setup, light, cover, media_player, fan, switch, climate
)
from homeassistant.components import google_assistant as ga
from tests.common import get_test_instance_port
@@ -45,7 +45,7 @@ def assistant_client(loop, hass_fixture, test_client):
@pytest.fixture
def hass_fixture(loop, hass):
"""Setup a hass instance for these tests."""
"""Set up a hass instance for these tests."""
# We need to do this to get access to homeassistant/turn_(on,off)
loop.run_until_complete(async_setup(hass, {core.DOMAIN: {}}))
@@ -89,6 +89,13 @@ def hass_fixture(loop, hass):
}]
}))
loop.run_until_complete(
setup.async_setup_component(hass, climate.DOMAIN, {
'climate': [{
'platform': 'demo'
}]
}))
# Kitchen light is explicitly excluded from being exposed
ceiling_lights_entity = hass.states.get('light.ceiling_lights')
attrs = dict(ceiling_lights_entity.attributes)
@@ -142,15 +149,18 @@ def test_sync_request(hass_fixture, assistant_client):
body = yield from result.json()
assert body.get('requestId') == reqid
devices = body['payload']['devices']
# assert len(devices) == 4
assert len(devices) == len(DEMO_DEVICES)
# HACK this is kind of slow and lazy
for dev in devices:
for demo in DEMO_DEVICES:
if dev['id'] == demo['id']:
assert dev['name'] == demo['name']
assert set(dev['traits']) == set(demo['traits'])
assert dev['type'] == demo['type']
assert (
sorted([dev['id'] for dev in devices])
== sorted([dev['id'] for dev in DEMO_DEVICES]))
for dev, demo in zip(
sorted(devices, key=lambda d: d['id']),
sorted(DEMO_DEVICES, key=lambda d: d['id'])):
assert dev['name'] == demo['name']
assert set(dev['traits']) == set(demo['traits'])
assert dev['type'] == demo['type']
if 'attributes' in demo:
assert dev['attributes'] == demo['attributes']
@asyncio.coroutine
@@ -3,6 +3,7 @@
import asyncio
from homeassistant import const
from homeassistant.components import climate
from homeassistant.components import google_assistant as ga
DETERMINE_SERVICE_TESTS = [{ # Test light brightness
@@ -73,6 +74,34 @@ DETERMINE_SERVICE_TESTS = [{ # Test light brightness
const.SERVICE_VOLUME_SET,
{'entity_id': 'media_player.living_room', 'volume_level': 0.3}
),
}, { # Test climate temperature
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
'params': {'thermostatTemperatureSetpoint': 24.5},
'expected': (
climate.SERVICE_SET_TEMPERATURE,
{'entity_id': 'climate.living_room', 'temperature': 24.5}
),
}, { # Test climate temperature range
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE,
'params': {
'thermostatTemperatureSetpointHigh': 24.5,
'thermostatTemperatureSetpointLow': 20.5,
},
'expected': (
climate.SERVICE_SET_TEMPERATURE,
{'entity_id': 'climate.living_room',
'target_temp_high': 24.5, 'target_temp_low': 20.5}
),
}, { # Test climate operation mode
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_SET_MODE,
'params': {'thermostatMode': 'heat'},
'expected': (
climate.SERVICE_SET_OPERATION_MODE,
{'entity_id': 'climate.living_room', 'operation_mode': 'heat'}
),
}]