Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 3 additions & 17 deletions homeassistant/components/cloud/google_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from hass_nabucasa.google_report_state import ErrorResponse

from homeassistant.components.google_assistant.helpers import AbstractConfig
from homeassistant.const import (
CLOUD_NEVER_EXPOSED_ENTITIES,
EVENT_HOMEASSISTANT_STARTED,
HTTP_OK,
)
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES, HTTP_OK
from homeassistant.core import CoreState, split_entity_id
from homeassistant.helpers import entity_registry

Expand Down Expand Up @@ -198,17 +194,7 @@ async def _handle_entity_registry_updated(self, event):
if not self._should_expose_entity_id(entity_id):
return

if self.hass.state == CoreState.running:
self.async_schedule_google_sync_all()
return

if self._sync_on_started:
if self.hass.state != CoreState.running:
return

self._sync_on_started = True

async def sync_google(_):
"""Sync entities to Google."""
await self.async_sync_entities_all()

self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, sync_google)
self.async_schedule_google_sync_all()
18 changes: 16 additions & 2 deletions homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
ATTR_SUPPORTED_FEATURES,
CLOUD_NEVER_EXPOSED_ENTITIES,
CONF_NAME,
EVENT_HOMEASSISTANT_START,
STATE_UNAVAILABLE,
)
from homeassistant.core import Context, HomeAssistant, State, callback
from homeassistant.core import Context, CoreState, HomeAssistant, State, callback
from homeassistant.helpers.area_registry import AreaEntry
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.entity_registry import RegistryEntry
Expand Down Expand Up @@ -104,6 +105,16 @@ async def async_initialize(self):
self._store = GoogleConfigStore(self.hass)
await self._store.async_load()

if self.hass.state == CoreState.running:
await self.async_sync_entities_all()
return

async def sync_google(_):
"""Sync entities to Google."""
await self.async_sync_entities_all()

self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, sync_google)

@property
def enabled(self):
"""Return if Google is enabled."""
Expand Down Expand Up @@ -193,7 +204,10 @@ async def async_sync_entities(self, agent_user_id: str):
"""Sync all entities to Google."""
# Remove any pending sync
self._google_sync_unsub.pop(agent_user_id, lambda: None)()
return await self._async_request_sync_devices(agent_user_id)
status = await self._async_request_sync_devices(agent_user_id)
if status == 404:
await self.async_disconnect_agent_user(agent_user_id)
return status

async def async_sync_entities_all(self):
"""Sync all entities to Google for all registered agents."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def should_2fa(self, state):

async def _async_request_sync_devices(self, agent_user_id: str):
if CONF_SERVICE_ACCOUNT in self._config:
await self.async_call_homegraph_api(
return await self.async_call_homegraph_api(
REQUEST_SYNC_BASE_URL, {"agentUserId": agent_user_id}
)
else:
Expand Down