Add SSDP integration (#24090)

* Add SSDP integration

* Fix tests

* Sort all the things

* Add netdisco to test requirements
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-05-26 19:48:27 -07:00
1 parent 97b671171b
commit 9debbfb1a8
22 files changed
+436 -28

No files matched your search

+9 -6
View File
@@ -185,14 +185,15 @@ async def test_flow_link_unknown_host(hass):
}
async def test_bridge_discovery(hass):
async def test_bridge_ssdp(hass):
"""Test a bridge being discovered."""
flow = config_flow.HueFlowHandler()
flow.hass = hass
flow.context = {}
with patch.object(config_flow, 'get_bridge',
side_effect=errors.AuthenticationRequired):
result = await flow.async_step_discovery({
result = await flow.async_step_ssdp({
'host': '0.0.0.0',
'serial': '1234'
})
@@ -201,12 +202,13 @@ async def test_bridge_discovery(hass):
assert result['step_id'] == 'link'
async def test_bridge_discovery_emulated_hue(hass):
async def test_bridge_ssdp_emulated_hue(hass):
"""Test if discovery info is from an emulated hue instance."""
flow = config_flow.HueFlowHandler()
flow.hass = hass
flow.context = {}
result = await flow.async_step_discovery({
result = await flow.async_step_ssdp({
'name': 'HASS Bridge',
'host': '0.0.0.0',
'serial': '1234'
@@ -215,7 +217,7 @@ async def test_bridge_discovery_emulated_hue(hass):
assert result['type'] == 'abort'
async def test_bridge_discovery_already_configured(hass):
async def test_bridge_ssdp_already_configured(hass):
"""Test if a discovered bridge has already been configured."""
MockConfigEntry(domain='hue', data={
'host': '0.0.0.0'
@@ -223,8 +225,9 @@ async def test_bridge_discovery_already_configured(hass):
flow = config_flow.HueFlowHandler()
flow.hass = hass
flow.context = {}
result = await flow.async_step_discovery({
result = await flow.async_step_ssdp({
'host': '0.0.0.0',
'serial': '1234'
})
+1
View File
@@ -0,0 +1 @@
"""Tests for the SSDP integration."""
+78
View File
@@ -0,0 +1,78 @@
"""Test the SSDP integration."""
from unittest.mock import patch, Mock
from homeassistant.generated import ssdp as gn_ssdp
from homeassistant.components import ssdp
from tests.common import mock_coro
async def test_scan_match_st(hass):
"""Test matching based on ST."""
scanner = ssdp.Scanner(hass)
with patch('netdisco.ssdp.scan', return_value=[
Mock(st="mock-st", location=None)
]), patch.dict(
gn_ssdp.SSDP['st'], {'mock-st': ['mock-domain']}
), patch.object(
hass.config_entries.flow, 'async_init',
return_value=mock_coro()
) as mock_init:
await scanner.async_scan(None)
assert len(mock_init.mock_calls) == 1
assert mock_init.mock_calls[0][1][0] == 'mock-domain'
assert mock_init.mock_calls[0][2]['context'] == {'source': 'ssdp'}
async def test_scan_match_manufacturer(hass, aioclient_mock):
"""Test matching based on ST."""
aioclient_mock.get('http://1.1.1.1', text="""
<root>
<device>
<manufacturer>Paulus</manufacturer>
</device>
</root>
""")
scanner = ssdp.Scanner(hass)
with patch('netdisco.ssdp.scan', return_value=[
Mock(st="mock-st", location='http://1.1.1.1')
]), patch.dict(
gn_ssdp.SSDP['manufacturer'], {'Paulus': ['mock-domain']}
), patch.object(
hass.config_entries.flow, 'async_init',
return_value=mock_coro()
) as mock_init:
await scanner.async_scan(None)
assert len(mock_init.mock_calls) == 1
assert mock_init.mock_calls[0][1][0] == 'mock-domain'
assert mock_init.mock_calls[0][2]['context'] == {'source': 'ssdp'}
async def test_scan_match_device_type(hass, aioclient_mock):
"""Test matching based on ST."""
aioclient_mock.get('http://1.1.1.1', text="""
<root>
<device>
<deviceType>Paulus</deviceType>
</device>
</root>
""")
scanner = ssdp.Scanner(hass)
with patch('netdisco.ssdp.scan', return_value=[
Mock(st="mock-st", location='http://1.1.1.1')
]), patch.dict(
gn_ssdp.SSDP['device_type'], {'Paulus': ['mock-domain']}
), patch.object(
hass.config_entries.flow, 'async_init',
return_value=mock_coro()
) as mock_init:
await scanner.async_scan(None)
assert len(mock_init.mock_calls) == 1
assert mock_init.mock_calls[0][1][0] == 'mock-domain'
assert mock_init.mock_calls[0][2]['context'] == {'source': 'ssdp'}