mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use ZeroconfServiceInfo in sonos (#60095)
This commit is contained in:
parent
b9cbfbae58
commit
b465131170
@ -5,7 +5,6 @@ import soco
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.config_entry_flow import DiscoveryFlowHandler
|
||||
@ -31,13 +30,13 @@ class SonosDiscoveryFlowHandler(DiscoveryFlowHandler):
|
||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initialized by zeroconf."""
|
||||
hostname = discovery_info["hostname"]
|
||||
hostname = discovery_info[zeroconf.ATTR_HOSTNAME]
|
||||
if hostname is None or not hostname.lower().startswith("sonos"):
|
||||
return self.async_abort(reason="not_sonos_device")
|
||||
await self.async_set_unique_id(self._domain, raise_on_progress=False)
|
||||
host = discovery_info[CONF_HOST]
|
||||
mdns_name = discovery_info[CONF_NAME]
|
||||
properties = discovery_info["properties"]
|
||||
host = discovery_info[zeroconf.ATTR_HOST]
|
||||
mdns_name = discovery_info[zeroconf.ATTR_NAME]
|
||||
properties = discovery_info[zeroconf.ATTR_PROPERTIES]
|
||||
boot_seqnum = properties.get("bootseq")
|
||||
model = properties.get("model")
|
||||
uid = hostname_to_uid(hostname)
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.sonos.const import DATA_SONOS_DISCOVERY_MANAGER, DOMAIN
|
||||
|
||||
|
||||
@ -43,12 +44,12 @@ async def test_zeroconf_form(hass: core.HomeAssistant):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"host": "192.168.4.2",
|
||||
"name": "Sonos-aaa@Living Room._sonos._tcp.local.",
|
||||
"hostname": "Sonos-aaa",
|
||||
"properties": {"bootseq": "1234"},
|
||||
},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.4.2",
|
||||
name="Sonos-aaa@Living Room._sonos._tcp.local.",
|
||||
hostname="Sonos-aaa",
|
||||
properties={"bootseq": "1234"},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] is None
|
||||
@ -82,13 +83,13 @@ async def test_zeroconf_sonos_v1(hass: core.HomeAssistant):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"host": "192.168.1.107",
|
||||
"port": 1443,
|
||||
"hostname": "sonos5CAAFDE47AC8.local.",
|
||||
"type": "_sonos._tcp.local.",
|
||||
"name": "Sonos-5CAAFDE47AC8._sonos._tcp.local.",
|
||||
"properties": {
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.107",
|
||||
port=1443,
|
||||
hostname="sonos5CAAFDE47AC8.local.",
|
||||
type="_sonos._tcp.local.",
|
||||
name="Sonos-5CAAFDE47AC8._sonos._tcp.local.",
|
||||
properties={
|
||||
"_raw": {
|
||||
"info": b"/api/v1/players/RINCON_5CAAFDE47AC801400/info",
|
||||
"vers": b"1",
|
||||
@ -98,7 +99,7 @@ async def test_zeroconf_sonos_v1(hass: core.HomeAssistant):
|
||||
"vers": "1",
|
||||
"protovers": "1.18.9",
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] is None
|
||||
@ -132,11 +133,11 @@ async def test_zeroconf_form_not_sonos(hass: core.HomeAssistant):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"host": "192.168.4.2",
|
||||
"hostname": "not-aaa",
|
||||
"properties": {"bootseq": "1234"},
|
||||
},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.4.2",
|
||||
hostname="not-aaa",
|
||||
properties={"bootseq": "1234"},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_sonos_device"
|
||||
|
Loading…
x
Reference in New Issue
Block a user