mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Use dataclass properties in dlna_dmr (#60794)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d775c66194
commit
66494b0238
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import logging
|
import logging
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import Any, Mapping, Optional
|
from typing import Any, Mapping, Optional, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from async_upnp_client.client import UpnpError
|
from async_upnp_client.client import UpnpError
|
||||||
@ -93,8 +93,8 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
return await self.async_step_manual()
|
return await self.async_step_manual()
|
||||||
|
|
||||||
self._discoveries = {
|
self._discoveries = {
|
||||||
discovery.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
|
discovery.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
|
||||||
or urlparse(discovery[ssdp.ATTR_SSDP_LOCATION]).hostname: discovery
|
or cast(str, urlparse(discovery.ssdp_location).hostname): discovery
|
||||||
for discovery in discoveries
|
for discovery in discoveries
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
# Find the device in the list of unconfigured devices
|
# Find the device in the list of unconfigured devices
|
||||||
for discovery in discoveries:
|
for discovery in discoveries:
|
||||||
if discovery[ssdp.ATTR_SSDP_LOCATION] == self._location:
|
if discovery.ssdp_location == self._location:
|
||||||
# Device found via SSDP, it shouldn't need polling
|
# Device found via SSDP, it shouldn't need polling
|
||||||
self._options[CONF_POLL_AVAILABILITY] = False
|
self._options[CONF_POLL_AVAILABILITY] = False
|
||||||
# Discovery info has everything required to create config entry
|
# Discovery info has everything required to create config entry
|
||||||
@ -376,9 +376,7 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
for entry in self._async_current_entries(include_ignore=False)
|
for entry in self._async_current_entries(include_ignore=False)
|
||||||
}
|
}
|
||||||
discoveries = [
|
discoveries = [
|
||||||
disc
|
disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids
|
||||||
for disc in discoveries
|
|
||||||
if disc[ssdp.ATTR_SSDP_UDN] not in current_unique_ids
|
|
||||||
]
|
]
|
||||||
|
|
||||||
return discoveries
|
return discoveries
|
||||||
|
@ -6,7 +6,7 @@ from collections.abc import Sequence
|
|||||||
import contextlib
|
import contextlib
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import functools
|
import functools
|
||||||
from typing import Any, Callable, TypeVar, cast
|
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
|
||||||
|
|
||||||
from async_upnp_client import UpnpService, UpnpStateVariable
|
from async_upnp_client import UpnpService, UpnpStateVariable
|
||||||
from async_upnp_client.const import NotificationSubType
|
from async_upnp_client.const import NotificationSubType
|
||||||
@ -278,7 +278,9 @@ class DlnaDmrEntity(MediaPlayerEntity):
|
|||||||
await self._device_disconnect()
|
await self._device_disconnect()
|
||||||
|
|
||||||
if change == ssdp.SsdpChange.ALIVE and not self._device:
|
if change == ssdp.SsdpChange.ALIVE and not self._device:
|
||||||
location = info.ssdp_location or ""
|
if TYPE_CHECKING:
|
||||||
|
assert info.ssdp_location
|
||||||
|
location = info.ssdp_location
|
||||||
try:
|
try:
|
||||||
await self._device_connect(location)
|
await self._device_connect(location)
|
||||||
except UpnpError as err:
|
except UpnpError as err:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user