Use dataclass properties in deconz discovery (#60690)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/60780/head
epenet 2021-12-01 19:38:20 +01:00 committed by GitHub
parent 6a926b41f2
commit 4411d51d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -203,18 +203,18 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
return await self.async_step_link()
async def async_step_ssdp(self, discovery_info: dict[str, str]) -> FlowResult:
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
"""Handle a discovered deCONZ bridge."""
if (
discovery_info.get(ssdp.ATTR_UPNP_MANUFACTURER_URL)
discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER_URL)
!= DECONZ_MANUFACTURERURL
):
return self.async_abort(reason="not_deconz_bridge")
LOGGER.debug("deCONZ SSDP discovery %s", pformat(discovery_info))
self.bridge_id = normalize_bridge_id(discovery_info[ssdp.ATTR_UPNP_SERIAL])
parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION])
self.bridge_id = normalize_bridge_id(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL])
parsed_url = urlparse(discovery_info.ssdp_location)
entry = await self.async_set_unique_id(self.bridge_id)
if entry and entry.source == config_entries.SOURCE_HASSIO:

View File

@ -7,6 +7,7 @@ import pydeconz
from pydeconz.websocket import STATE_RETRYING, STATE_RUNNING
import pytest
from homeassistant.components import ssdp
from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
)
@ -28,7 +29,6 @@ from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.siren import DOMAIN as SIREN_DOMAIN
from homeassistant.components.ssdp import (
ATTR_SSDP_LOCATION,
ATTR_UPNP_MANUFACTURER_URL,
ATTR_UPNP_SERIAL,
ATTR_UPNP_UDN,
@ -262,12 +262,16 @@ async def test_update_address(hass, aioclient_mock):
) as mock_setup_entry:
await hass.config_entries.flow.async_init(
DECONZ_DOMAIN,
data={
ATTR_SSDP_LOCATION: "http://2.3.4.5:80/",
ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
ATTR_UPNP_SERIAL: BRIDGEID,
ATTR_UPNP_UDN: "uuid:456DEF",
},
data=ssdp.SsdpServiceInfo(
ssdp_st="mock_st",
ssdp_usn="mock_usn",
ssdp_location="http://2.3.4.5:80/",
upnp={
ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
ATTR_UPNP_SERIAL: BRIDGEID,
ATTR_UPNP_UDN: "uuid:456DEF",
},
),
context={"source": SOURCE_SSDP},
)
await hass.async_block_till_done()