hass-core/homeassistant/components/dynalite/config_flow.py
Ziv 39408ab240
Add cover platform to Dynalite (#32594)
* lib version

* unit-test refactoring

* added type hints

* added cover

* added test to see that consts have the same value as library consts

* Update tests/components/dynalite/test_init.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* removed trigger template

* Update homeassistant/components/dynalite/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/dynalite/const.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* removed CONF_TRIGGER from const
corrected type hints - not clear why mypy didn't catch it

* conversion of the config to library CONFs

* moved to use the value since it should come from the library

* taking CONF_HOST from homeassistant.const instead of module const

* use dict.get
removed leftover log

* force device_class to be from homeassistant consts

* move dict.get to inline

* removed CONF from values
changed "channelcover" to "channel_cover"

* moved some CONF values out of const.py and taking them from homeassistant.const

* verifying that device class is a valid HA device class

* moved shutter to home assistant const

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-04-02 20:26:36 +02:00

36 lines
1.4 KiB
Python
Executable file

"""Config flow to configure Dynalite hub."""
from typing import Any, Dict
from homeassistant import config_entries
from homeassistant.const import CONF_HOST
from .bridge import DynaliteBridge
from .const import DOMAIN, LOGGER
class DynaliteFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a Dynalite config flow."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
def __init__(self) -> None:
"""Initialize the Dynalite flow."""
self.host = None
async def async_step_import(self, import_info: Dict[str, Any]) -> Any:
"""Import a new bridge as a config entry."""
LOGGER.debug("Starting async_step_import - %s", import_info)
host = import_info[CONF_HOST]
for entry in self.hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == host:
if entry.data != import_info:
self.hass.config_entries.async_update_entry(entry, data=import_info)
return self.async_abort(reason="already_configured")
# New entry
bridge = DynaliteBridge(self.hass, import_info)
if not await bridge.async_setup():
LOGGER.error("Unable to setup bridge - import info=%s", import_info)
return self.async_abort(reason="no_connection")
LOGGER.debug("Creating entry for the bridge - %s", import_info)
return self.async_create_entry(title=host, data=import_info)