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 sense coordinator (#137958)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
7fec225e79
commit
71d47aef2e
@ -89,8 +89,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: SenseConfigEntry) -> boo
|
|||||||
except SENSE_WEBSOCKET_EXCEPTIONS as err:
|
except SENSE_WEBSOCKET_EXCEPTIONS as err:
|
||||||
raise ConfigEntryNotReady(str(err) or "Error during realtime update") from err
|
raise ConfigEntryNotReady(str(err) or "Error during realtime update") from err
|
||||||
|
|
||||||
trends_coordinator = SenseTrendCoordinator(hass, gateway)
|
trends_coordinator = SenseTrendCoordinator(hass, entry, gateway)
|
||||||
realtime_coordinator = SenseRealtimeCoordinator(hass, gateway)
|
realtime_coordinator = SenseRealtimeCoordinator(hass, entry, gateway)
|
||||||
|
|
||||||
# This can take longer than 60s and we already know
|
# This can take longer than 60s and we already know
|
||||||
# sense is online since get_discovered_device_data was
|
# sense is online since get_discovered_device_data was
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
"""Sense Coordinators."""
|
"""Sense Coordinators."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from sense_energy import (
|
from sense_energy import (
|
||||||
ASyncSenseable,
|
ASyncSenseable,
|
||||||
@ -13,6 +16,9 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import SenseConfigEntry
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ACTIVE_UPDATE_RATE,
|
ACTIVE_UPDATE_RATE,
|
||||||
SENSE_CONNECT_EXCEPTIONS,
|
SENSE_CONNECT_EXCEPTIONS,
|
||||||
@ -27,13 +33,21 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class SenseCoordinator(DataUpdateCoordinator[None]):
|
class SenseCoordinator(DataUpdateCoordinator[None]):
|
||||||
"""Sense Trend Coordinator."""
|
"""Sense Trend Coordinator."""
|
||||||
|
|
||||||
|
config_entry: SenseConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, gateway: ASyncSenseable, name: str, update: int
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SenseConfigEntry,
|
||||||
|
gateway: ASyncSenseable,
|
||||||
|
name: str,
|
||||||
|
update: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=_LOGGER,
|
logger=_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=f"Sense {name} {gateway.sense_monitor_id}",
|
name=f"Sense {name} {gateway.sense_monitor_id}",
|
||||||
update_interval=timedelta(seconds=update),
|
update_interval=timedelta(seconds=update),
|
||||||
)
|
)
|
||||||
@ -44,9 +58,14 @@ class SenseCoordinator(DataUpdateCoordinator[None]):
|
|||||||
class SenseTrendCoordinator(SenseCoordinator):
|
class SenseTrendCoordinator(SenseCoordinator):
|
||||||
"""Sense Trend Coordinator."""
|
"""Sense Trend Coordinator."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, gateway: ASyncSenseable) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SenseConfigEntry,
|
||||||
|
gateway: ASyncSenseable,
|
||||||
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(hass, gateway, "Trends", TREND_UPDATE_RATE)
|
super().__init__(hass, config_entry, gateway, "Trends", TREND_UPDATE_RATE)
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
async def _async_update_data(self) -> None:
|
||||||
"""Update the trend data."""
|
"""Update the trend data."""
|
||||||
@ -62,9 +81,14 @@ class SenseTrendCoordinator(SenseCoordinator):
|
|||||||
class SenseRealtimeCoordinator(SenseCoordinator):
|
class SenseRealtimeCoordinator(SenseCoordinator):
|
||||||
"""Sense Realtime Coordinator."""
|
"""Sense Realtime Coordinator."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, gateway: ASyncSenseable) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: SenseConfigEntry,
|
||||||
|
gateway: ASyncSenseable,
|
||||||
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(hass, gateway, "Realtime", ACTIVE_UPDATE_RATE)
|
super().__init__(hass, config_entry, gateway, "Realtime", ACTIVE_UPDATE_RATE)
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
async def _async_update_data(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user