From ed1cba02aed8c5df7cf19cebadd07a3dca2658db Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Thu, 23 Apr 2026 13:03:08 +0200 Subject: [PATCH] Migrate Matter integration to use `runtime_data` (#168862) --- homeassistant/components/matter/__init__.py | 34 ++++++++----------- homeassistant/components/matter/adapter.py | 5 ++- .../components/matter/binary_sensor.py | 7 ++-- homeassistant/components/matter/button.py | 7 ++-- homeassistant/components/matter/climate.py | 7 ++-- homeassistant/components/matter/cover.py | 7 ++-- .../components/matter/diagnostics.py | 7 ++-- homeassistant/components/matter/event.py | 7 ++-- homeassistant/components/matter/fan.py | 7 ++-- homeassistant/components/matter/helpers.py | 10 +++--- homeassistant/components/matter/light.py | 7 ++-- homeassistant/components/matter/lock.py | 7 ++-- homeassistant/components/matter/number.py | 7 ++-- homeassistant/components/matter/select.py | 7 ++-- homeassistant/components/matter/sensor.py | 7 ++-- homeassistant/components/matter/switch.py | 7 ++-- homeassistant/components/matter/update.py | 7 ++-- homeassistant/components/matter/vacuum.py | 7 ++-- homeassistant/components/matter/valve.py | 7 ++-- .../components/matter/water_heater.py | 7 ++-- 20 files changed, 74 insertions(+), 94 deletions(-) diff --git a/homeassistant/components/matter/__init__.py b/homeassistant/components/matter/__init__.py index fae9308e812f..e3698efc7bd3 100644 --- a/homeassistant/components/matter/__init__.py +++ b/homeassistant/components/matter/__init__.py @@ -1,5 +1,4 @@ """The Matter integration.""" -# pylint: disable=hass-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern from __future__ import annotations @@ -17,7 +16,7 @@ from matter_server.client.exceptions import ( from matter_server.common.errors import MatterError, NodeNotExists from homeassistant.components.hassio import AddonError, AddonManager, AddonState -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_URL, EVENT_HOMEASSISTANT_STOP from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady @@ -36,6 +35,7 @@ from .api import async_register_api from .const import CONF_INTEGRATION_CREATED_ADDON, CONF_USE_ADDON, DOMAIN, LOGGER from .discovery import SUPPORTED_PLATFORMS from .helpers import ( + MatterConfigEntry, MatterEntryData, get_matter, get_node_from_device_entry, @@ -56,8 +56,7 @@ def get_matter_device_info( hass: HomeAssistant, device_id: str ) -> MatterDeviceInfo | None: """Return Matter device info or None if device does not exist.""" - # Test hass.data[DOMAIN] to ensure config entry is set up - if not hass.data.get(DOMAIN, False) or not ( + if not hass.config_entries.async_loaded_entries(DOMAIN) or not ( node := node_from_ha_device_id(hass, device_id) ): return None @@ -75,7 +74,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: MatterConfigEntry) -> bool: """Set up Matter from a config entry.""" if use_addon := entry.data.get(CONF_USE_ADDON): await _async_ensure_addon_running(hass, entry) @@ -153,13 +152,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: listen_task.cancel() raise ConfigEntryNotReady("Failed to set default fabric label") from err - if DOMAIN not in hass.data: - hass.data[DOMAIN] = {} - # create an intermediate layer (adapter) which keeps track of the nodes # and discovery of platform entities from the node attributes matter = MatterAdapter(hass, matter_client, entry) - hass.data[DOMAIN][entry.entry_id] = MatterEntryData(matter, listen_task) + entry.runtime_data = MatterEntryData(matter, listen_task) await hass.config_entries.async_forward_entry_setups(entry, SUPPORTED_PLATFORMS) await matter.setup_nodes() @@ -167,7 +163,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # If the listen task is already failed, we need to raise ConfigEntryNotReady if listen_task.done() and (listen_error := listen_task.exception()) is not None: await hass.config_entries.async_unload_platforms(entry, SUPPORTED_PLATFORMS) - hass.data[DOMAIN].pop(entry.entry_id) try: await matter_client.disconnect() finally: @@ -178,7 +173,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def _client_listen( hass: HomeAssistant, - entry: ConfigEntry, + entry: MatterConfigEntry, matter_client: MatterClient, init_ready: asyncio.Event, ) -> None: @@ -200,16 +195,15 @@ async def _client_listen( hass.async_create_task(hass.config_entries.async_reload(entry.entry_id)) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: MatterConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms( entry, SUPPORTED_PLATFORMS ) if unload_ok: - matter_entry_data: MatterEntryData = hass.data[DOMAIN].pop(entry.entry_id) - matter_entry_data.listen_task.cancel() - await matter_entry_data.adapter.matter_client.disconnect() + entry.runtime_data.listen_task.cancel() + await entry.runtime_data.adapter.matter_client.disconnect() if entry.data.get(CONF_USE_ADDON) and entry.disabled_by: addon_manager: AddonManager = get_addon_manager(hass) @@ -223,7 +217,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def async_remove_entry(hass: HomeAssistant, entry: MatterConfigEntry) -> None: """Config entry is being removed.""" if not entry.data.get(CONF_INTEGRATION_CREATED_ADDON): @@ -247,7 +241,7 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: def _remove_via_devices( - hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry + hass: HomeAssistant, config_entry: MatterConfigEntry, device_entry: dr.DeviceEntry ) -> None: """Remove all via devices associated with a device.""" device_registry = dr.async_get(hass) @@ -260,7 +254,7 @@ def _remove_via_devices( async def async_remove_config_entry_device( - hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry + hass: HomeAssistant, config_entry: MatterConfigEntry, device_entry: dr.DeviceEntry ) -> bool: """Remove a config entry from a device.""" node = get_node_from_device_entry(hass, device_entry) @@ -289,7 +283,9 @@ async def async_remove_config_entry_device( return True -async def _async_ensure_addon_running(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def _async_ensure_addon_running( + hass: HomeAssistant, entry: MatterConfigEntry +) -> None: """Ensure that Matter Server add-on is installed and running.""" addon_manager = _get_addon_manager(hass) try: diff --git a/homeassistant/components/matter/adapter.py b/homeassistant/components/matter/adapter.py index dad780d9a872..c6ec4ece74b2 100644 --- a/homeassistant/components/matter/adapter.py +++ b/homeassistant/components/matter/adapter.py @@ -8,7 +8,6 @@ from chip.clusters import Objects as clusters from matter_server.client.models.device_types import BridgedNode from matter_server.common.models import EventType, ServerInfoMessage -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr @@ -16,7 +15,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, ID_TYPE_DEVICE_ID, ID_TYPE_SERIAL, LOGGER from .discovery import async_discover_entities -from .helpers import get_device_id +from .helpers import MatterConfigEntry, get_device_id if TYPE_CHECKING: from matter_server.client import MatterClient @@ -38,7 +37,7 @@ class MatterAdapter: self, hass: HomeAssistant, matter_client: MatterClient, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, ) -> None: """Initialize the adapter.""" self.matter_client = matter_client diff --git a/homeassistant/components/matter/binary_sensor.py b/homeassistant/components/matter/binary_sensor.py index 84ed60d580b8..3c7246a0569e 100644 --- a/homeassistant/components/matter/binary_sensor.py +++ b/homeassistant/components/matter/binary_sensor.py @@ -15,23 +15,22 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, BinarySensorEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter binary sensor from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.BINARY_SENSOR, async_add_entities) diff --git a/homeassistant/components/matter/button.py b/homeassistant/components/matter/button.py index 11a364622e34..5582356a244c 100644 --- a/homeassistant/components/matter/button.py +++ b/homeassistant/components/matter/button.py @@ -13,23 +13,22 @@ from homeassistant.components.button import ( ButtonEntity, ButtonEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter Button platform.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.BUTTON, async_add_entities) diff --git a/homeassistant/components/matter/climate.py b/homeassistant/components/matter/climate.py index 4b508a57954d..7eb8edb263da 100644 --- a/homeassistant/components/matter/climate.py +++ b/homeassistant/components/matter/climate.py @@ -26,13 +26,12 @@ from homeassistant.components.climate import ( HVACAction, HVACMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema HUMIDITY_SCALING_FACTOR = 100 @@ -194,11 +193,11 @@ class ThermostatRunningState(IntEnum): async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter climate platform from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.CLIMATE, async_add_entities) diff --git a/homeassistant/components/matter/cover.py b/homeassistant/components/matter/cover.py index 2d81577772a9..149e8709a650 100644 --- a/homeassistant/components/matter/cover.py +++ b/homeassistant/components/matter/cover.py @@ -17,14 +17,13 @@ from homeassistant.components.cover import ( CoverEntityDescription, CoverEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .const import LOGGER from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema # The MASK used for extracting bits 0 to 1 of the byte. @@ -54,11 +53,11 @@ class OperationalStatus(IntEnum): async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter Cover from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.COVER, async_add_entities) diff --git a/homeassistant/components/matter/diagnostics.py b/homeassistant/components/matter/diagnostics.py index 23b6854c791d..1388addffd14 100644 --- a/homeassistant/components/matter/diagnostics.py +++ b/homeassistant/components/matter/diagnostics.py @@ -9,11 +9,10 @@ from chip.clusters import Objects from matter_server.common.helpers.util import dataclass_to_dict, parse_attribute_path from homeassistant.components.diagnostics import REDACTED -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr -from .helpers import get_matter, get_node_from_device_entry +from .helpers import MatterConfigEntry, get_matter, get_node_from_device_entry ATTRIBUTES_TO_REDACT = {Objects.BasicInformation.Attributes.Location} @@ -41,7 +40,7 @@ def remove_serialization_type(data: dict[str, Any]) -> dict[str, Any]: async def async_get_config_entry_diagnostics( - hass: HomeAssistant, config_entry: ConfigEntry + hass: HomeAssistant, config_entry: MatterConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" matter = get_matter(hass) @@ -54,7 +53,7 @@ async def async_get_config_entry_diagnostics( async def async_get_device_diagnostics( - hass: HomeAssistant, config_entry: ConfigEntry, device: dr.DeviceEntry + hass: HomeAssistant, config_entry: MatterConfigEntry, device: dr.DeviceEntry ) -> dict[str, Any]: """Return diagnostics for a device.""" matter = get_matter(hass) diff --git a/homeassistant/components/matter/event.py b/homeassistant/components/matter/event.py index d840daad8ba9..a640440c53d3 100644 --- a/homeassistant/components/matter/event.py +++ b/homeassistant/components/matter/event.py @@ -14,13 +14,12 @@ from homeassistant.components.event import ( EventEntity, EventEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema SwitchFeature = clusters.Switch.Bitmaps.Feature @@ -39,11 +38,11 @@ EVENT_TYPES_MAP = { async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter switches from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.EVENT, async_add_entities) diff --git a/homeassistant/components/matter/fan.py b/homeassistant/components/matter/fan.py index 6195030a7405..59d4d6e9dd8e 100644 --- a/homeassistant/components/matter/fan.py +++ b/homeassistant/components/matter/fan.py @@ -14,13 +14,12 @@ from homeassistant.components.fan import ( FanEntityDescription, FanEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema FanControlFeature = clusters.FanControl.Bitmaps.Feature @@ -45,11 +44,11 @@ PRESET_SLEEP_WIND = "sleep_wind" async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter fan from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.FAN, async_add_entities) diff --git a/homeassistant/components/matter/helpers.py b/homeassistant/components/matter/helpers.py index 0bd6bd48c234..99a9454f1329 100644 --- a/homeassistant/components/matter/helpers.py +++ b/homeassistant/components/matter/helpers.py @@ -6,6 +6,7 @@ import asyncio from dataclasses import dataclass from typing import TYPE_CHECKING +from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry as dr @@ -31,16 +32,17 @@ class MatterEntryData: listen_task: asyncio.Task +type MatterConfigEntry = ConfigEntry[MatterEntryData] + + @callback def get_matter(hass: HomeAssistant) -> MatterAdapter: """Return MatterAdapter instance.""" # NOTE: This assumes only one Matter connection/fabric can exist. # Shall we support connecting to multiple servers in the client or by # config entries? In case of the config entry we need to fix this. - # Uses legacy hass.data[DOMAIN] pattern - # pylint: disable-next=hass-use-runtime-data - matter_entry_data: MatterEntryData = next(iter(hass.data[DOMAIN].values())) - return matter_entry_data.adapter + entries: list[MatterConfigEntry] = hass.config_entries.async_loaded_entries(DOMAIN) + return entries[0].runtime_data.adapter def get_operational_instance_id( diff --git a/homeassistant/components/matter/light.py b/homeassistant/components/matter/light.py index 599f34bc9f4f..3103bdc56308 100644 --- a/homeassistant/components/matter/light.py +++ b/homeassistant/components/matter/light.py @@ -23,7 +23,6 @@ from homeassistant.components.light import ( LightEntityFeature, filter_supported_color_modes, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -31,7 +30,7 @@ from homeassistant.util import color as color_util from .const import LOGGER from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema from .util import ( convert_to_hass_hs, @@ -86,11 +85,11 @@ TRANSITION_BLOCKLIST = ( async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter Light from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.LIGHT, async_add_entities) diff --git a/homeassistant/components/matter/lock.py b/homeassistant/components/matter/lock.py index 80316ea80148..be577f6c09e7 100644 --- a/homeassistant/components/matter/lock.py +++ b/homeassistant/components/matter/lock.py @@ -15,7 +15,6 @@ from homeassistant.components.lock import ( LockEntityDescription, LockEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_CODE, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError @@ -34,7 +33,7 @@ from .const import ( LOGGER, ) from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .lock_helpers import ( DoorLockFeature, GetLockCredentialStatusResult, @@ -70,11 +69,11 @@ DOOR_LOCK_OPERATION_SOURCE: dict[int, str] = { async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter lock from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.LOCK, async_add_entities) diff --git a/homeassistant/components/matter/number.py b/homeassistant/components/matter/number.py index 21be4cd90d15..bce75244d6d6 100644 --- a/homeassistant/components/matter/number.py +++ b/homeassistant/components/matter/number.py @@ -17,7 +17,6 @@ from homeassistant.components.number import ( NumberEntityDescription, NumberMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, EntityCategory, @@ -30,17 +29,17 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter Number Input from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.NUMBER, async_add_entities) diff --git a/homeassistant/components/matter/select.py b/homeassistant/components/matter/select.py index a0c87cc4974c..21ee86302b82 100644 --- a/homeassistant/components/matter/select.py +++ b/homeassistant/components/matter/select.py @@ -11,13 +11,12 @@ from chip.clusters.ClusterObjects import ClusterAttributeDescriptor, ClusterComm from chip.clusters.Types import Nullable from homeassistant.components.select import SelectEntity, SelectEntityDescription -from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema DOOR_LOCK_OPERATING_MODE_MAP = { @@ -66,11 +65,11 @@ type SelectCluster = ( async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter ModeSelect from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.SELECT, async_add_entities) diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index 36fdbc7d3f68..8708e7624561 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -23,7 +23,6 @@ from homeassistant.components.sensor import ( SensorEntityDescription, SensorStateClass, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_PARTS_PER_MILLION, @@ -50,7 +49,7 @@ from homeassistant.util import dt as dt_util, slugify from .const import CONCENTRATION_BECQUERELS_PER_CUBIC_METER from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema AIR_QUALITY_MAP = { @@ -225,11 +224,11 @@ def matter_epoch_microseconds_to_utc(x: int | None) -> datetime | None: async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter sensors from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.SENSOR, async_add_entities) diff --git a/homeassistant/components/matter/switch.py b/homeassistant/components/matter/switch.py index 8e19d3d13b68..dc6a6bbcb5d8 100644 --- a/homeassistant/components/matter/switch.py +++ b/homeassistant/components/matter/switch.py @@ -15,13 +15,12 @@ from homeassistant.components.switch import ( SwitchEntity, SwitchEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema EVSE_SUPPLY_STATE_MAP = { @@ -34,11 +33,11 @@ EVSE_SUPPLY_STATE_MAP = { async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter switches from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.SWITCH, async_add_entities) diff --git a/homeassistant/components/matter/update.py b/homeassistant/components/matter/update.py index 56d98f8b5b0f..eb817ba6ef86 100644 --- a/homeassistant/components/matter/update.py +++ b/homeassistant/components/matter/update.py @@ -17,7 +17,6 @@ from homeassistant.components.update import ( UpdateEntityDescription, UpdateEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_ON, Platform from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError @@ -26,7 +25,7 @@ from homeassistant.helpers.event import async_call_later from homeassistant.helpers.restore_state import ExtraStoredData from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema SCAN_INTERVAL = timedelta(hours=12) @@ -59,11 +58,11 @@ class MatterUpdateExtraStoredData(ExtraStoredData): async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter lock from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.UPDATE, async_add_entities) diff --git a/homeassistant/components/matter/vacuum.py b/homeassistant/components/matter/vacuum.py index 30fa8a7fde37..c3d7f31eaa83 100644 --- a/homeassistant/components/matter/vacuum.py +++ b/homeassistant/components/matter/vacuum.py @@ -17,14 +17,13 @@ from homeassistant.components.vacuum import ( VacuumActivity, VacuumEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema _LOGGER = logging.getLogger(__name__) @@ -55,11 +54,11 @@ class ModeTag(IntEnum): async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter vacuum platform from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.VACUUM, async_add_entities) diff --git a/homeassistant/components/matter/valve.py b/homeassistant/components/matter/valve.py index f2deea97d7fc..b6327d9d3931 100644 --- a/homeassistant/components/matter/valve.py +++ b/homeassistant/components/matter/valve.py @@ -13,13 +13,12 @@ from homeassistant.components.valve import ( ValveEntityDescription, ValveEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema ValveConfigurationAndControl = clusters.ValveConfigurationAndControl @@ -28,11 +27,11 @@ ValveStateEnum = ValveConfigurationAndControl.Enums.ValveStateEnum async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter valve platform from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.VALVE, async_add_entities) diff --git a/homeassistant/components/matter/water_heater.py b/homeassistant/components/matter/water_heater.py index 5f3c0ce3a95e..a6423c1d99a5 100644 --- a/homeassistant/components/matter/water_heater.py +++ b/homeassistant/components/matter/water_heater.py @@ -19,7 +19,6 @@ from homeassistant.components.water_heater import ( WaterHeaterEntityDescription, WaterHeaterEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_TEMPERATURE, PRECISION_WHOLE, @@ -31,7 +30,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MatterEntity, MatterEntityDescription -from .helpers import get_matter +from .helpers import MatterConfigEntry from .models import MatterDiscoverySchema TEMPERATURE_SCALING_FACTOR = 100 @@ -48,11 +47,11 @@ DEFAULT_BOOST_DURATION = 3600 # 1 hour async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: MatterConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up Matter WaterHeater platform from Config Entry.""" - matter = get_matter(hass) + matter = config_entry.runtime_data.adapter matter.register_platform_handler(Platform.WATER_HEATER, async_add_entities)