Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def sync_google(_):
"""Sync entities to Google."""
await self.async_sync_entities_all()

self._on_deinitialize.append(start.async_at_start(self.hass, sync_google))
self._on_deinitialize.append(start.async_at_started(self.hass, sync_google))
Comment thread
frenck marked this conversation as resolved.

@callback
def async_deinitialize(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions tests/components/cloud/test_google_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ async def test_sync_google_on_home_assistant_start(

hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
assert len(mock_sync.mock_calls) == 0

hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
assert len(mock_sync.mock_calls) == 1


Expand Down
27 changes: 25 additions & 2 deletions tests/components/google_assistant/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
_get_homegraph_token,
async_get_users,
)
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.core import HomeAssistant, State
from homeassistant.const import (
CLOUD_NEVER_EXPOSED_ENTITIES,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STARTED,
)
from homeassistant.core import CoreState, HomeAssistant, State
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -78,6 +82,25 @@
}


async def test_sync_google_does_not_block_startup(hass: HomeAssistant) -> None:
"""Test that Google entity sync runs after startup, not during."""
hass.set_state(CoreState.not_running)
config = GoogleConfig(hass, DUMMY_CONFIG)

with patch.object(config, "async_sync_entities_all") as mock_sync:
await config.async_initialize()

# Fire EVENT_HOMEASSISTANT_START - sync should NOT run yet
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
mock_sync.assert_not_called()

# Fire EVENT_HOMEASSISTANT_STARTED - now sync should run
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
mock_sync.assert_called_once()


async def test_get_jwt(hass: HomeAssistant) -> None:
"""Test signing of key."""

Expand Down