Use dataclass properties in yamaha_musiccast (#60787)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-02 18:50:35 +01:00 committed by GitHub
parent 66494b0238
commit 0c18d710cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View file

@ -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:

View file

@ -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(
{

View file

@ -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