Use dataclass properties in denonavr discovery (#60691)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-01 14:28:40 +01:00 committed by GitHub
parent 6544b440d2
commit 16942fc8e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,7 +211,7 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
}, },
) )
async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> FlowResult: async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
"""Handle a discovered Denon AVR. """Handle a discovered Denon AVR.
This flow is triggered by the SSDP component. It will check if the This flow is triggered by the SSDP component. It will check if the
@ -219,21 +219,23 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
""" """
# Filter out non-Denon AVRs#1 # Filter out non-Denon AVRs#1
if ( if (
discovery_info.get(ssdp.ATTR_UPNP_MANUFACTURER) discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER)
not in SUPPORTED_MANUFACTURERS not in SUPPORTED_MANUFACTURERS
): ):
return self.async_abort(reason="not_denonavr_manufacturer") return self.async_abort(reason="not_denonavr_manufacturer")
# Check if required information is present to set the unique_id # Check if required information is present to set the unique_id
if ( if (
ssdp.ATTR_UPNP_MODEL_NAME not in discovery_info ssdp.ATTR_UPNP_MODEL_NAME not in discovery_info.upnp
or ssdp.ATTR_UPNP_SERIAL not in discovery_info or ssdp.ATTR_UPNP_SERIAL not in discovery_info.upnp
): ):
return self.async_abort(reason="not_denonavr_missing") return self.async_abort(reason="not_denonavr_missing")
self.model_name = discovery_info[ssdp.ATTR_UPNP_MODEL_NAME].replace("*", "") self.model_name = discovery_info.upnp[ssdp.ATTR_UPNP_MODEL_NAME].replace(
self.serial_number = discovery_info[ssdp.ATTR_UPNP_SERIAL] "*", ""
self.host = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]).hostname )
self.serial_number = discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
self.host = urlparse(discovery_info.ssdp_location).hostname
if self.model_name in IGNORED_MODELS: if self.model_name in IGNORED_MODELS:
return self.async_abort(reason="not_denonavr_manufacturer") return self.async_abort(reason="not_denonavr_manufacturer")
@ -245,7 +247,9 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.context.update( self.context.update(
{ {
"title_placeholders": { "title_placeholders": {
"name": discovery_info.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, self.host) "name": discovery_info.upnp.get(
ssdp.ATTR_UPNP_FRIENDLY_NAME, self.host
)
} }
} }
) )