Google Assistant for climate entities: Support QUERY and respect system-wide unit_system setting. (#10346)

This commit is contained in:
Eitan Mosenkis
2017-11-14 20:19:42 -08:00
committed by Paulus Schoutsen
parent 309e493e76
commit 0b4de54725
4 changed files with 176 additions and 24 deletions
@@ -11,6 +11,7 @@ from homeassistant import core, const, setup
from homeassistant.components import (
fan, http, cover, light, switch, climate, async_setup, media_player)
from homeassistant.components import google_assistant as ga
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
from . import DEMO_DEVICES
@@ -198,6 +199,101 @@ def test_query_request(hass_fixture, assistant_client):
assert devices['light.ceiling_lights']['brightness'] == 70
@asyncio.coroutine
def test_query_climate_request(hass_fixture, assistant_client):
"""Test a query request."""
reqid = '5711642932632160984'
data = {
'requestId':
reqid,
'inputs': [{
'intent': 'action.devices.QUERY',
'payload': {
'devices': [
{'id': 'climate.hvac'},
{'id': 'climate.heatpump'},
{'id': 'climate.ecobee'},
]
}
}]
}
result = yield from assistant_client.post(
ga.const.GOOGLE_ASSISTANT_API_ENDPOINT,
data=json.dumps(data),
headers=AUTH_HEADER)
assert result.status == 200
body = yield from result.json()
assert body.get('requestId') == reqid
devices = body['payload']['devices']
assert devices == {
'climate.heatpump': {
'thermostatTemperatureSetpoint': 20.0,
'thermostatTemperatureAmbient': 25.0,
'thermostatMode': 'heat',
},
'climate.ecobee': {
'thermostatTemperatureSetpointHigh': 24,
'thermostatTemperatureAmbient': 23,
'thermostatMode': 'on',
'thermostatTemperatureSetpointLow': 21
},
'climate.hvac': {
'thermostatTemperatureSetpoint': 21,
'thermostatTemperatureAmbient': 22,
'thermostatMode': 'cool',
'thermostatHumidityAmbient': 54,
}
}
@asyncio.coroutine
def test_query_climate_request_f(hass_fixture, assistant_client):
"""Test a query request."""
hass_fixture.config.units = IMPERIAL_SYSTEM
reqid = '5711642932632160984'
data = {
'requestId':
reqid,
'inputs': [{
'intent': 'action.devices.QUERY',
'payload': {
'devices': [
{'id': 'climate.hvac'},
{'id': 'climate.heatpump'},
{'id': 'climate.ecobee'},
]
}
}]
}
result = yield from assistant_client.post(
ga.const.GOOGLE_ASSISTANT_API_ENDPOINT,
data=json.dumps(data),
headers=AUTH_HEADER)
assert result.status == 200
body = yield from result.json()
assert body.get('requestId') == reqid
devices = body['payload']['devices']
assert devices == {
'climate.heatpump': {
'thermostatTemperatureSetpoint': -6.7,
'thermostatTemperatureAmbient': -3.9,
'thermostatMode': 'heat',
},
'climate.ecobee': {
'thermostatTemperatureSetpointHigh': -4.4,
'thermostatTemperatureAmbient': -5,
'thermostatMode': 'on',
'thermostatTemperatureSetpointLow': -6.1,
},
'climate.hvac': {
'thermostatTemperatureSetpoint': -6.1,
'thermostatTemperatureAmbient': -5.6,
'thermostatMode': 'cool',
'thermostatHumidityAmbient': 54,
}
}
@asyncio.coroutine
def test_execute_request(hass_fixture, assistant_client):
"""Test a execute request."""
@@ -5,6 +5,7 @@ import asyncio
from homeassistant import const
from homeassistant.components import climate
from homeassistant.components import google_assistant as ga
from homeassistant.util.unit_system import (IMPERIAL_SYSTEM, METRIC_SYSTEM)
DETERMINE_SERVICE_TESTS = [{ # Test light brightness
'entity_id': 'light.test',
@@ -82,6 +83,15 @@ DETERMINE_SERVICE_TESTS = [{ # Test light brightness
climate.SERVICE_SET_TEMPERATURE,
{'entity_id': 'climate.living_room', 'temperature': 24.5}
),
}, { # Test climate temperature Fahrenheit
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
'params': {'thermostatTemperatureSetpoint': 24.5},
'units': IMPERIAL_SYSTEM,
'expected': (
climate.SERVICE_SET_TEMPERATURE,
{'entity_id': 'climate.living_room', 'temperature': 76.1}
),
}, { # Test climate temperature range
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE,
@@ -94,6 +104,19 @@ DETERMINE_SERVICE_TESTS = [{ # Test light brightness
{'entity_id': 'climate.living_room',
'target_temp_high': 24.5, 'target_temp_low': 20.5}
),
}, { # Test climate temperature range Fahrenheit
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE,
'params': {
'thermostatTemperatureSetpointHigh': 24.5,
'thermostatTemperatureSetpointLow': 20.5,
},
'units': IMPERIAL_SYSTEM,
'expected': (
climate.SERVICE_SET_TEMPERATURE,
{'entity_id': 'climate.living_room',
'target_temp_high': 76.1, 'target_temp_low': 68.9}
),
}, { # Test climate operation mode
'entity_id': 'climate.living_room',
'command': ga.const.COMMAND_THERMOSTAT_SET_MODE,
@@ -122,5 +145,6 @@ def test_determine_service():
result = ga.smart_home.determine_service(
test['entity_id'],
test['command'],
test['params'])
test['params'],
test.get('units', METRIC_SYSTEM))
assert result == test['expected']