add support for color temperature and color to Google Assistant (#10039)

* add support for color temperature and color; also add some extra deviceInfo attributes

* change so that default behaviour doesn't turn off device if the action isn't handled

* add tests

* fix lint

* more lint

* use attributes were applicable

* removed debug logging

* fix unassigned if only None returned

* report more data in QUERY

* better tests for color and temperature

* fixes after dev merge

* remove deviceInfo as not part of a device state (PR #10399)

* fix after merge
This commit is contained in:
Per Osbäck authored and Paulus Schoutsen committed 2017-11-15 23:00:43 -08:00
1 parent f494c32866
commit d4bd4c114b
4 files changed
+154 -7

No files matched your search

@@ -181,6 +181,8 @@ def test_query_request(hass_fixture, assistant_client):
'id': "light.ceiling_lights",
}, {
'id': "light.bed_light",
}, {
'id': "light.kitchen_lights",
}]
}
}]
@@ -193,10 +195,12 @@ def test_query_request(hass_fixture, assistant_client):
body = yield from result.json()
assert body.get('requestId') == reqid
devices = body['payload']['devices']
assert len(devices) == 2
assert len(devices) == 3
assert devices['light.bed_light']['on'] is False
assert devices['light.ceiling_lights']['on'] is True
assert devices['light.ceiling_lights']['brightness'] == 70
assert devices['light.kitchen_lights']['color']['spectrumRGB'] == 16727919
assert devices['light.kitchen_lights']['color']['temperature'] == 4166
@asyncio.coroutine
@@ -321,6 +325,31 @@ def test_execute_request(hass_fixture, assistant_client):
"on": False
}
}]
}, {
"devices": [{
"id": "light.kitchen_lights",
}],
"execution": [{
"command": "action.devices.commands.ColorAbsolute",
"params": {
"color": {
"spectrumRGB": 16711680,
"temperature": 2100
}
}
}]
}, {
"devices": [{
"id": "light.kitchen_lights",
}],
"execution": [{
"command": "action.devices.commands.ColorAbsolute",
"params": {
"color": {
"spectrumRGB": 16711680
}
}
}]
}]
}
}]
@@ -333,7 +362,10 @@ def test_execute_request(hass_fixture, assistant_client):
body = yield from result.json()
assert body.get('requestId') == reqid
commands = body['payload']['commands']
assert len(commands) == 3
assert len(commands) == 5
ceiling = hass_fixture.states.get('light.ceiling_lights')
assert ceiling.state == 'off'
kitchen = hass_fixture.states.get('light.kitchen_lights')
assert kitchen.attributes.get(light.ATTR_COLOR_TEMP) == 476
assert kitchen.attributes.get(light.ATTR_RGB_COLOR) == (255, 0, 0)
assert hass_fixture.states.get('switch.decorative_lights').state == 'off'
@@ -17,6 +17,57 @@ DETERMINE_SERVICE_TESTS = [{ # Test light brightness
const.SERVICE_TURN_ON,
{'entity_id': 'light.test', 'brightness': 242}
)
}, { # Test light color temperature
'entity_id': 'light.test',
'command': ga.const.COMMAND_COLOR,
'params': {
'color': {
'temperature': 2300,
'name': 'warm white'
}
},
'expected': (
const.SERVICE_TURN_ON,
{'entity_id': 'light.test', 'kelvin': 2300}
)
}, { # Test light color blue
'entity_id': 'light.test',
'command': ga.const.COMMAND_COLOR,
'params': {
'color': {
'spectrumRGB': 255,
'name': 'blue'
}
},
'expected': (
const.SERVICE_TURN_ON,
{'entity_id': 'light.test', 'rgb_color': [0, 0, 255]}
)
}, { # Test light color yellow
'entity_id': 'light.test',
'command': ga.const.COMMAND_COLOR,
'params': {
'color': {
'spectrumRGB': 16776960,
'name': 'yellow'
}
},
'expected': (
const.SERVICE_TURN_ON,
{'entity_id': 'light.test', 'rgb_color': [255, 255, 0]}
)
}, { # Test unhandled action/service
'entity_id': 'light.test',
'command': ga.const.COMMAND_COLOR,
'params': {
'color': {
'unhandled': 2300
}
},
'expected': (
None,
{'entity_id': 'light.test'}
)
}, { # Test switch to light custom type
'entity_id': 'switch.decorative_lights',
'command': ga.const.COMMAND_ONOFF,