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
@@ -1,15 +1,23 @@
|
||||
"""Support for Axis devices."""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE,
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_TRIGGER_TIME,
|
||||
CONF_USERNAME,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
|
||||
from .const import CONF_CAMERA, CONF_EVENTS, DEFAULT_TRIGGER_TIME, DOMAIN
|
||||
from .device import AxisNetworkDevice, get_device
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Old way to set up Axis devices."""
|
||||
@@ -35,7 +43,7 @@ async def async_setup_entry(hass, config_entry):
|
||||
config_entry, unique_id=device.api.vapix.params.system_serialnumber
|
||||
)
|
||||
|
||||
hass.data[DOMAIN][device.serial] = device
|
||||
hass.data[DOMAIN][config_entry.unique_id] = device
|
||||
|
||||
await device.async_update_device_registry()
|
||||
|
||||
@@ -52,7 +60,13 @@ async def async_unload_entry(hass, config_entry):
|
||||
|
||||
async def async_populate_options(hass, config_entry):
|
||||
"""Populate default options for device."""
|
||||
device = await get_device(hass, config_entry.data[CONF_DEVICE])
|
||||
device = await get_device(
|
||||
hass,
|
||||
host=config_entry.data[CONF_HOST],
|
||||
port=config_entry.data[CONF_PORT],
|
||||
username=config_entry.data[CONF_USERNAME],
|
||||
password=config_entry.data[CONF_PASSWORD],
|
||||
)
|
||||
|
||||
supported_formats = device.vapix.params.image_format
|
||||
camera = bool(supported_formats)
|
||||
@@ -64,3 +78,18 @@ async def async_populate_options(hass, config_entry):
|
||||
}
|
||||
|
||||
hass.config_entries.async_update_entry(config_entry, options=options)
|
||||
|
||||
|
||||
async def async_migrate_entry(hass, config_entry):
|
||||
"""Migrate old entry."""
|
||||
LOGGER.debug("Migrating from version %s", config_entry.version)
|
||||
|
||||
# Flatten configuration but keep old data if user rollbacks HASS
|
||||
if config_entry.version == 1:
|
||||
config_entry.data = {**config_entry.data, **config_entry.data[CONF_DEVICE]}
|
||||
|
||||
config_entry.version = 2
|
||||
|
||||
LOGGER.info("Migration to version %s successful", config_entry.version)
|
||||
|
||||
return True
|
||||
Reference in new issue
Block a user