diff --git a/homeassistant/components/eufylife_ble/__init__.py b/homeassistant/components/eufylife_ble/__init__.py index f66cf7df30d..8a58c50c8e4 100644 --- a/homeassistant/components/eufylife_ble/__init__.py +++ b/homeassistant/components/eufylife_ble/__init__.py @@ -6,17 +6,15 @@ from eufylife_ble_client import EufyLifeBLEDevice from homeassistant.components import bluetooth from homeassistant.components.bluetooth.match import ADDRESS, BluetoothCallbackMatcher -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_MODEL, EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import Event, HomeAssistant, callback -from .const import DOMAIN -from .models import EufyLifeData +from .models import EufyLifeConfigEntry, EufyLifeData PLATFORMS: list[Platform] = [Platform.SENSOR] -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: EufyLifeConfigEntry) -> bool: """Set up EufyLife device from a config entry.""" address = entry.unique_id assert address is not None @@ -45,11 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) ) - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = EufyLifeData( - address, - model, - client, - ) + entry.runtime_data = EufyLifeData(address, model, client) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) @@ -63,9 +57,6 @@ 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: EufyLifeConfigEntry) -> 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/eufylife_ble/models.py b/homeassistant/components/eufylife_ble/models.py index eb937fc4f3d..26154a74fac 100644 --- a/homeassistant/components/eufylife_ble/models.py +++ b/homeassistant/components/eufylife_ble/models.py @@ -6,6 +6,10 @@ from dataclasses import dataclass from eufylife_ble_client import EufyLifeBLEDevice +from homeassistant.config_entries import ConfigEntry + +type EufyLifeConfigEntry = ConfigEntry[EufyLifeData] + @dataclass class EufyLifeData: diff --git a/homeassistant/components/eufylife_ble/sensor.py b/homeassistant/components/eufylife_ble/sensor.py index 5e3ae64aabf..d9cef45ce4d 100644 --- a/homeassistant/components/eufylife_ble/sensor.py +++ b/homeassistant/components/eufylife_ble/sensor.py @@ -6,7 +6,6 @@ from typing import Any from eufylife_ble_client import MODEL_TO_NAME -from homeassistant import config_entries from homeassistant.components.bluetooth import async_address_present from homeassistant.components.sensor import ( RestoreSensor, @@ -20,19 +19,18 @@ from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM -from .const import DOMAIN -from .models import EufyLifeData +from .models import EufyLifeConfigEntry, EufyLifeData IGNORED_STATES = {STATE_UNAVAILABLE, STATE_UNKNOWN} async def async_setup_entry( hass: HomeAssistant, - entry: config_entries.ConfigEntry, + entry: EufyLifeConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the EufyLife sensors.""" - data: EufyLifeData = hass.data[DOMAIN][entry.entry_id] + data = entry.runtime_data entities = [ EufyLifeWeightSensorEntity(data),