mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Explicitly pass in the config_entry in p1_monitor coordinator (#138045)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
0e4db4265a
commit
d0e2a9e0bf
@ -2,23 +2,20 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import LOGGER
|
||||
from .coordinator import P1MonitorDataUpdateCoordinator
|
||||
from .coordinator import P1MonitorConfigEntry, P1MonitorDataUpdateCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||
|
||||
type P1MonitorConfigEntry = ConfigEntry[P1MonitorDataUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: P1MonitorConfigEntry) -> bool:
|
||||
"""Set up P1 Monitor from a config entry."""
|
||||
|
||||
coordinator = P1MonitorDataUpdateCoordinator(hass)
|
||||
coordinator = P1MonitorDataUpdateCoordinator(hass, entry)
|
||||
try:
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
except ConfigEntryNotReady:
|
||||
@ -31,7 +28,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_migrate_entry(
|
||||
hass: HomeAssistant, config_entry: P1MonitorConfigEntry
|
||||
) -> bool:
|
||||
"""Migrate old entry."""
|
||||
LOGGER.debug("Migrating from version %s", config_entry.version)
|
||||
|
||||
@ -54,6 +53,6 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: P1MonitorConfigEntry) -> bool:
|
||||
"""Unload P1 Monitor config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -30,6 +30,8 @@ from .const import (
|
||||
SERVICE_WATERMETER,
|
||||
)
|
||||
|
||||
type P1MonitorConfigEntry = ConfigEntry[P1MonitorDataUpdateCoordinator]
|
||||
|
||||
|
||||
class P1MonitorData(TypedDict):
|
||||
"""Class for defining data in dict."""
|
||||
@ -43,17 +45,19 @@ class P1MonitorData(TypedDict):
|
||||
class P1MonitorDataUpdateCoordinator(DataUpdateCoordinator[P1MonitorData]):
|
||||
"""Class to manage fetching P1 Monitor data from single endpoint."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: P1MonitorConfigEntry
|
||||
has_water_meter: bool | None = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: P1MonitorConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize global P1 Monitor data updater."""
|
||||
super().__init__(
|
||||
hass,
|
||||
LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
|
@ -6,7 +6,6 @@ from dataclasses import asdict
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -16,6 +15,7 @@ from .const import (
|
||||
SERVICE_SMARTMETER,
|
||||
SERVICE_WATERMETER,
|
||||
)
|
||||
from .coordinator import P1MonitorConfigEntry
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from _typeshed import DataclassInstance
|
||||
@ -24,7 +24,7 @@ TO_REDACT = {CONF_HOST, CONF_PORT}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: P1MonitorConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = {
|
||||
|
@ -10,7 +10,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CURRENCY_EURO,
|
||||
@ -33,7 +32,7 @@ from .const import (
|
||||
SERVICE_SMARTMETER,
|
||||
SERVICE_WATERMETER,
|
||||
)
|
||||
from .coordinator import P1MonitorDataUpdateCoordinator
|
||||
from .coordinator import P1MonitorConfigEntry, P1MonitorDataUpdateCoordinator
|
||||
|
||||
SENSORS_SMARTMETER: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
@ -236,7 +235,9 @@ SENSORS_WATERMETER: tuple[SensorEntityDescription, ...] = (
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: P1MonitorConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up P1 Monitor Sensors based on a config entry."""
|
||||
entities: list[P1MonitorSensorEntity] = []
|
||||
@ -290,7 +291,7 @@ class P1MonitorSensorEntity(
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
entry: ConfigEntry,
|
||||
entry: P1MonitorConfigEntry,
|
||||
description: SensorEntityDescription,
|
||||
name: str,
|
||||
service: Literal["smartmeter", "watermeter", "phases", "settings"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user