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
This commit is contained in:
Eric Severance 2023-07-20 01:06:16 -07:00 committed by GitHub
parent 0349e47372
commit 5ffffd8dbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 245 additions and 124 deletions

View file

@ -1,7 +1,6 @@
"""Support for power sensors in WeMo Insight devices."""
from __future__ import annotations
import asyncio
from collections.abc import Callable
from dataclasses import dataclass
from typing import cast
@ -15,11 +14,10 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfEnergy, UnitOfPower
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from .const import DOMAIN as WEMO_DOMAIN
from . import async_wemo_dispatcher_connect
from .entity import WemoEntity
from .wemo_device import DeviceCoordinator
@ -59,7 +57,7 @@ ATTRIBUTE_SENSORS = (
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
_config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up WeMo sensors."""
@ -72,14 +70,7 @@ async def async_setup_entry(
if hasattr(coordinator.wemo, description.key)
)
async_dispatcher_connect(hass, f"{WEMO_DOMAIN}.sensor", _discovered_wemo)
await asyncio.gather(
*(
_discovered_wemo(coordinator)
for coordinator in hass.data[WEMO_DOMAIN]["pending"].pop("sensor")
)
)
await async_wemo_dispatcher_connect(hass, _discovered_wemo)
class AttributeSensor(WemoEntity, SensorEntity):