Add Home Assistant Started event (#34657)

This commit is contained in:
Paulus Schoutsen committed 2020-04-24 14:20:55 -07:00
1 parent f3f2aa807b
commit 214d6f5cf5
8 files changed
+68 -25

No files matched your search

+25 -11
View File
@@ -6,7 +6,8 @@ from asynctest import patch
from homeassistant.components.cloud import GACTIONS_SCHEMA
from homeassistant.components.cloud.google_config import CloudGoogleConfig
from homeassistant.components.google_assistant import helpers as ga_helpers
from homeassistant.const import HTTP_NOT_FOUND
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, HTTP_NOT_FOUND
from homeassistant.core import CoreState
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.util.dt import utcnow
@@ -25,9 +26,7 @@ async def test_google_update_report_state(hass, cloud_prefs):
await config.async_initialize()
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_sync_entities", side_effect=mock_coro
) as mock_sync, patch(
with patch.object(config, "async_sync_entities") 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)
@@ -67,9 +66,9 @@ async def test_google_update_expose_trigger_sync(hass, cloud_prefs):
await config.async_initialize()
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_sync_entities", side_effect=mock_coro
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
with patch.object(config, "async_sync_entities") 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
)
@@ -79,9 +78,9 @@ async def test_google_update_expose_trigger_sync(hass, cloud_prefs):
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):
with patch.object(config, "async_sync_entities") 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
)
@@ -107,7 +106,7 @@ async def test_google_entity_registry_sync(hass, mock_cloud_login, cloud_prefs):
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_schedule_google_sync_all", side_effect=mock_coro
config, "async_schedule_google_sync_all"
) as mock_sync, patch.object(ga_helpers, "SYNC_DELAY", 0):
# Created entity
hass.bus.async_fire(
@@ -148,3 +147,18 @@ async def test_google_entity_registry_sync(hass, mock_cloud_login, cloud_prefs):
await hass.async_block_till_done()
assert len(mock_sync.mock_calls) == 3
# When hass is not started yet we wait till started
hass.state = CoreState.starting
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) == 3
with patch.object(config, "async_sync_entities_all") as mock_sync:
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
assert len(mock_sync.mock_calls) == 1