mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Explicitly pass in the config_entry in solarlog coordinator (#137939)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
d522af729a
commit
017af4fcf8
@ -2,18 +2,16 @@
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import CONF_HAS_PWD
|
||||
from .coordinator import SolarLogCoordinator
|
||||
from .coordinator import SolarlogConfigEntry, SolarLogCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
type SolarlogConfigEntry = ConfigEntry[SolarLogCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: SolarlogConfigEntry) -> bool:
|
||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
from urllib.parse import ParseResult, urlparse
|
||||
|
||||
from solarlog_cli.solarlog_connector import SolarLogConnector
|
||||
@ -16,6 +15,7 @@ from solarlog_cli.solarlog_exceptions import (
|
||||
)
|
||||
from solarlog_cli.solarlog_models import SolarlogData
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
@ -28,30 +28,35 @@ from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import SolarlogConfigEntry
|
||||
type SolarlogConfigEntry = ConfigEntry[SolarLogCoordinator]
|
||||
|
||||
|
||||
class SolarLogCoordinator(DataUpdateCoordinator[SolarlogData]):
|
||||
"""Get and update the latest data."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, entry: SolarlogConfigEntry) -> None:
|
||||
config_entry: SolarlogConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, config_entry: SolarlogConfigEntry) -> None:
|
||||
"""Initialize the data object."""
|
||||
super().__init__(
|
||||
hass, _LOGGER, name="SolarLog", update_interval=timedelta(seconds=60)
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name="SolarLog",
|
||||
update_interval=timedelta(seconds=60),
|
||||
)
|
||||
|
||||
self.new_device_callbacks: list[Callable[[int], None]] = []
|
||||
self._devices_last_update: set[tuple[int, str]] = set()
|
||||
|
||||
host_entry = entry.data[CONF_HOST]
|
||||
password = entry.data.get("password", "")
|
||||
host_entry = config_entry.data[CONF_HOST]
|
||||
password = config_entry.data.get("password", "")
|
||||
|
||||
url = urlparse(host_entry, "http")
|
||||
netloc = url.netloc or url.path
|
||||
path = url.path if url.netloc else ""
|
||||
url = ParseResult("http", netloc, path, *url[3:])
|
||||
self.unique_id = entry.entry_id
|
||||
self.unique_id = config_entry.entry_id
|
||||
self.host = url.geturl()
|
||||
|
||||
self.solarlog = SolarLogConnector(
|
||||
|
@ -8,7 +8,7 @@ from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import SolarlogConfigEntry
|
||||
from .coordinator import SolarlogConfigEntry
|
||||
|
||||
TO_REDACT = [
|
||||
CONF_HOST,
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import SolarlogConfigEntry
|
||||
from .coordinator import SolarlogConfigEntry
|
||||
from .entity import SolarLogCoordinatorEntity, SolarLogInverterEntity
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user