Use dataclass properties in yamaha_musiccast (#60787)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
66494b0238
commit
0c18d710cc
3 changed files with 17 additions and 8 deletions
|
@ -39,11 +39,10 @@ SCAN_INTERVAL = timedelta(seconds=60)
|
|||
async def get_upnp_desc(hass: HomeAssistant, host: str):
|
||||
"""Get the upnp description URL for a given host, using the SSPD scanner."""
|
||||
ssdp_entries = await ssdp.async_get_discovery_info_by_st(hass, "upnp:rootdevice")
|
||||
matches = [w for w in ssdp_entries if w.get("_host", "") == host]
|
||||
matches = [w for w in ssdp_entries if w.ssdp_headers.get("_host", "") == host]
|
||||
upnp_desc = None
|
||||
for match in matches:
|
||||
if match.get(ssdp.ATTR_SSDP_LOCATION):
|
||||
upnp_desc = match[ssdp.ATTR_SSDP_LOCATION]
|
||||
if upnp_desc := match.ssdp_location:
|
||||
break
|
||||
|
||||
if not upnp_desc:
|
||||
|
|
|
@ -92,8 +92,13 @@ class MusicCastFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
return self.async_abort(reason="yxc_control_url_missing")
|
||||
|
||||
self.serial_number = discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
|
||||
self.host = urlparse(discovery_info.ssdp_location or "").hostname or ""
|
||||
self.upnp_description = discovery_info.ssdp_location
|
||||
|
||||
# ssdp_location and hostname have been checked in check_yamaha_ssdp so it is safe to ignore type assignment
|
||||
self.host = urlparse(
|
||||
discovery_info.ssdp_location
|
||||
).hostname # type: ignore[assignment]
|
||||
|
||||
await self.async_set_unique_id(self.serial_number)
|
||||
self._abort_if_unique_id_configured(
|
||||
{
|
||||
|
|
|
@ -94,10 +94,15 @@ def mock_valid_discovery_information():
|
|||
with patch(
|
||||
"homeassistant.components.ssdp.async_get_discovery_info_by_st",
|
||||
return_value=[
|
||||
{
|
||||
"ssdp_location": "http://127.0.0.1:9000/MediaRenderer/desc.xml",
|
||||
"_host": "127.0.0.1",
|
||||
}
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="http://127.0.0.1:9000/MediaRenderer/desc.xml",
|
||||
ssdp_headers={
|
||||
"_host": "127.0.0.1",
|
||||
},
|
||||
upnp={},
|
||||
)
|
||||
],
|
||||
):
|
||||
yield
|
||||
|
|
Loading…
Add table
Reference in a new issue