Disable creating port mappings from UI, add discovery from component (#18565)
* Disable creating port mappings from UI, add discovery from component * Remove unused constant * Upgrade to async_upnp_client==0.13.6 and use manufacturer from device * Upgrade to async_upnp_client==0.13.7
This commit is contained in:
parent
5efc61feaf
commit
501b3f9927
12 changed files with 195 additions and 653 deletions
|
@ -26,7 +26,7 @@ class MockDevice(Device):
|
|||
@classmethod
|
||||
async def async_create_device(cls, hass, ssdp_description):
|
||||
"""Return self."""
|
||||
return cls()
|
||||
return cls('UDN')
|
||||
|
||||
@property
|
||||
def udn(self):
|
||||
|
@ -47,102 +47,10 @@ class MockDevice(Device):
|
|||
self.removed_port_mappings.append(entry)
|
||||
|
||||
|
||||
async def test_async_setup_no_auto_config(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
config = {
|
||||
'discovery': {},
|
||||
# no upnp
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': False,
|
||||
'enable_sensors': False,
|
||||
'enable_port_mapping': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
}
|
||||
|
||||
|
||||
async def test_async_setup_auto_config(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
config = {
|
||||
'discovery': {},
|
||||
'upnp': {},
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'enable_sensors': True,
|
||||
'enable_port_mapping': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
}
|
||||
|
||||
|
||||
async def test_async_setup_auto_config_port_mapping(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
config = {
|
||||
'discovery': {},
|
||||
'upnp': {
|
||||
'port_mapping': True,
|
||||
'ports': {'hass': 'hass'},
|
||||
},
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'enable_sensors': True,
|
||||
'enable_port_mapping': True,
|
||||
'ports': {'hass': 'hass'},
|
||||
}
|
||||
|
||||
|
||||
async def test_async_setup_auto_config_no_sensors(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
config = {
|
||||
'discovery': {},
|
||||
'upnp': {'sensors': False},
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'enable_sensors': False,
|
||||
'enable_port_mapping': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
}
|
||||
|
||||
|
||||
async def test_async_setup_entry_default(hass):
|
||||
"""Test async_setup_entry."""
|
||||
udn = 'uuid:device_1'
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
'udn': udn,
|
||||
'sensors': True,
|
||||
'port_mapping': False,
|
||||
})
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN)
|
||||
|
||||
config = {
|
||||
'http': {},
|
||||
|
@ -150,7 +58,7 @@ async def test_async_setup_entry_default(hass):
|
|||
# no upnp
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
patch('homeassistant.components.upnp.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'http', config)
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
|
@ -158,17 +66,23 @@ async def test_async_setup_entry_default(hass):
|
|||
|
||||
# mock homeassistant.components.upnp.device.Device
|
||||
mock_device = MockDevice(udn)
|
||||
with patch.object(Device, 'async_create_device') as create_device:
|
||||
discovery_infos = [{
|
||||
'udn': udn,
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
}]
|
||||
with patch.object(Device, 'async_create_device') as create_device, \
|
||||
patch.object(Device, 'async_discover') as async_discover: # noqa:E125
|
||||
|
||||
create_device.return_value = mock_coro(return_value=mock_device)
|
||||
with patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
assert await upnp.async_setup_entry(hass, entry) is True
|
||||
async_discover.return_value = mock_coro(return_value=discovery_infos)
|
||||
|
||||
# ensure device is stored/used
|
||||
assert hass.data[upnp.DOMAIN]['devices'][udn] == mock_device
|
||||
assert await upnp.async_setup_entry(hass, entry) is True
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
# ensure device is stored/used
|
||||
assert hass.data[upnp.DOMAIN]['devices'][udn] == mock_device
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# ensure no port-mappings created or removed
|
||||
assert not mock_device.added_port_mappings
|
||||
|
@ -177,13 +91,9 @@ async def test_async_setup_entry_default(hass):
|
|||
|
||||
async def test_async_setup_entry_port_mapping(hass):
|
||||
"""Test async_setup_entry."""
|
||||
# pylint: disable=invalid-name
|
||||
udn = 'uuid:device_1'
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
'udn': udn,
|
||||
'sensors': False,
|
||||
'port_mapping': True,
|
||||
})
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN)
|
||||
|
||||
config = {
|
||||
'http': {},
|
||||
|
@ -194,15 +104,22 @@ async def test_async_setup_entry_port_mapping(hass):
|
|||
},
|
||||
}
|
||||
with MockDependency('netdisco.discovery'), \
|
||||
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||
patch('homeassistant.components.upnp.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
await async_setup_component(hass, 'http', config)
|
||||
await async_setup_component(hass, 'upnp', config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_device = MockDevice(udn)
|
||||
with patch.object(Device, 'async_create_device') as create_device:
|
||||
discovery_infos = [{
|
||||
'udn': udn,
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
}]
|
||||
with patch.object(Device, 'async_create_device') as create_device, \
|
||||
patch.object(Device, 'async_discover') as async_discover: # noqa:E125
|
||||
|
||||
create_device.return_value = mock_coro(return_value=mock_device)
|
||||
async_discover.return_value = mock_coro(return_value=discovery_infos)
|
||||
|
||||
assert await upnp.async_setup_entry(hass, entry) is True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue