From c9cb96a600be46ce38757ff58fb258701005108c Mon Sep 17 00:00:00 2001 From: mib1185 Date: Sat, 9 May 2026 19:29:06 +0000 Subject: [PATCH 1/2] migrate to config entry runtime data --- .../components/thermobeacon/__init__.py | 30 +++++++++---------- .../components/thermobeacon/model.py | 8 +++++ .../components/thermobeacon/sensor.py | 12 ++------ 3 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 homeassistant/components/thermobeacon/model.py diff --git a/homeassistant/components/thermobeacon/__init__.py b/homeassistant/components/thermobeacon/__init__.py index 1ede394a70c862..42f67a3b025031 100644 --- a/homeassistant/components/thermobeacon/__init__.py +++ b/homeassistant/components/thermobeacon/__init__.py @@ -8,30 +8,29 @@ from homeassistant.components.bluetooth.passive_update_processor import ( PassiveBluetoothProcessorCoordinator, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from .const import DOMAIN +from .model import ThermoBeaconConfigEntry PLATFORMS: list[Platform] = [Platform.SENSOR] _LOGGER = logging.getLogger(__name__) -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry( + hass: HomeAssistant, entry: ThermoBeaconConfigEntry +) -> bool: """Set up ThermoBeacon BLE device from a config entry.""" address = entry.unique_id assert address is not None data = ThermoBeaconBluetoothDeviceData() - coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = ( - PassiveBluetoothProcessorCoordinator( - hass, - _LOGGER, - address=address, - mode=BluetoothScanningMode.PASSIVE, - update_method=data.update, - ) + entry.runtime_data = coordinator = PassiveBluetoothProcessorCoordinator( + hass, + _LOGGER, + address=address, + mode=BluetoothScanningMode.PASSIVE, + update_method=data.update, ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) entry.async_on_unload( @@ -40,9 +39,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry( + hass: HomeAssistant, entry: ThermoBeaconConfigEntry +) -> bool: """Unload a config entry.""" - if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): - hass.data[DOMAIN].pop(entry.entry_id) - - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/thermobeacon/model.py b/homeassistant/components/thermobeacon/model.py new file mode 100644 index 00000000000000..57513c02e52f9e --- /dev/null +++ b/homeassistant/components/thermobeacon/model.py @@ -0,0 +1,8 @@ +"""Models for the ThermoBeacon integration.""" + +from homeassistant.components.bluetooth.passive_update_processor import ( + PassiveBluetoothProcessorCoordinator, +) +from homeassistant.config_entries import ConfigEntry + +type ThermoBeaconConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator] diff --git a/homeassistant/components/thermobeacon/sensor.py b/homeassistant/components/thermobeacon/sensor.py index 9e61c0dd7507c4..f03715cc7138a7 100644 --- a/homeassistant/components/thermobeacon/sensor.py +++ b/homeassistant/components/thermobeacon/sensor.py @@ -6,11 +6,9 @@ Units, ) -from homeassistant import config_entries from homeassistant.components.bluetooth.passive_update_processor import ( PassiveBluetoothDataProcessor, PassiveBluetoothDataUpdate, - PassiveBluetoothProcessorCoordinator, PassiveBluetoothProcessorEntity, ) from homeassistant.components.sensor import ( @@ -30,8 +28,8 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info -from .const import DOMAIN from .device import device_key_to_bluetooth_entity_key +from .model import ThermoBeaconConfigEntry SENSOR_DESCRIPTIONS = { (ThermoBeaconSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( @@ -110,15 +108,11 @@ def sensor_update_to_bluetooth_data_update( async def async_setup_entry( hass: HomeAssistant, - entry: config_entries.ConfigEntry, + entry: ThermoBeaconConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up the ThermoBeacon BLE sensors.""" - # Uses legacy hass.data[DOMAIN] pattern - # pylint: disable-next=hass-use-runtime-data - coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][ - entry.entry_id - ] + coordinator = entry.runtime_data processor = PassiveBluetoothDataProcessor(sensor_update_to_bluetooth_data_update) entry.async_on_unload( processor.async_add_entities_listener( From e1b894e90f84326134b975df293c55f4af535fcc Mon Sep 17 00:00:00 2001 From: mib1185 Date: Sun, 10 May 2026 09:58:54 +0000 Subject: [PATCH 2/2] move ThermoBeaconConfigEntry into init module --- homeassistant/components/thermobeacon/__init__.py | 5 +++-- homeassistant/components/thermobeacon/model.py | 8 -------- homeassistant/components/thermobeacon/sensor.py | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 homeassistant/components/thermobeacon/model.py diff --git a/homeassistant/components/thermobeacon/__init__.py b/homeassistant/components/thermobeacon/__init__.py index 42f67a3b025031..7847a318df582f 100644 --- a/homeassistant/components/thermobeacon/__init__.py +++ b/homeassistant/components/thermobeacon/__init__.py @@ -8,15 +8,16 @@ from homeassistant.components.bluetooth.passive_update_processor import ( PassiveBluetoothProcessorCoordinator, ) +from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from .model import ThermoBeaconConfigEntry - PLATFORMS: list[Platform] = [Platform.SENSOR] _LOGGER = logging.getLogger(__name__) +type ThermoBeaconConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator] + async def async_setup_entry( hass: HomeAssistant, entry: ThermoBeaconConfigEntry diff --git a/homeassistant/components/thermobeacon/model.py b/homeassistant/components/thermobeacon/model.py deleted file mode 100644 index 57513c02e52f9e..00000000000000 --- a/homeassistant/components/thermobeacon/model.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Models for the ThermoBeacon integration.""" - -from homeassistant.components.bluetooth.passive_update_processor import ( - PassiveBluetoothProcessorCoordinator, -) -from homeassistant.config_entries import ConfigEntry - -type ThermoBeaconConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator] diff --git a/homeassistant/components/thermobeacon/sensor.py b/homeassistant/components/thermobeacon/sensor.py index f03715cc7138a7..9d77a2b3c5d0e8 100644 --- a/homeassistant/components/thermobeacon/sensor.py +++ b/homeassistant/components/thermobeacon/sensor.py @@ -28,8 +28,8 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info +from . import ThermoBeaconConfigEntry from .device import device_key_to_bluetooth_entity_key -from .model import ThermoBeaconConfigEntry SENSOR_DESCRIPTIONS = { (ThermoBeaconSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(