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 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
|
import logging
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .const import CONF_HAS_PWD
|
from .const import CONF_HAS_PWD
|
||||||
from .coordinator import SolarLogCoordinator
|
from .coordinator import SolarlogConfigEntry, SolarLogCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
type SolarlogConfigEntry = ConfigEntry[SolarLogCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: SolarlogConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: SolarlogConfigEntry) -> bool:
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
from urllib.parse import ParseResult, urlparse
|
from urllib.parse import ParseResult, urlparse
|
||||||
|
|
||||||
from solarlog_cli.solarlog_connector import SolarLogConnector
|
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 solarlog_cli.solarlog_models import SolarlogData
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -28,30 +28,35 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
type SolarlogConfigEntry = ConfigEntry[SolarLogCoordinator]
|
||||||
from . import SolarlogConfigEntry
|
|
||||||
|
|
||||||
|
|
||||||
class SolarLogCoordinator(DataUpdateCoordinator[SolarlogData]):
|
class SolarLogCoordinator(DataUpdateCoordinator[SolarlogData]):
|
||||||
"""Get and update the latest data."""
|
"""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."""
|
"""Initialize the data object."""
|
||||||
super().__init__(
|
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.new_device_callbacks: list[Callable[[int], None]] = []
|
||||||
self._devices_last_update: set[tuple[int, str]] = set()
|
self._devices_last_update: set[tuple[int, str]] = set()
|
||||||
|
|
||||||
host_entry = entry.data[CONF_HOST]
|
host_entry = config_entry.data[CONF_HOST]
|
||||||
password = entry.data.get("password", "")
|
password = config_entry.data.get("password", "")
|
||||||
|
|
||||||
url = urlparse(host_entry, "http")
|
url = urlparse(host_entry, "http")
|
||||||
netloc = url.netloc or url.path
|
netloc = url.netloc or url.path
|
||||||
path = url.path if url.netloc else ""
|
path = url.path if url.netloc else ""
|
||||||
url = ParseResult("http", netloc, path, *url[3:])
|
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.host = url.geturl()
|
||||||
|
|
||||||
self.solarlog = SolarLogConnector(
|
self.solarlog = SolarLogConnector(
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.components.diagnostics import async_redact_data
|
|||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import SolarlogConfigEntry
|
from .coordinator import SolarlogConfigEntry
|
||||||
|
|
||||||
TO_REDACT = [
|
TO_REDACT = [
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
|
@ -24,7 +24,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import SolarlogConfigEntry
|
from .coordinator import SolarlogConfigEntry
|
||||||
from .entity import SolarLogCoordinatorEntity, SolarLogInverterEntity
|
from .entity import SolarLogCoordinatorEntity, SolarLogInverterEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user