Use runtime_data in google_assistant (#144332)

This commit is contained in:
epenet 2025-05-06 15:20:18 +02:00 committed by GitHub
parent 313be7b30a
commit e2c02706a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 12 deletions

View File

@ -95,6 +95,8 @@ CONFIG_SCHEMA = vol.Schema(
{vol.Optional(DOMAIN): GOOGLE_ASSISTANT_SCHEMA}, extra=vol.ALLOW_EXTRA {vol.Optional(DOMAIN): GOOGLE_ASSISTANT_SCHEMA}, extra=vol.ALLOW_EXTRA
) )
type GoogleConfigEntry = ConfigEntry[GoogleConfig]
async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool: async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
"""Activate Google Actions component.""" """Activate Google Actions component."""
@ -115,7 +117,7 @@ async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
return True return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: GoogleConfigEntry) -> bool:
"""Set up from a config entry.""" """Set up from a config entry."""
config: ConfigType = {**hass.data[DOMAIN][DATA_CONFIG]} config: ConfigType = {**hass.data[DOMAIN][DATA_CONFIG]}
@ -141,7 +143,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
google_config = GoogleConfig(hass, config) google_config = GoogleConfig(hass, config)
await google_config.async_initialize() await google_config.async_initialize()
hass.data[DOMAIN][entry.entry_id] = google_config entry.runtime_data = google_config
hass.http.register_view(GoogleAssistantView(google_config)) hass.http.register_view(GoogleAssistantView(google_config))

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from homeassistant import config_entries
from homeassistant.components.button import ButtonEntity from homeassistant.components.button import ButtonEntity
from homeassistant.const import EntityCategory from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -11,18 +10,19 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from . import GoogleConfigEntry
from .const import CONF_PROJECT_ID, CONF_SERVICE_ACCOUNT, DATA_CONFIG, DOMAIN from .const import CONF_PROJECT_ID, CONF_SERVICE_ACCOUNT, DATA_CONFIG, DOMAIN
from .http import GoogleConfig from .http import GoogleConfig
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: config_entries.ConfigEntry, config_entry: GoogleConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback, async_add_entities: AddConfigEntryEntitiesCallback,
) -> None: ) -> None:
"""Set up the platform.""" """Set up the platform."""
yaml_config: ConfigType = hass.data[DOMAIN][DATA_CONFIG] yaml_config: ConfigType = hass.data[DOMAIN][DATA_CONFIG]
google_config: GoogleConfig = hass.data[DOMAIN][config_entry.entry_id] google_config = config_entry.runtime_data
entities = [] entities = []

View File

@ -5,13 +5,12 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.components.diagnostics import REDACTED, async_redact_data from homeassistant.components.diagnostics import REDACTED, async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from . import GoogleConfigEntry
from .const import CONF_SECURE_DEVICES_PIN, CONF_SERVICE_ACCOUNT, DATA_CONFIG, DOMAIN from .const import CONF_SECURE_DEVICES_PIN, CONF_SERVICE_ACCOUNT, DATA_CONFIG, DOMAIN
from .http import GoogleConfig
from .smart_home import ( from .smart_home import (
async_devices_query_response, async_devices_query_response,
async_devices_sync_response, async_devices_sync_response,
@ -29,12 +28,11 @@ TO_REDACT = [
async def async_get_config_entry_diagnostics( async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry hass: HomeAssistant, entry: GoogleConfigEntry
) -> dict[str, Any]: ) -> dict[str, Any]:
"""Return diagnostic information.""" """Return diagnostic information."""
data = hass.data[DOMAIN] config = entry.runtime_data
config: GoogleConfig = data[entry.entry_id] yaml_config: ConfigType = hass.data[DOMAIN][DATA_CONFIG]
yaml_config: ConfigType = data[DATA_CONFIG]
devices = await async_devices_sync_response(hass, config, REDACTED) devices = await async_devices_sync_response(hass, config, REDACTED)
sync = create_sync_response(REDACTED, devices) sync = create_sync_response(REDACTED, devices)
query = await async_devices_query_response(hass, config, devices) query = await async_devices_query_response(hass, config, devices)

View File

@ -29,7 +29,7 @@ async def test_sync_button(hass: HomeAssistant, hass_owner_user: MockUser) -> No
assert state assert state
config_entry = hass.config_entries.async_entries("google_assistant")[0] config_entry = hass.config_entries.async_entries("google_assistant")[0]
google_config: ga.GoogleConfig = hass.data[ga.DOMAIN][config_entry.entry_id] google_config: ga.GoogleConfig = config_entry.runtime_data
with patch.object(google_config, "async_sync_entities") as mock_sync_entities: with patch.object(google_config, "async_sync_entities") as mock_sync_entities:
mock_sync_entities.return_value = 200 mock_sync_entities.return_value = 200