Improve dlna_dmr code quality (#56886)
* Listen for config updates from DlnaDmrEntity.async_added_to_hass
Use `Entity.async_on_remove` for dealing with callback cancellation,
instead of re-inventing the wheel with `_remove_ssdp_callbacks`.
* Use async_write_ha_state within async methods
* Import YAML config from async_setup_platform
* Import flow prompts user when device is uncontactable during migration
When config flow is able to contact a device, or when it has information
from SSDP, it will create config entries without error. If the device is
uncontactable at this point then it will appear as unavailable in HA
until it is turned on again.
When import flow cannot migrate an entry because it needs to contact the
device and can't, it will notify the user with a config flow form.
* Don't del unused parameters, HA pylint doesn't care
* Remove unused imports from tests
* Abort config flow at earliest opportunity
* Return async_abort instead of raising AbortFlow
* Consolidate config entry test cleanup into a single function
* fixup! Consolidate config entry test cleanup into a single function
Revert "Consolidate config entry test cleanup into a single function"
This reverts commit 8220da7263
.
* Check resource acquisition/release in specific tests
* fixup! Check resource acquisition/release in specific tests
* Remove unused network dependency from manifest
* _on_event runs in async context
* Call async_write_ha_state directly (not via shedule_update)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b980dc7e33
commit
667e730946
11 changed files with 436 additions and 436 deletions
|
@ -3,8 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
from collections import defaultdict
|
||||
from collections.abc import Mapping
|
||||
from typing import Any, NamedTuple, cast
|
||||
from typing import NamedTuple, cast
|
||||
|
||||
from async_upnp_client import UpnpEventHandler, UpnpFactory, UpnpRequester
|
||||
from async_upnp_client.aiohttp import AiohttpNotifyServer, AiohttpSessionRequester
|
||||
|
@ -33,7 +32,6 @@ class DlnaDmrData:
|
|||
event_notifiers: dict[EventListenAddr, AiohttpNotifyServer]
|
||||
event_notifier_refs: defaultdict[EventListenAddr, int]
|
||||
stop_listener_remove: CALLBACK_TYPE | None = None
|
||||
unmigrated_config: dict[str, Mapping[str, Any]]
|
||||
|
||||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
"""Initialize global data."""
|
||||
|
@ -43,11 +41,9 @@ class DlnaDmrData:
|
|||
self.upnp_factory = UpnpFactory(self.requester, non_strict=True)
|
||||
self.event_notifiers = {}
|
||||
self.event_notifier_refs = defaultdict(int)
|
||||
self.unmigrated_config = {}
|
||||
|
||||
async def async_cleanup_event_notifiers(self, event: Event) -> None:
|
||||
"""Clean up resources when Home Assistant is stopped."""
|
||||
del event # unused
|
||||
LOGGER.debug("Cleaning resources in DlnaDmrData")
|
||||
async with self.lock:
|
||||
tasks = (server.stop_server() for server in self.event_notifiers.values())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue