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