Axis discovery updates host address (#22632)
* Discovery can update host on existing entries * Add support in device to update host on entry update * Fix tests and listener * Fix hound comment * Fix failing tests from cleanup
This commit is contained in:
1 parent
6c14e7afa7
commit
8a0b210f87
7 files changed
+104
-49
No files matched your search
@@ -16,7 +16,7 @@ async def test_configured_devices(hass):
|
||||
assert not result
|
||||
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN,
|
||||
data={axis.CONF_DEVICE: {axis.CONF_HOST: ''}})
|
||||
data={axis.config_flow.CONF_MAC: '1234'})
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = config_flow.configured_devices(hass)
|
||||
@@ -76,17 +76,21 @@ async def test_flow_fails_already_configured(hass):
|
||||
flow = config_flow.AxisFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN, data={axis.CONF_DEVICE: {
|
||||
axis.CONF_HOST: '1.2.3.4'
|
||||
}})
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN,
|
||||
data={axis.config_flow.CONF_MAC: '1234'})
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await flow.async_step_user(user_input={
|
||||
config_flow.CONF_HOST: '1.2.3.4',
|
||||
config_flow.CONF_USERNAME: 'user',
|
||||
config_flow.CONF_PASSWORD: 'pass',
|
||||
config_flow.CONF_PORT: 81
|
||||
})
|
||||
mock_device = Mock()
|
||||
mock_device.vapix.get_param.return_value = '1234'
|
||||
|
||||
with patch('homeassistant.components.axis.config_flow.get_device',
|
||||
return_value=mock_coro(mock_device)):
|
||||
result = await flow.async_step_user(user_input={
|
||||
config_flow.CONF_HOST: '1.2.3.4',
|
||||
config_flow.CONF_USERNAME: 'user',
|
||||
config_flow.CONF_PASSWORD: 'pass',
|
||||
config_flow.CONF_PORT: 81
|
||||
})
|
||||
|
||||
assert result['errors'] == {'base': 'already_configured'}
|
||||
|
||||
@@ -220,16 +224,19 @@ async def test_discovery_flow_already_configured(hass):
|
||||
flow = config_flow.AxisFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN, data={axis.CONF_DEVICE: {
|
||||
axis.CONF_HOST: '1.2.3.4'
|
||||
}})
|
||||
entry = MockConfigEntry(
|
||||
domain=axis.DOMAIN,
|
||||
data={axis.CONF_DEVICE: {axis.config_flow.CONF_HOST: '1.2.3.4'},
|
||||
axis.config_flow.CONF_MAC: '1234ABCD'}
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await flow.async_step_discovery(discovery_info={
|
||||
config_flow.CONF_HOST: '1.2.3.4',
|
||||
config_flow.CONF_USERNAME: 'user',
|
||||
config_flow.CONF_PASSWORD: 'pass',
|
||||
config_flow.CONF_PORT: 81
|
||||
config_flow.CONF_PORT: 81,
|
||||
'properties': {'macaddress': '1234ABCD'}
|
||||
})
|
||||
print(result)
|
||||
assert result['type'] == 'abort'
|
||||
|
||||
@@ -3,9 +3,10 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.common import mock_coro, MockConfigEntry
|
||||
|
||||
from homeassistant.components.axis import device, errors
|
||||
from homeassistant.components.axis.camera import AxisCamera
|
||||
|
||||
DEVICE_DATA = {
|
||||
device.CONF_HOST: '1.2.3.4',
|
||||
@@ -16,7 +17,7 @@ DEVICE_DATA = {
|
||||
|
||||
ENTRY_OPTIONS = {
|
||||
device.CONF_CAMERA: True,
|
||||
device.CONF_EVENTS: ['pir'],
|
||||
device.CONF_EVENTS: True,
|
||||
}
|
||||
|
||||
ENTRY_CONFIG = {
|
||||
@@ -53,6 +54,31 @@ async def test_device_setup():
|
||||
(entry, 'binary_sensor')
|
||||
|
||||
|
||||
async def test_device_signal_new_address(hass):
|
||||
"""Successful setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS)
|
||||
|
||||
api = Mock()
|
||||
api.vapix.get_param.return_value = '1234'
|
||||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
hass.data[device.DOMAIN] = {axis_device.serial: axis_device}
|
||||
|
||||
with patch.object(device, 'get_device', return_value=mock_coro(api)), \
|
||||
patch.object(AxisCamera, '_new_address') as new_address_mock:
|
||||
await axis_device.async_setup()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry.data[device.CONF_DEVICE][device.CONF_HOST] = '2.3.4.5'
|
||||
hass.config_entries.async_update_entry(entry, data=entry.data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert axis_device.host == '2.3.4.5'
|
||||
assert axis_device.api.config.host == '2.3.4.5'
|
||||
assert len(new_address_mock.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_device_not_accessible():
|
||||
"""Failed setup schedules a retry of setup."""
|
||||
hass = Mock()
|
||||
|
||||
@@ -9,30 +9,28 @@ from tests.common import mock_coro, MockConfigEntry
|
||||
|
||||
async def test_setup(hass):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(axis, 'configured_devices', return_value={}):
|
||||
with patch.object(hass.config_entries, 'flow') as mock_config_flow:
|
||||
|
||||
assert await async_setup_component(hass, axis.DOMAIN, {
|
||||
axis.DOMAIN: {
|
||||
'device_name': {
|
||||
axis.CONF_HOST: '1.2.3.4',
|
||||
axis.config_flow.CONF_HOST: '1.2.3.4',
|
||||
axis.config_flow.CONF_PORT: 80,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
assert len(mock_config_entries.flow.mock_calls) == 1
|
||||
assert len(mock_config_flow.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_setup_device_already_configured(hass):
|
||||
"""Test already configured device does not configure a second."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(axis, 'configured_devices', return_value={'1.2.3.4'}):
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries:
|
||||
|
||||
assert await async_setup_component(hass, axis.DOMAIN, {
|
||||
axis.DOMAIN: {
|
||||
'device_name': {
|
||||
axis.CONF_HOST: '1.2.3.4'
|
||||
axis.config_flow.CONF_HOST: '1.2.3.4'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user