Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make matter import in google_assistant late to avoid blocking the event loop #111335

Merged
merged 1 commit into from
Feb 25, 2024
Merged
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
23 changes: 13 additions & 10 deletions homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from awesomeversion import AwesomeVersion
from yarl import URL

from homeassistant.components import matter, webhook
from homeassistant.components import webhook
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_SUPPORTED_FEATURES,
Expand Down Expand Up @@ -644,16 +644,19 @@ def sync_serialize(self, agent_user_id, instance_uuid):
return device

# Add Matter info
if (
"matter" in self.hass.config.components
and any(x for x in device_entry.identifiers if x[0] == "matter")
and (
matter_info := matter.get_matter_device_info(self.hass, device_entry.id)
)
if "matter" in self.hass.config.components and any(
x for x in device_entry.identifiers if x[0] == "matter"
):
device["matterUniqueId"] = matter_info["unique_id"]
device["matterOriginalVendorId"] = matter_info["vendor_id"]
device["matterOriginalProductId"] = matter_info["product_id"]
# pylint: disable-next=import-outside-toplevel
from homeassistant.components.matter import get_matter_device_info

# Import matter can block the event loop for multiple seconds
# so we import it here to avoid blocking the event loop during
# setup since google_assistant is imported from cloud.
if matter_info := get_matter_device_info(self.hass, device_entry.id):
device["matterUniqueId"] = matter_info["unique_id"]
device["matterOriginalVendorId"] = matter_info["vendor_id"]
device["matterOriginalProductId"] = matter_info["product_id"]

# Add deviceInfo
device_info = {}
Expand Down
Loading