mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Use runtime_data in rainforest_eagle integration (#167652)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,29 +2,27 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import EagleDataCoordinator
|
||||
from .coordinator import EagleDataCoordinator, RainforestEagleConfigEntry
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: RainforestEagleConfigEntry
|
||||
) -> bool:
|
||||
"""Set up Rainforest Eagle from a config entry."""
|
||||
coordinator = EagleDataCoordinator(hass, entry)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, entry: RainforestEagleConfigEntry
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
@@ -23,17 +23,21 @@ from .const import (
|
||||
)
|
||||
from .data import UPDATE_100_ERRORS
|
||||
|
||||
type RainforestEagleConfigEntry = ConfigEntry[EagleDataCoordinator]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EagleDataCoordinator(DataUpdateCoordinator):
|
||||
"""Get the latest data from the Eagle device."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: RainforestEagleConfigEntry
|
||||
eagle100_reader: Eagle100Reader | None = None
|
||||
eagle200_meter: aioeagle.ElectricMeter | None = None
|
||||
|
||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: RainforestEagleConfigEntry
|
||||
) -> None:
|
||||
"""Initialize the data object."""
|
||||
if config_entry.data[CONF_TYPE] == TYPE_EAGLE_100:
|
||||
self.model = "EAGLE-100"
|
||||
|
||||
@@ -5,22 +5,19 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_CLOUD_ID, CONF_INSTALL_CODE, DOMAIN
|
||||
from .coordinator import EagleDataCoordinator
|
||||
from .const import CONF_CLOUD_ID, CONF_INSTALL_CODE
|
||||
from .coordinator import RainforestEagleConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_CLOUD_ID, CONF_INSTALL_CODE}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
hass: HomeAssistant, config_entry: RainforestEagleConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: EagleDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
|
||||
"data": coordinator.data,
|
||||
"data": config_entry.runtime_data.data,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfEnergy, UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
@@ -17,7 +16,7 @@ from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import EagleDataCoordinator
|
||||
from .coordinator import EagleDataCoordinator, RainforestEagleConfigEntry
|
||||
|
||||
SENSORS = (
|
||||
SensorEntityDescription(
|
||||
@@ -46,11 +45,11 @@ SENSORS = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: RainforestEagleConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up a config entry."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
entities = [EagleSensor(coordinator, description) for description in SENSORS]
|
||||
|
||||
if coordinator.data.get("zigbee:Price") not in (None, "invalid"):
|
||||
|
||||
Reference in New Issue
Block a user