Axis - config flow use new helper functions (#31286)
* Make use of new config flow helpers Simplify Axis entry config to work with config flow helpers * Keep old device data for rollback purposes
This commit is contained in:
1 parent
cd1aa46404
commit
56657fa859
8 files changed
+183
-130
No files matched your search
@@ -4,7 +4,7 @@ from unittest.mock import Mock, patch
|
||||
from homeassistant.components import axis
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_device import MAC, setup_axis_integration
|
||||
from .test_device import ENTRY_CONFIG, MAC, setup_axis_integration
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
|
||||
@@ -16,7 +16,7 @@ async def test_setup_device_already_configured(hass):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
axis.DOMAIN,
|
||||
{axis.DOMAIN: {"device_name": {axis.config_flow.CONF_HOST: "1.2.3.4"}}},
|
||||
{axis.DOMAIN: {"device_name": {axis.CONF_HOST: "1.2.3.4"}}},
|
||||
)
|
||||
|
||||
assert not mock_config_entries.flow.mock_calls
|
||||
@@ -38,7 +38,7 @@ async def test_setup_entry(hass):
|
||||
async def test_setup_entry_fails(hass):
|
||||
"""Test successful setup of entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=axis.DOMAIN, data={axis.device.CONF_MAC: "0123"}, options=True
|
||||
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, options=True
|
||||
)
|
||||
|
||||
mock_device = Mock()
|
||||
@@ -63,7 +63,7 @@ async def test_unload_entry(hass):
|
||||
|
||||
async def test_populate_options(hass):
|
||||
"""Test successful populate options."""
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN, data={"device": {}})
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN, data=ENTRY_CONFIG)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch.object(axis, "get_device", return_value=mock_coro(Mock())):
|
||||
@@ -75,3 +75,41 @@ async def test_populate_options(hass):
|
||||
axis.CONF_EVENTS: True,
|
||||
axis.CONF_TRIGGER_TIME: axis.DEFAULT_TRIGGER_TIME,
|
||||
}
|
||||
|
||||
|
||||
async def test_migrate_entry(hass):
|
||||
"""Test successful migration of entry data."""
|
||||
legacy_config = {
|
||||
axis.CONF_DEVICE: {
|
||||
axis.CONF_HOST: "1.2.3.4",
|
||||
axis.CONF_USERNAME: "username",
|
||||
axis.CONF_PASSWORD: "password",
|
||||
axis.CONF_PORT: 80,
|
||||
},
|
||||
axis.CONF_MAC: "mac",
|
||||
axis.device.CONF_MODEL: "model",
|
||||
axis.device.CONF_NAME: "name",
|
||||
}
|
||||
entry = MockConfigEntry(domain=axis.DOMAIN, data=legacy_config)
|
||||
|
||||
assert entry.data == legacy_config
|
||||
assert entry.version == 1
|
||||
|
||||
await axis.async_migrate_entry(hass, entry)
|
||||
|
||||
assert entry.data == {
|
||||
axis.CONF_DEVICE: {
|
||||
axis.CONF_HOST: "1.2.3.4",
|
||||
axis.CONF_USERNAME: "username",
|
||||
axis.CONF_PASSWORD: "password",
|
||||
axis.CONF_PORT: 80,
|
||||
},
|
||||
axis.CONF_HOST: "1.2.3.4",
|
||||
axis.CONF_USERNAME: "username",
|
||||
axis.CONF_PASSWORD: "password",
|
||||
axis.CONF_PORT: 80,
|
||||
axis.CONF_MAC: "mac",
|
||||
axis.device.CONF_MODEL: "model",
|
||||
axis.device.CONF_NAME: "name",
|
||||
}
|
||||
assert entry.version == 2
|
||||
Reference in new issue
Block a user