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 lektrico coordinator (#138114)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
12c5ad7249
commit
75cf47be2b
@ -4,11 +4,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from lektricowifi import Device
|
from lektricowifi import Device
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.const import CONF_TYPE, Platform
|
||||||
from homeassistant.const import ATTR_SERIAL_NUMBER, CONF_TYPE, Platform
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .coordinator import LektricoDeviceDataUpdateCoordinator
|
from .coordinator import LektricoConfigEntry, LektricoDeviceDataUpdateCoordinator
|
||||||
|
|
||||||
# List the platforms that charger supports.
|
# List the platforms that charger supports.
|
||||||
CHARGERS_PLATFORMS: list[Platform] = [
|
CHARGERS_PLATFORMS: list[Platform] = [
|
||||||
@ -26,15 +25,10 @@ LB_DEVICES_PLATFORMS: list[Platform] = [
|
|||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
type LektricoConfigEntry = ConfigEntry[LektricoDeviceDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: LektricoConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: LektricoConfigEntry) -> bool:
|
||||||
"""Set up Lektrico Charging Station from a config entry."""
|
"""Set up Lektrico Charging Station from a config entry."""
|
||||||
coordinator = LektricoDeviceDataUpdateCoordinator(
|
coordinator = LektricoDeviceDataUpdateCoordinator(hass, entry)
|
||||||
hass,
|
|
||||||
f"{entry.data[CONF_TYPE]}_{entry.data[ATTR_SERIAL_NUMBER]}",
|
|
||||||
)
|
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
@ -45,7 +39,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LektricoConfigEntry) ->
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: LektricoConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
|
||||||
return await hass.config_entries.async_unload_platforms(
|
return await hass.config_entries.async_unload_platforms(
|
||||||
@ -53,7 +47,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_platforms(entry: ConfigEntry) -> list[Platform]:
|
def _get_platforms(entry: LektricoConfigEntry) -> list[Platform]:
|
||||||
"""Return the platforms for this type of device."""
|
"""Return the platforms for this type of device."""
|
||||||
_device_type: str = entry.data[CONF_TYPE]
|
_device_type: str = entry.data[CONF_TYPE]
|
||||||
if _device_type in (Device.TYPE_1P7K, Device.TYPE_3P22K):
|
if _device_type in (Device.TYPE_1P7K, Device.TYPE_3P22K):
|
||||||
|
@ -22,18 +22,21 @@ from .const import LOGGER
|
|||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=10)
|
SCAN_INTERVAL = timedelta(seconds=10)
|
||||||
|
|
||||||
|
type LektricoConfigEntry = ConfigEntry[LektricoDeviceDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class LektricoDeviceDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class LektricoDeviceDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Data update coordinator for Lektrico device."""
|
"""Data update coordinator for Lektrico device."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: LektricoConfigEntry
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, device_name: str) -> None:
|
def __init__(self, hass: HomeAssistant, config_entry: LektricoConfigEntry) -> None:
|
||||||
"""Initialize a Lektrico Device."""
|
"""Initialize a Lektrico Device."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
name=device_name,
|
config_entry=config_entry,
|
||||||
|
name=f"{config_entry.data[CONF_TYPE]}_{config_entry.data[ATTR_SERIAL_NUMBER]}",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
self.device = Device(
|
self.device = Device(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user