mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Store runtime data inside the config entry in Met.no (#116767)
This commit is contained in:
parent
985fd49909
commit
831282c3ba
@ -21,8 +21,12 @@ PLATFORMS = [Platform.WEATHER]
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
MetWeatherConfigEntry = ConfigEntry[MetDataUpdateCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: MetWeatherConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up Met as config entry."""
|
"""Set up Met as config entry."""
|
||||||
# Don't setup if tracking home location and latitude or longitude isn't set.
|
# Don't setup if tracking home location and latitude or longitude isn't set.
|
||||||
# Also, filters out our onboarding default location.
|
# Also, filters out our onboarding default location.
|
||||||
@ -44,10 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
if config_entry.data.get(CONF_TRACK_HOME, False):
|
if config_entry.data.get(CONF_TRACK_HOME, False):
|
||||||
coordinator.track_home()
|
coordinator.track_home()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
config_entry.runtime_data = coordinator
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
|
||||||
|
|
||||||
config_entry.async_on_unload(config_entry.add_update_listener(async_update_entry))
|
config_entry.async_on_unload(config_entry.add_update_listener(async_update_entry))
|
||||||
|
config_entry.async_on_unload(coordinator.untrack_home)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||||
|
|
||||||
@ -56,19 +60,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: MetWeatherConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||||
config_entry, PLATFORMS
|
|
||||||
)
|
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id].untrack_home()
|
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def async_update_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
async def async_update_entry(hass: HomeAssistant, config_entry: MetWeatherConfigEntry):
|
||||||
"""Reload Met component when options changed."""
|
"""Reload Met component when options changed."""
|
||||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ from homeassistant.components.weather import (
|
|||||||
SingleCoordinatorWeatherEntity,
|
SingleCoordinatorWeatherEntity,
|
||||||
WeatherEntityFeature,
|
WeatherEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
@ -37,6 +36,7 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||||
|
|
||||||
|
from . import MetWeatherConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_CONDITION_CLEAR_NIGHT,
|
ATTR_CONDITION_CLEAR_NIGHT,
|
||||||
ATTR_CONDITION_SUNNY,
|
ATTR_CONDITION_SUNNY,
|
||||||
@ -53,11 +53,11 @@ DEFAULT_NAME = "Met.no"
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MetWeatherConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add a weather entity from a config_entry."""
|
"""Add a weather entity from a config_entry."""
|
||||||
coordinator: MetDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
name: str | None
|
name: str | None
|
||||||
@ -120,7 +120,7 @@ class MetWeather(SingleCoordinatorWeatherEntity[MetDataUpdateCoordinator]):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: MetDataUpdateCoordinator,
|
coordinator: MetDataUpdateCoordinator,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MetWeatherConfigEntry,
|
||||||
name: str,
|
name: str,
|
||||||
is_metric: bool,
|
is_metric: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user