mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Use dataclass properties in webostv discovery (#64159)
This commit is contained in:
parent
533d0e4444
commit
c0b1d083b8
@ -11,6 +11,7 @@ from homeassistant import config_entries, data_entry_flow
|
|||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_NAME, CONF_UNIQUE_ID
|
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_NAME, CONF_UNIQUE_ID
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import async_control_connect
|
from . import async_control_connect
|
||||||
@ -116,12 +117,12 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return self.async_show_form(step_id="pairing", errors=errors)
|
return self.async_show_form(step_id="pairing", errors=errors)
|
||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info):
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a flow initialized by discovery."""
|
"""Handle a flow initialized by discovery."""
|
||||||
self._host = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]).hostname
|
self._host = urlparse(discovery_info.ssdp_location).hostname
|
||||||
self._name = discovery_info[ssdp.ATTR_UPNP_FRIENDLY_NAME]
|
self._name = discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]
|
||||||
|
|
||||||
uuid = discovery_info[ssdp.ATTR_UPNP_UDN]
|
uuid = discovery_info.upnp[ssdp.ATTR_UPNP_UDN]
|
||||||
if uuid.startswith("uuid:"):
|
if uuid.startswith("uuid:"):
|
||||||
uuid = uuid[5:]
|
uuid = uuid[5:]
|
||||||
await self.async_set_unique_id(uuid)
|
await self.async_set_unique_id(uuid)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""Test the WebOS Tv config flow."""
|
"""Test the WebOS Tv config flow."""
|
||||||
|
import dataclasses
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from aiowebostv import WebOsTvPairError
|
from aiowebostv import WebOsTvPairError
|
||||||
@ -31,11 +32,15 @@ MOCK_YAML_CONFIG = {
|
|||||||
CONF_UNIQUE_ID: "fake-uuid",
|
CONF_UNIQUE_ID: "fake-uuid",
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_DISCOVERY_INFO = {
|
MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo(
|
||||||
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4",
|
ssdp_usn="mock_usn",
|
||||||
|
ssdp_st="mock_st",
|
||||||
|
ssdp_location="http://1.2.3.4",
|
||||||
|
upnp={
|
||||||
ssdp.ATTR_UPNP_FRIENDLY_NAME: "LG Webostv",
|
ssdp.ATTR_UPNP_FRIENDLY_NAME: "LG Webostv",
|
||||||
ssdp.ATTR_UPNP_UDN: "uuid:some-fake-uuid",
|
ssdp.ATTR_UPNP_UDN: "uuid:some-fake-uuid",
|
||||||
}
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass, client):
|
async def test_import(hass, client):
|
||||||
@ -250,8 +255,8 @@ async def test_ssdp_not_update_uuid(hass, client):
|
|||||||
assert client
|
assert client
|
||||||
assert entry.unique_id is None
|
assert entry.unique_id is None
|
||||||
|
|
||||||
discovery_info = MOCK_DISCOVERY_INFO.copy()
|
discovery_info = dataclasses.replace(MOCK_DISCOVERY_INFO)
|
||||||
discovery_info.update({ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.5"})
|
discovery_info.ssdp_location = "http://1.2.3.5"
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
result2 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=discovery_info
|
DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=discovery_info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user