Add Ruckus Unleashed integration (#40002)

* Add Ruckus Unleashed integration

* Tweak catches to better rely on CoordinatorEntity error handling, rename LoginError to AuthenticationError

* Make router_update be a callback function

* Make name property return hint match the newer value

* Add entity to tracked set when restoring on boot

* Add a device's MAC to the attributes
This commit is contained in:
Gabe Cook 2020-10-10 06:01:53 -05:00 committed by GitHub
parent de300ddd56
commit 4b617db669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 690 additions and 0 deletions

View file

@ -0,0 +1,68 @@
"""Config flow for Ruckus Unleashed integration."""
from pyruckus import Ruckus
from pyruckus.exceptions import AuthenticationError
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from .const import _LOGGER, DOMAIN # pylint:disable=unused-import
DATA_SCHEMA = vol.Schema({"host": str, "username": str, "password": str})
async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
try:
ruckus = await hass.async_add_executor_job(
Ruckus, data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
)
except AuthenticationError as error:
raise InvalidAuth from error
except ConnectionError as error:
raise CannotConnect from error
mesh_name = ruckus.mesh_name()
return {"title": mesh_name}
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Ruckus Unleashed."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
await self.async_set_unique_id(user_input[CONF_HOST])
self._abort_if_unique_id_configured()
return self.async_create_entry(title=info["title"], data=user_input)
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)
class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""
class InvalidAuth(exceptions.HomeAssistantError):
"""Error to indicate there is invalid auth."""