1
mirror of https://github.com/home-assistant/core synced 2024-08-28 03:36:46 +02:00
ha-core/homeassistant/components/wemo/models.py
Eric Severance 5ffffd8dbc
Fully unload wemo config entry (#96620)
* Fully unload wemo config entity

* Test reloading the config entry

* Encapsulate data with dataclasses

* Fix missing test coverage

* Replace if with assert for options that are always set

* Move WemoData/WemoConfigEntryData to models.py

* Use _ to indicate unused argument

* Test that the entry and entity work after reloading

* Nit: Slight test reordering

* Reset the correct mock (get_state)

* from .const import DOMAIN

* Nit: _async_wemo_data -> async_wemo_data; not module private
2023-07-20 10:06:16 +02:00

44 lines
1.2 KiB
Python

"""Common data structures and helpers for accessing them."""
from collections.abc import Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING, cast
import pywemo
from homeassistant.core import HomeAssistant, callback
from .const import DOMAIN
if TYPE_CHECKING: # Avoid circular dependencies.
from . import HostPortTuple, WemoDiscovery, WemoDispatcher
from .wemo_device import DeviceCoordinator
@dataclass
class WemoConfigEntryData:
"""Config entry state data."""
device_coordinators: dict[str, "DeviceCoordinator"]
discovery: "WemoDiscovery"
dispatcher: "WemoDispatcher"
@dataclass
class WemoData:
"""Component state data."""
discovery_enabled: bool
static_config: Sequence["HostPortTuple"]
registry: pywemo.SubscriptionRegistry
# config_entry_data is set when the config entry is loaded and unset when it's
# unloaded. It's a programmer error if config_entry_data is accessed when the
# config entry is not loaded
config_entry_data: WemoConfigEntryData = None # type: ignore[assignment]
@callback
def async_wemo_data(hass: HomeAssistant) -> WemoData:
"""Fetch WemoData with proper typing."""
return cast(WemoData, hass.data[DOMAIN])