Merge UniFi device tracker to config entry (#24367)
* Move device tracker to use config entry * Remove monitored conditions attributes based on ADR0003 * Add support for import of device tracker config to be backwards compatible * Remove unnecessary configuration options from device tracker * Add component configuration support
This commit is contained in:
parent
3480e6229a
commit
01b890f426
11 changed files with 493 additions and 449 deletions
|
@ -7,9 +7,7 @@ from homeassistant.const import (
|
|||
|
||||
from .const import CONF_CONTROLLER, CONF_SITE_ID, DOMAIN, LOGGER
|
||||
from .controller import get_controller
|
||||
from .errors import (
|
||||
AlreadyConfigured, AuthenticationRequired, CannotConnect, UserLevel)
|
||||
|
||||
from .errors import AlreadyConfigured, AuthenticationRequired, CannotConnect
|
||||
|
||||
DEFAULT_PORT = 8443
|
||||
DEFAULT_SITE_ID = 'default'
|
||||
|
@ -44,6 +42,7 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
|
|||
CONF_VERIFY_SSL: user_input.get(CONF_VERIFY_SSL),
|
||||
CONF_SITE_ID: DEFAULT_SITE_ID,
|
||||
}
|
||||
|
||||
controller = await get_controller(self.hass, **self.config)
|
||||
|
||||
self.sites = await controller.sites()
|
||||
|
@ -80,14 +79,11 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
|
|||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
|
||||
try:
|
||||
desc = user_input.get(CONF_SITE_ID, self.desc)
|
||||
print(self.sites)
|
||||
|
||||
for site in self.sites.values():
|
||||
if desc == site['desc']:
|
||||
if site['role'] != 'admin':
|
||||
raise UserLevel
|
||||
self.config[CONF_SITE_ID] = site['name']
|
||||
break
|
||||
|
||||
|
@ -109,13 +105,16 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
|
|||
except AlreadyConfigured:
|
||||
return self.async_abort(reason='already_configured')
|
||||
|
||||
except UserLevel:
|
||||
return self.async_abort(reason='user_privilege')
|
||||
|
||||
if len(self.sites) == 1:
|
||||
self.desc = next(iter(self.sites.values()))['desc']
|
||||
return await self.async_step_site(user_input={})
|
||||
|
||||
if self.desc is not None:
|
||||
for site in self.sites.values():
|
||||
if self.desc == site['name']:
|
||||
self.desc = site['desc']
|
||||
return await self.async_step_site(user_input={})
|
||||
|
||||
sites = []
|
||||
for site in self.sites.values():
|
||||
sites.append(site['desc'])
|
||||
|
@ -127,3 +126,17 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
|
|||
}),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config):
|
||||
"""Import from UniFi device tracker config."""
|
||||
config = {
|
||||
CONF_HOST: import_config[CONF_HOST],
|
||||
CONF_USERNAME: import_config[CONF_USERNAME],
|
||||
CONF_PASSWORD: import_config[CONF_PASSWORD],
|
||||
CONF_PORT: import_config.get(CONF_PORT),
|
||||
CONF_VERIFY_SSL: import_config.get(CONF_VERIFY_SSL),
|
||||
}
|
||||
|
||||
self.desc = import_config[CONF_SITE_ID]
|
||||
|
||||
return await self.async_step_user(user_input=config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue