mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
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:
committed by
Pascal Vizeli
parent
3e99743244
commit
f184bf4d85
121
tests/components/cloud/test_google_config.py
Normal file
121
tests/components/cloud/test_google_config.py
Normal file
@@ -0,0 +1,121 @@
|
||||
"""Test the Cloud Google Config."""
|
||||
from unittest.mock import patch, Mock
|
||||
|
||||
from homeassistant.components.google_assistant import helpers as ga_helpers
|
||||
from homeassistant.components.cloud import GACTIONS_SCHEMA
|
||||
from homeassistant.components.cloud.google_config import CloudGoogleConfig
|
||||
from homeassistant.util.dt import utcnow
|
||||
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
|
||||
|
||||
from tests.common import mock_coro, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_google_update_report_state(hass, cloud_prefs):
|
||||
"""Test Google config responds to updating preference."""
|
||||
config = CloudGoogleConfig(hass, GACTIONS_SCHEMA({}), cloud_prefs, None)
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch(
|
||||
"homeassistant.components.google_assistant.report_state.async_enable_report_state"
|
||||
) as mock_report_state:
|
||||
await cloud_prefs.async_update(google_report_state=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
assert len(mock_report_state.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_sync_entities(aioclient_mock, hass, cloud_prefs):
|
||||
"""Test sync devices."""
|
||||
aioclient_mock.post("http://example.com", status=404)
|
||||
config = CloudGoogleConfig(
|
||||
hass,
|
||||
GACTIONS_SCHEMA({}),
|
||||
cloud_prefs,
|
||||
Mock(
|
||||
google_actions_sync_url="http://example.com",
|
||||
auth=Mock(async_check_token=Mock(side_effect=mock_coro)),
|
||||
),
|
||||
)
|
||||
|
||||
assert await config.async_sync_entities() == 404
|
||||
|
||||
|
||||
async def test_google_update_expose_trigger_sync(hass, cloud_prefs):
|
||||
"""Test Google config responds to updating exposed entities."""
|
||||
config = CloudGoogleConfig(hass, GACTIONS_SCHEMA({}), cloud_prefs, None)
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
|
||||
await cloud_prefs.async_update_google_entity_config(
|
||||
entity_id="light.kitchen", should_expose=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, utcnow())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
|
||||
await cloud_prefs.async_update_google_entity_config(
|
||||
entity_id="light.kitchen", should_expose=False
|
||||
)
|
||||
await cloud_prefs.async_update_google_entity_config(
|
||||
entity_id="binary_sensor.door", should_expose=True
|
||||
)
|
||||
await cloud_prefs.async_update_google_entity_config(
|
||||
entity_id="sensor.temp", should_expose=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, utcnow())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_google_entity_registry_sync(hass, mock_cloud_login, cloud_prefs):
|
||||
"""Test Google config responds to entity registry."""
|
||||
config = CloudGoogleConfig(
|
||||
hass, GACTIONS_SCHEMA({}), cloud_prefs, hass.data["cloud"]
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{"action": "create", "entity_id": "light.kitchen"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{"action": "remove", "entity_id": "light.kitchen"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
|
||||
with patch.object(
|
||||
config, "async_sync_entities", side_effect=mock_coro
|
||||
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{
|
||||
"action": "update",
|
||||
"entity_id": "light.kitchen",
|
||||
"changes": ["entity_id"],
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_sync.mock_calls) == 1
|
||||
Reference in New Issue
Block a user