mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use runtime_data in eufylife_ble (#136705)
This commit is contained in:
parent
8b738c919c
commit
cd9abacdb2
@ -6,17 +6,15 @@ from eufylife_ble_client import EufyLifeBLEDevice
|
|||||||
|
|
||||||
from homeassistant.components import bluetooth
|
from homeassistant.components import bluetooth
|
||||||
from homeassistant.components.bluetooth.match import ADDRESS, BluetoothCallbackMatcher
|
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.const import CONF_MODEL, EVENT_HOMEASSISTANT_STOP, Platform
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .models import EufyLifeConfigEntry, EufyLifeData
|
||||||
from .models import EufyLifeData
|
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
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."""
|
"""Set up EufyLife device from a config entry."""
|
||||||
address = entry.unique_id
|
address = entry.unique_id
|
||||||
assert address is not None
|
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(
|
entry.runtime_data = EufyLifeData(address, model, client)
|
||||||
address,
|
|
||||||
model,
|
|
||||||
client,
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
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
|
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."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -6,6 +6,10 @@ from dataclasses import dataclass
|
|||||||
|
|
||||||
from eufylife_ble_client import EufyLifeBLEDevice
|
from eufylife_ble_client import EufyLifeBLEDevice
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
|
||||||
|
type EufyLifeConfigEntry = ConfigEntry[EufyLifeData]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EufyLifeData:
|
class EufyLifeData:
|
||||||
|
@ -6,7 +6,6 @@ from typing import Any
|
|||||||
|
|
||||||
from eufylife_ble_client import MODEL_TO_NAME
|
from eufylife_ble_client import MODEL_TO_NAME
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.components.bluetooth import async_address_present
|
from homeassistant.components.bluetooth import async_address_present
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
RestoreSensor,
|
RestoreSensor,
|
||||||
@ -20,19 +19,18 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .models import EufyLifeConfigEntry, EufyLifeData
|
||||||
from .models import EufyLifeData
|
|
||||||
|
|
||||||
IGNORED_STATES = {STATE_UNAVAILABLE, STATE_UNKNOWN}
|
IGNORED_STATES = {STATE_UNAVAILABLE, STATE_UNKNOWN}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: config_entries.ConfigEntry,
|
entry: EufyLifeConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the EufyLife sensors."""
|
"""Set up the EufyLife sensors."""
|
||||||
data: EufyLifeData = hass.data[DOMAIN][entry.entry_id]
|
data = entry.runtime_data
|
||||||
|
|
||||||
entities = [
|
entities = [
|
||||||
EufyLifeWeightSensorEntity(data),
|
EufyLifeWeightSensorEntity(data),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user