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 filesize coordinator (#137807)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
de1a503284
commit
b22830260c
@ -2,19 +2,15 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_FILE_PATH
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import PLATFORMS
|
from .const import PLATFORMS
|
||||||
from .coordinator import FileSizeCoordinator
|
from .coordinator import FileSizeConfigEntry, FileSizeCoordinator
|
||||||
|
|
||||||
type FileSizeConfigEntry = ConfigEntry[FileSizeCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: FileSizeConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: FileSizeConfigEntry) -> bool:
|
||||||
"""Set up from a config entry."""
|
"""Set up from a config entry."""
|
||||||
coordinator = FileSizeCoordinator(hass, entry.data[CONF_FILE_PATH])
|
coordinator = FileSizeCoordinator(hass, entry)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
@ -22,6 +18,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: FileSizeConfigEntry) ->
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: FileSizeConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -7,6 +7,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_FILE_PATH
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
@ -15,22 +17,26 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type FileSizeConfigEntry = ConfigEntry[FileSizeCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class FileSizeCoordinator(DataUpdateCoordinator[dict[str, int | float | datetime]]):
|
class FileSizeCoordinator(DataUpdateCoordinator[dict[str, int | float | datetime]]):
|
||||||
"""Filesize coordinator."""
|
"""Filesize coordinator."""
|
||||||
|
|
||||||
|
config_entry: FileSizeConfigEntry
|
||||||
path: pathlib.Path
|
path: pathlib.Path
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, unresolved_path: str) -> None:
|
def __init__(self, hass: HomeAssistant, config_entry: FileSizeConfigEntry) -> None:
|
||||||
"""Initialize filesize coordinator."""
|
"""Initialize filesize coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=timedelta(seconds=60),
|
update_interval=timedelta(seconds=60),
|
||||||
always_update=False,
|
always_update=False,
|
||||||
)
|
)
|
||||||
self._unresolved_path = unresolved_path
|
self._unresolved_path = self.config_entry.data[CONF_FILE_PATH]
|
||||||
|
|
||||||
def _get_full_path(self) -> pathlib.Path:
|
def _get_full_path(self) -> pathlib.Path:
|
||||||
"""Check if path is valid, allowed and return full path."""
|
"""Check if path is valid, allowed and return full path."""
|
||||||
|
@ -17,9 +17,8 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import FileSizeConfigEntry
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import FileSizeCoordinator
|
from .coordinator import FileSizeConfigEntry, FileSizeCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user