mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Explicitly pass in the config_entry in solaredge coordinator (#137941)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
beb5c3b838
commit
12072b625c
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from aiosolaredge import SolarEdge
|
from aiosolaredge import SolarEdge
|
||||||
from stringcase import snakecase
|
from stringcase import snakecase
|
||||||
@ -21,13 +21,22 @@ from .const import (
|
|||||||
POWER_FLOW_UPDATE_DELAY,
|
POWER_FLOW_UPDATE_DELAY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .types import SolarEdgeConfigEntry
|
||||||
|
|
||||||
|
|
||||||
class SolarEdgeDataService(ABC):
|
class SolarEdgeDataService(ABC):
|
||||||
"""Get and update the latest data."""
|
"""Get and update the latest data."""
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator[None]
|
coordinator: DataUpdateCoordinator[None]
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: SolarEdge, site_id: str) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SolarEdgeConfigEntry,
|
||||||
|
api: SolarEdge,
|
||||||
|
site_id: str,
|
||||||
|
) -> None:
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.api = api
|
self.api = api
|
||||||
self.site_id = site_id
|
self.site_id = site_id
|
||||||
@ -36,6 +45,7 @@ class SolarEdgeDataService(ABC):
|
|||||||
self.attributes: dict[str, Any] = {}
|
self.attributes: dict[str, Any] = {}
|
||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
self.config_entry = config_entry
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_setup(self) -> None:
|
def async_setup(self) -> None:
|
||||||
@ -43,6 +53,7 @@ class SolarEdgeDataService(ABC):
|
|||||||
self.coordinator = DataUpdateCoordinator(
|
self.coordinator = DataUpdateCoordinator(
|
||||||
self.hass,
|
self.hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=self.config_entry,
|
||||||
name=str(self),
|
name=str(self),
|
||||||
update_method=self.async_update_data,
|
update_method=self.async_update_data,
|
||||||
update_interval=self.update_interval,
|
update_interval=self.update_interval,
|
||||||
@ -174,9 +185,15 @@ class SolarEdgeInventoryDataService(SolarEdgeDataService):
|
|||||||
class SolarEdgeEnergyDetailsService(SolarEdgeDataService):
|
class SolarEdgeEnergyDetailsService(SolarEdgeDataService):
|
||||||
"""Get and update the latest power flow data."""
|
"""Get and update the latest power flow data."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: SolarEdge, site_id: str) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SolarEdgeConfigEntry,
|
||||||
|
api: SolarEdge,
|
||||||
|
site_id: str,
|
||||||
|
) -> None:
|
||||||
"""Initialize the power flow data service."""
|
"""Initialize the power flow data service."""
|
||||||
super().__init__(hass, api, site_id)
|
super().__init__(hass, config_entry, api, site_id)
|
||||||
|
|
||||||
self.unit = None
|
self.unit = None
|
||||||
|
|
||||||
@ -234,9 +251,15 @@ class SolarEdgeEnergyDetailsService(SolarEdgeDataService):
|
|||||||
class SolarEdgePowerFlowDataService(SolarEdgeDataService):
|
class SolarEdgePowerFlowDataService(SolarEdgeDataService):
|
||||||
"""Get and update the latest power flow data."""
|
"""Get and update the latest power flow data."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: SolarEdge, site_id: str) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SolarEdgeConfigEntry,
|
||||||
|
api: SolarEdge,
|
||||||
|
site_id: str,
|
||||||
|
) -> None:
|
||||||
"""Initialize the power flow data service."""
|
"""Initialize the power flow data service."""
|
||||||
super().__init__(hass, api, site_id)
|
super().__init__(hass, config_entry, api, site_id)
|
||||||
|
|
||||||
self.unit = None
|
self.unit = None
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ async def async_setup_entry(
|
|||||||
"""Add an solarEdge entry."""
|
"""Add an solarEdge entry."""
|
||||||
# Add the needed sensors to hass
|
# Add the needed sensors to hass
|
||||||
api = entry.runtime_data[DATA_API_CLIENT]
|
api = entry.runtime_data[DATA_API_CLIENT]
|
||||||
sensor_factory = SolarEdgeSensorFactory(hass, entry.data[CONF_SITE_ID], api)
|
sensor_factory = SolarEdgeSensorFactory(hass, entry, entry.data[CONF_SITE_ID], api)
|
||||||
for service in sensor_factory.all_services:
|
for service in sensor_factory.all_services:
|
||||||
service.async_setup()
|
service.async_setup()
|
||||||
await service.coordinator.async_refresh()
|
await service.coordinator.async_refresh()
|
||||||
@ -222,14 +222,20 @@ async def async_setup_entry(
|
|||||||
class SolarEdgeSensorFactory:
|
class SolarEdgeSensorFactory:
|
||||||
"""Factory which creates sensors based on the sensor_key."""
|
"""Factory which creates sensors based on the sensor_key."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, site_id: str, api: SolarEdge) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SolarEdgeConfigEntry,
|
||||||
|
site_id: str,
|
||||||
|
api: SolarEdge,
|
||||||
|
) -> None:
|
||||||
"""Initialize the factory."""
|
"""Initialize the factory."""
|
||||||
|
|
||||||
details = SolarEdgeDetailsDataService(hass, api, site_id)
|
details = SolarEdgeDetailsDataService(hass, config_entry, api, site_id)
|
||||||
overview = SolarEdgeOverviewDataService(hass, api, site_id)
|
overview = SolarEdgeOverviewDataService(hass, config_entry, api, site_id)
|
||||||
inventory = SolarEdgeInventoryDataService(hass, api, site_id)
|
inventory = SolarEdgeInventoryDataService(hass, config_entry, api, site_id)
|
||||||
flow = SolarEdgePowerFlowDataService(hass, api, site_id)
|
flow = SolarEdgePowerFlowDataService(hass, config_entry, api, site_id)
|
||||||
energy = SolarEdgeEnergyDetailsService(hass, api, site_id)
|
energy = SolarEdgeEnergyDetailsService(hass, config_entry, api, site_id)
|
||||||
|
|
||||||
self.all_services = (details, overview, inventory, flow, energy)
|
self.all_services = (details, overview, inventory, flow, energy)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user