Add config entry for ZHA (#18352)
* Add support for zha config entries * Add support for zha config entries * Fix node_config retrieval * Dynamically load discovered entities * Restore device config support * Refactor loading of entities * Remove device registry support * Send discovery_info directly * Clean up discovery_info in hass.data * Update tests * Clean up rebase * Simplify config flow * Address comments * Fix config path and zigpy check timeout * Remove device entities when unloading config entry
This commit is contained in:
1 parent
43676fcaf4
commit
052d305243
14 files changed
+567
-135
No files matched your search
@@ -0,0 +1,57 @@
|
||||
"""Config flow for ZHA."""
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from .helpers import check_zigpy_connection
|
||||
from .const import (
|
||||
DOMAIN, CONF_RADIO_TYPE, CONF_USB_PATH, DEFAULT_DATABASE_NAME, RadioType
|
||||
)
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register(DOMAIN)
|
||||
class ZhaFlowHandler(config_entries.ConfigFlow):
|
||||
"""Handle a config flow."""
|
||||
|
||||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle a zha config flow start."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason='single_instance_allowed')
|
||||
|
||||
errors = {}
|
||||
|
||||
fields = OrderedDict()
|
||||
fields[vol.Required(CONF_USB_PATH)] = str
|
||||
fields[vol.Optional(CONF_RADIO_TYPE, default='ezsp')] = vol.In(
|
||||
RadioType.list()
|
||||
)
|
||||
|
||||
if user_input is not None:
|
||||
database = os.path.join(self.hass.config.config_dir,
|
||||
DEFAULT_DATABASE_NAME)
|
||||
test = await check_zigpy_connection(user_input[CONF_USB_PATH],
|
||||
user_input[CONF_RADIO_TYPE],
|
||||
database)
|
||||
if test:
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_USB_PATH], data=user_input)
|
||||
errors['base'] = 'cannot_connect'
|
||||
|
||||
return self.async_show_form(
|
||||
step_id='user', data_schema=vol.Schema(fields), errors=errors
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_info):
|
||||
"""Handle a zha config import."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason='single_instance_allowed')
|
||||
|
||||
return self.async_create_entry(
|
||||
title=import_info[CONF_USB_PATH],
|
||||
data=import_info
|
||||
)
|
||||
Reference in new issue
Block a user