mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Use runtime_data in geonetnz_volcano (#144320)
This commit is contained in:
parent
19a0a16915
commit
5a01521ff8
@ -29,7 +29,6 @@ from .const import (
|
||||
DEFAULT_RADIUS,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DOMAIN,
|
||||
FEED,
|
||||
IMPERIAL_UNITS,
|
||||
PLATFORMS,
|
||||
)
|
||||
@ -52,6 +51,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
type GeonetnzVolcanoConfigEntry = ConfigEntry[GeonetnzVolcanoFeedEntityManager]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the GeoNet NZ Volcano component."""
|
||||
@ -84,11 +85,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: GeonetnzVolcanoConfigEntry
|
||||
) -> bool:
|
||||
"""Set up the GeoNet NZ Volcano component as config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN].setdefault(FEED, {})
|
||||
|
||||
radius = config_entry.data[CONF_RADIUS]
|
||||
unit_system = config_entry.data[CONF_UNIT_SYSTEM]
|
||||
if unit_system == IMPERIAL_UNITS:
|
||||
@ -97,16 +97,17 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
)
|
||||
# Create feed entity manager for all platforms.
|
||||
manager = GeonetnzVolcanoFeedEntityManager(hass, config_entry, radius, unit_system)
|
||||
hass.data[DOMAIN][FEED][config_entry.entry_id] = manager
|
||||
config_entry.runtime_data = manager
|
||||
_LOGGER.debug("Feed entity manager added for %s", config_entry.entry_id)
|
||||
await manager.async_init()
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, entry: GeonetnzVolcanoConfigEntry
|
||||
) -> bool:
|
||||
"""Unload an GeoNet NZ Volcano component config entry."""
|
||||
manager = hass.data[DOMAIN][FEED].pop(entry.entry_id)
|
||||
await manager.async_stop()
|
||||
await entry.runtime_data.async_stop()
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
|
@ -6,8 +6,6 @@ from homeassistant.const import Platform
|
||||
|
||||
DOMAIN = "geonetnz_volcano"
|
||||
|
||||
FEED = "feed"
|
||||
|
||||
ATTR_ACTIVITY = "activity"
|
||||
ATTR_DISTANCE = "distance"
|
||||
ATTR_EXTERNAL_ID = "external_id"
|
||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, UnitOfLength
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
@ -13,14 +12,13 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
|
||||
from . import GeonetnzVolcanoConfigEntry
|
||||
from .const import (
|
||||
ATTR_ACTIVITY,
|
||||
ATTR_DISTANCE,
|
||||
ATTR_EXTERNAL_ID,
|
||||
ATTR_HAZARDS,
|
||||
DEFAULT_ICON,
|
||||
DOMAIN,
|
||||
FEED,
|
||||
IMPERIAL_UNITS,
|
||||
)
|
||||
|
||||
@ -32,11 +30,11 @@ ATTR_LAST_UPDATE_SUCCESSFUL = "feed_last_update_successful"
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: GeonetnzVolcanoConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the GeoNet NZ Volcano Feed platform."""
|
||||
manager = hass.data[DOMAIN][FEED][entry.entry_id]
|
||||
manager = entry.runtime_data
|
||||
|
||||
@callback
|
||||
def async_add_sensor(feed_manager, external_id, unit_system):
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant.components.geonetnz_volcano import DOMAIN, FEED
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
@ -17,8 +16,7 @@ async def test_component_unload_config_entry(hass: HomeAssistant, config_entry)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_feed_manager_update.call_count == 1
|
||||
assert hass.data[DOMAIN][FEED][config_entry.entry_id] is not None
|
||||
|
||||
# Unload config entry.
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[DOMAIN][FEED].get(config_entry.entry_id) is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user