Delay sync for Google and limit updates to relevant info (#34622)
This commit is contained in:
1 parent
813e945d86
commit
d3bbd9ec65
5 files changed
+69
-21
No files matched your search
@@ -271,15 +271,25 @@ class AlexaConfig(alexa_config.AbstractConfig):
|
||||
if not self.enabled or not self._cloud.is_logged_in:
|
||||
return
|
||||
|
||||
action = event.data["action"]
|
||||
entity_id = event.data["entity_id"]
|
||||
|
||||
if not self.should_expose(entity_id):
|
||||
return
|
||||
|
||||
action = event.data["action"]
|
||||
to_update = []
|
||||
to_remove = []
|
||||
|
||||
if action == "create" and self.should_expose(entity_id):
|
||||
if action == "create":
|
||||
to_update.append(entity_id)
|
||||
elif action == "remove" and self.should_expose(entity_id):
|
||||
elif action == "remove":
|
||||
to_remove.append(entity_id)
|
||||
elif action == "update" and bool(
|
||||
set(event.data["changes"]) & entity_registry.ENTITY_DESCRIBING_ATTRIBUTES
|
||||
):
|
||||
to_update.append(entity_id)
|
||||
if "old_entity_id" in event.data:
|
||||
to_remove.append(event.data["old_entity_id"])
|
||||
|
||||
try:
|
||||
await self._sync_helper(to_update, to_remove)
|
||||
|
||||
@@ -33,12 +33,6 @@ class CloudGoogleConfig(AbstractConfig):
|
||||
self._cur_entity_prefs = self._prefs.google_entity_configs
|
||||
self._sync_entities_lock = asyncio.Lock()
|
||||
|
||||
prefs.async_listen_updates(self._async_prefs_updated)
|
||||
hass.bus.async_listen(
|
||||
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
self._handle_entity_registry_updated,
|
||||
)
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
"""Return if Google is enabled."""
|
||||
@@ -83,6 +77,13 @@ class CloudGoogleConfig(AbstractConfig):
|
||||
# Remove bad data that was there until 0.103.6 - Jan 6, 2020
|
||||
self._store.pop_agent_user_id(self._user)
|
||||
|
||||
self._prefs.async_listen_updates(self._async_prefs_updated)
|
||||
|
||||
self.hass.bus.async_listen(
|
||||
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
self._handle_entity_registry_updated,
|
||||
)
|
||||
|
||||
def should_expose(self, state):
|
||||
"""If a state object should be exposed."""
|
||||
return self._should_expose_entity_id(state.entity_id)
|
||||
@@ -160,8 +161,14 @@ class CloudGoogleConfig(AbstractConfig):
|
||||
if not self.enabled or not self._cloud.is_logged_in:
|
||||
return
|
||||
|
||||
# Only consider entity registry updates if info relevant for Google has changed
|
||||
if event.data["action"] == "update" and not bool(
|
||||
set(event.data["changes"]) & entity_registry.ENTITY_DESCRIBING_ATTRIBUTES
|
||||
):
|
||||
return
|
||||
|
||||
entity_id = event.data["entity_id"]
|
||||
|
||||
# Schedule a sync if a change was made to an entity that Google knows about
|
||||
if self._should_expose_entity_id(entity_id):
|
||||
await self.async_sync_entities_all()
|
||||
self.async_schedule_google_sync_all()
|
||||
Reference in new issue
Block a user