Axis - Code improvements (#35592)

* Adapt library improvements
Clean up integration and tests and make them more like latest changes in UniFi integration

* Bump dependency to v26
This commit is contained in:
Robert Svensson authored and GitHub committed 2020-05-14 10:49:27 +02:00
1 parent cf50ccb919
commit e6c58c9795
16 files changed
+323 -307

No files matched your search

+39 -40
View File
@@ -1,5 +1,15 @@
"""Test Axis component setup process."""
from homeassistant.components import axis
from homeassistant.components.axis.const import CONF_MODEL, DOMAIN as AXIS_DOMAIN
from homeassistant.const import (
CONF_DEVICE,
CONF_HOST,
CONF_MAC,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
)
from homeassistant.setup import async_setup_component
from .test_device import MAC, setup_axis_integration
@@ -10,21 +20,21 @@ from tests.common import MockConfigEntry
async def test_setup_no_config(hass):
"""Test setup without configuration."""
assert await async_setup_component(hass, axis.DOMAIN, {})
assert axis.DOMAIN not in hass.data
assert await async_setup_component(hass, AXIS_DOMAIN, {})
assert AXIS_DOMAIN not in hass.data
async def test_setup_entry(hass):
"""Test successful setup of entry."""
await setup_axis_integration(hass)
assert len(hass.data[axis.DOMAIN]) == 1
assert MAC in hass.data[axis.DOMAIN]
assert len(hass.data[AXIS_DOMAIN]) == 1
assert MAC in hass.data[AXIS_DOMAIN]
async def test_setup_entry_fails(hass):
"""Test successful setup of entry."""
config_entry = MockConfigEntry(
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, version=2
domain=AXIS_DOMAIN, data={CONF_MAC: "0123"}, version=2
)
config_entry.add_to_hass(hass)
@@ -36,43 +46,32 @@ async def test_setup_entry_fails(hass):
assert not await hass.config_entries.async_setup(config_entry.entry_id)
assert not hass.data[axis.DOMAIN]
assert not hass.data[AXIS_DOMAIN]
async def test_unload_entry(hass):
"""Test successful unload of entry."""
device = await setup_axis_integration(hass)
assert hass.data[axis.DOMAIN]
assert hass.data[AXIS_DOMAIN]
assert await hass.config_entries.async_unload(device.config_entry.entry_id)
assert not hass.data[axis.DOMAIN]
async def test_populate_options(hass):
"""Test successful populate options."""
device = await setup_axis_integration(hass, options=None)
assert device.config_entry.options == {
axis.CONF_CAMERA: True,
axis.CONF_EVENTS: True,
axis.CONF_TRIGGER_TIME: axis.DEFAULT_TRIGGER_TIME,
}
assert not hass.data[AXIS_DOMAIN]
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,
CONF_DEVICE: {
CONF_HOST: "1.2.3.4",
CONF_USERNAME: "username",
CONF_PASSWORD: "password",
CONF_PORT: 80,
},
axis.CONF_MAC: "mac",
axis.device.CONF_MODEL: "model",
axis.device.CONF_NAME: "name",
CONF_MAC: "mac",
CONF_MODEL: "model",
CONF_NAME: "name",
}
entry = MockConfigEntry(domain=axis.DOMAIN, data=legacy_config)
entry = MockConfigEntry(domain=AXIS_DOMAIN, data=legacy_config)
assert entry.data == legacy_config
assert entry.version == 1
@@ -80,18 +79,18 @@ async def test_migrate_entry(hass):
await entry.async_migrate(hass)
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,
CONF_DEVICE: {
CONF_HOST: "1.2.3.4",
CONF_USERNAME: "username",
CONF_PASSWORD: "password",
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",
CONF_HOST: "1.2.3.4",
CONF_USERNAME: "username",
CONF_PASSWORD: "password",
CONF_PORT: 80,
CONF_MAC: "mac",
CONF_MODEL: "model",
CONF_NAME: "name",
}
assert entry.version == 2