mirror of
https://github.com/home-assistant/core.git
synced 2026-05-19 23:10:15 +01:00
Use runtime_data in sharkiq integration (#167741)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,6 @@ from sharkiq import (
|
||||
)
|
||||
|
||||
from homeassistant import exceptions
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
@@ -28,7 +27,7 @@ from .const import (
|
||||
SHARKIQ_REGION_DEFAULT,
|
||||
SHARKIQ_REGION_EUROPE,
|
||||
)
|
||||
from .coordinator import SharkIqUpdateCoordinator
|
||||
from .coordinator import SharkIqConfigEntry, SharkIqUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
@@ -60,7 +59,9 @@ 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: SharkIqConfigEntry
|
||||
) -> bool:
|
||||
"""Initialize the sharkiq platform via config entry."""
|
||||
if CONF_REGION not in config_entry.data:
|
||||
hass.config_entries.async_update_entry(
|
||||
@@ -93,8 +94,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
||||
config_entry.runtime_data = coordinator
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
@@ -116,15 +116,15 @@ async def async_update_options(hass: HomeAssistant, config_entry):
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, config_entry: SharkIqConfigEntry
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||
config_entry, PLATFORMS
|
||||
)
|
||||
if unload_ok:
|
||||
domain_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
with suppress(SharkIqAuthError):
|
||||
await async_disconnect_or_timeout(coordinator=domain_data)
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
await async_disconnect_or_timeout(coordinator=config_entry.runtime_data)
|
||||
|
||||
return unload_ok
|
||||
|
||||
@@ -20,16 +20,18 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
|
||||
from .const import API_TIMEOUT, DOMAIN, LOGGER, UPDATE_INTERVAL
|
||||
|
||||
type SharkIqConfigEntry = ConfigEntry[SharkIqUpdateCoordinator]
|
||||
|
||||
|
||||
class SharkIqUpdateCoordinator(DataUpdateCoordinator[bool]):
|
||||
"""Define a wrapper class to update Shark IQ data."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: SharkIqConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: SharkIqConfigEntry,
|
||||
ayla_api: AylaApi,
|
||||
shark_vacs: list[SharkIqVacuum],
|
||||
) -> None:
|
||||
|
||||
@@ -12,7 +12,6 @@ from homeassistant.components.vacuum import (
|
||||
VacuumActivity,
|
||||
VacuumEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
@@ -20,7 +19,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import ATTR_ROOMS, DOMAIN, LOGGER, SHARK
|
||||
from .coordinator import SharkIqUpdateCoordinator
|
||||
from .coordinator import SharkIqConfigEntry, SharkIqUpdateCoordinator
|
||||
|
||||
OPERATING_STATE_MAP = {
|
||||
OperatingModes.PAUSE: VacuumActivity.PAUSED,
|
||||
@@ -46,11 +45,11 @@ ATTR_RECHARGE_RESUME = "recharge_and_resume"
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: SharkIqConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Shark IQ vacuum cleaner."""
|
||||
coordinator: SharkIqUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator = config_entry.runtime_data
|
||||
devices: Iterable[SharkIqVacuum] = coordinator.shark_vacs.values()
|
||||
device_names = [d.name for d in devices]
|
||||
LOGGER.debug(
|
||||
|
||||
@@ -290,7 +290,9 @@ async def test_coordinator_updates(
|
||||
hass: HomeAssistant, side_effect: Exception | None, success: bool
|
||||
) -> None:
|
||||
"""Test the update coordinator update functions."""
|
||||
coordinator = hass.data[DOMAIN][ENTRY_ID]
|
||||
entry = hass.config_entries.async_get_entry(ENTRY_ID)
|
||||
assert entry is not None
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user