Add Google Report State (#27112)

* Add Google Report State

* UPDATE codeowners"

* Add config option for dev mode

* update library

* lint

* Bug fixes
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2019-10-03 13:02:38 +02:00
1 parent 3e99743244
commit f184bf4d85
26 files changed
+510 -56

No files matched your search

@@ -6,9 +6,15 @@ class MockConfig(helpers.AbstractConfig):
"""Fake config that always exposes everything."""
def __init__(
self, *, secure_devices_pin=None, should_expose=None, entity_config=None
self,
*,
secure_devices_pin=None,
should_expose=None,
entity_config=None,
hass=None,
):
"""Initialize config."""
super().__init__(hass)
self._should_expose = should_expose
self._secure_devices_pin = secure_devices_pin
self._entity_config = entity_config or {}
@@ -1,6 +1,7 @@
"""The tests for google-assistant init."""
import asyncio
from homeassistant.core import Context
from homeassistant.setup import async_setup_component
from homeassistant.components import google_assistant as ga
@@ -20,7 +21,10 @@ def test_request_sync_service(aioclient_mock, hass):
assert aioclient_mock.call_count == 0
yield from hass.services.async_call(
ga.const.DOMAIN, ga.const.SERVICE_REQUEST_SYNC, blocking=True
ga.const.DOMAIN,
ga.const.SERVICE_REQUEST_SYNC,
blocking=True,
context=Context(user_id="123"),
)
assert aioclient_mock.call_count == 1
@@ -0,0 +1,47 @@
"""Test Google report state."""
from unittest.mock import patch
from homeassistant.components.google_assistant.report_state import (
async_enable_report_state,
)
from . import BASIC_CONFIG
from tests.common import mock_coro
async def test_report_state(hass):
"""Test report state works."""
unsub = async_enable_report_state(hass, BASIC_CONFIG)
with patch.object(
BASIC_CONFIG, "async_report_state", side_effect=mock_coro
) as mock_report:
hass.states.async_set("light.kitchen", "on")
await hass.async_block_till_done()
assert len(mock_report.mock_calls) == 1
assert mock_report.mock_calls[0][1][0] == {
"devices": {"states": {"light.kitchen": {"on": True, "online": True}}}
}
# Test that state changes that change something that Google doesn't care about
# do not trigger a state report.
with patch.object(
BASIC_CONFIG, "async_report_state", side_effect=mock_coro
) as mock_report:
hass.states.async_set(
"light.kitchen", "on", {"irrelevant": "should_be_ignored"}
)
await hass.async_block_till_done()
assert len(mock_report.mock_calls) == 0
unsub()
with patch.object(
BASIC_CONFIG, "async_report_state", side_effect=mock_coro
) as mock_report:
hass.states.async_set("light.kitchen", "on")
await hass.async_block_till_done()
assert len(mock_report.mock_calls) == 0
@@ -657,14 +657,20 @@ async def test_device_media_player(hass, device_class, google_type):
async def test_query_disconnect(hass):
"""Test a disconnect message."""
result = await sh.async_handle_message(
hass,
BASIC_CONFIG,
"test-agent",
{"inputs": [{"intent": "action.devices.DISCONNECT"}], "requestId": REQ_ID},
)
config = MockConfig(hass=hass)
config.async_enable_report_state()
assert config._unsub_report_state is not None
with patch.object(
config, "async_deactivate_report_state", side_effect=mock_coro
) as mock_deactivate:
result = await sh.async_handle_message(
hass,
config,
"test-agent",
{"inputs": [{"intent": "action.devices.DISCONNECT"}], "requestId": REQ_ID},
)
assert result is None
assert len(mock_deactivate.mock_calls) == 1
async def test_trait_execute_adding_query_data(hass):