mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use SsdpServiceInfo for ssdp tests (part 2) (#60322)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
3399c90936
commit
2468724378
@ -101,7 +101,7 @@ class _SsdpServiceDescription:
|
||||
|
||||
ssdp_usn: str
|
||||
ssdp_st: str
|
||||
ssdp_location: str
|
||||
ssdp_location: str | None = None
|
||||
ssdp_nt: str | None = None
|
||||
ssdp_udn: str | None = None
|
||||
ssdp_ext: str | None = None
|
||||
|
@ -5,7 +5,7 @@ import pytest
|
||||
import respx
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components import dhcp, zeroconf
|
||||
from homeassistant.components import dhcp, ssdp, zeroconf
|
||||
from homeassistant.components.axis import config_flow
|
||||
from homeassistant.components.axis.const import (
|
||||
CONF_EVENTS,
|
||||
@ -263,32 +263,36 @@ async def test_reauth_flow_update_configuration(hass):
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
{
|
||||
"st": "urn:axis-com:service:BasicService:1",
|
||||
"usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1",
|
||||
"ext": "",
|
||||
"server": "Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP devices/1.8.7",
|
||||
"deviceType": "urn:schemas-upnp-org:device:Basic:1",
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"manufacturer": "AXIS",
|
||||
"manufacturerURL": "http://www.axis.com/",
|
||||
"modelDescription": "AXIS M1065-LW Network Camera",
|
||||
"modelName": "AXIS M1065-LW",
|
||||
"modelNumber": "M1065-LW",
|
||||
"modelURL": "http://www.axis.com/",
|
||||
"serialNumber": MAC,
|
||||
"UDN": f"uuid:Upnp-BasicDevice-1_0-{MAC}",
|
||||
"serviceList": {
|
||||
"service": {
|
||||
"serviceType": "urn:axis-com:service:BasicService:1",
|
||||
"serviceId": "urn:axis-com:serviceId:BasicServiceId",
|
||||
"controlURL": "/upnp/control/BasicServiceId",
|
||||
"eventSubURL": "/upnp/event/BasicServiceId",
|
||||
"SCPDURL": "/scpd_basic.xml",
|
||||
}
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"st": "urn:axis-com:service:BasicService:1",
|
||||
"usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1",
|
||||
"ext": "",
|
||||
"server": "Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP devices/1.8.7",
|
||||
"deviceType": "urn:schemas-upnp-org:device:Basic:1",
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"manufacturer": "AXIS",
|
||||
"manufacturerURL": "http://www.axis.com/",
|
||||
"modelDescription": "AXIS M1065-LW Network Camera",
|
||||
"modelName": "AXIS M1065-LW",
|
||||
"modelNumber": "M1065-LW",
|
||||
"modelURL": "http://www.axis.com/",
|
||||
"serialNumber": MAC,
|
||||
"UDN": f"uuid:Upnp-BasicDevice-1_0-{MAC}",
|
||||
"serviceList": {
|
||||
"service": {
|
||||
"serviceType": "urn:axis-com:service:BasicService:1",
|
||||
"serviceId": "urn:axis-com:serviceId:BasicServiceId",
|
||||
"controlURL": "/upnp/control/BasicServiceId",
|
||||
"eventSubURL": "/upnp/event/BasicServiceId",
|
||||
"SCPDURL": "/scpd_basic.xml",
|
||||
}
|
||||
},
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
@ -354,11 +358,15 @@ async def test_discovery_flow(hass, source: str, discovery_info: dict):
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
{
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
@ -403,11 +411,15 @@ async def test_discovered_device_already_configured(
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
{
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://2.3.4.5:8080/",
|
||||
},
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://2.3.4.5:8080/",
|
||||
},
|
||||
),
|
||||
8080,
|
||||
),
|
||||
(
|
||||
@ -474,11 +486,15 @@ async def test_discovery_flow_updated_configuration(
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
{
|
||||
"friendlyName": "",
|
||||
"serialNumber": "01234567890",
|
||||
"presentationURL": "",
|
||||
},
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": "",
|
||||
"serialNumber": "01234567890",
|
||||
"presentationURL": "",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
@ -518,11 +534,15 @@ async def test_discovery_flow_ignore_non_axis_device(
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
{
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://169.254.3.4:80/",
|
||||
},
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://169.254.3.4:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
|
@ -7,7 +7,7 @@ from aionanoleaf import InvalidToken, NanoleafException, Unauthorized, Unavailab
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components import ssdp, zeroconf
|
||||
from homeassistant.components.nanoleaf.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -462,11 +462,15 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"_host": TEST_HOST,
|
||||
"nl-devicename": TEST_NAME,
|
||||
"nl-deviceid": TEST_DEVICE_ID,
|
||||
},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"_host": TEST_HOST,
|
||||
"nl-devicename": TEST_NAME,
|
||||
"nl-deviceid": TEST_DEVICE_ID,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||
from pyoctoprintapi import ApiError, DiscoverySettings
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components import ssdp, zeroconf
|
||||
from homeassistant.components.octoprint.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -235,11 +235,15 @@ async def test_show_ssdp_form(hass: HomeAssistant) -> None:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"presentationURL": "http://192.168.1.123:80/discovery/device.xml",
|
||||
"port": 80,
|
||||
"UDN": "uuid:83747482",
|
||||
},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"presentationURL": "http://192.168.1.123:80/discovery/device.xml",
|
||||
"port": 80,
|
||||
"UDN": "uuid:83747482",
|
||||
},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert not result["errors"]
|
||||
@ -512,11 +516,15 @@ async def test_duplicate_ssdp_ignored(hass: HomeAssistant) -> None:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"presentationURL": "http://192.168.1.123:80/discovery/device.xml",
|
||||
"port": 80,
|
||||
"UDN": "uuid:83747482",
|
||||
},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"presentationURL": "http://192.168.1.123:80/discovery/device.xml",
|
||||
"port": 80,
|
||||
"UDN": "uuid:83747482",
|
||||
},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dhcp, zeroconf
|
||||
from homeassistant.components import dhcp, ssdp, zeroconf
|
||||
from homeassistant.components.yeelight.config_flow import MODEL_UNKNOWN, CannotConnect
|
||||
from homeassistant.components.yeelight.const import (
|
||||
CONF_DETECTED_MODEL,
|
||||
@ -52,6 +52,12 @@ DEFAULT_CONFIG = {
|
||||
CONF_NIGHTLIGHT_SWITCH: DEFAULT_NIGHTLIGHT_SWITCH,
|
||||
}
|
||||
|
||||
SSDP_INFO = ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp=CAPABILITIES,
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery(hass: HomeAssistant):
|
||||
"""Test setting up discovery."""
|
||||
@ -627,7 +633,7 @@ async def test_discovered_ssdp(hass):
|
||||
f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=CAPABILITIES
|
||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=SSDP_INFO
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -656,7 +662,7 @@ async def test_discovered_ssdp(hass):
|
||||
f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=CAPABILITIES
|
||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=SSDP_INFO
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -719,7 +725,7 @@ async def test_discovered_zeroconf(hass):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=CAPABILITIES,
|
||||
data=SSDP_INFO,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user