Fix Ruckus Unleashed SSH connection failures (#75032)

This commit is contained in:
Gabe Cook 2022-07-12 09:06:38 -05:00 committed by GitHub
parent 5fdae0fc5b
commit 5489b2111a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 19 deletions

View File

@ -29,8 +29,7 @@ from .coordinator import RuckusUnleashedDataUpdateCoordinator
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Ruckus Unleashed from a config entry.""" """Set up Ruckus Unleashed from a config entry."""
try: try:
ruckus = await hass.async_add_executor_job( ruckus = await Ruckus.create(
Ruckus,
entry.data[CONF_HOST], entry.data[CONF_HOST],
entry.data[CONF_USERNAME], entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD], entry.data[CONF_PASSWORD],
@ -42,10 +41,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
system_info = await hass.async_add_executor_job(ruckus.system_info) system_info = await ruckus.system_info()
registry = device_registry.async_get(hass) registry = device_registry.async_get(hass)
ap_info = await hass.async_add_executor_job(ruckus.ap_info) ap_info = await ruckus.ap_info()
for device in ap_info[API_AP][API_ID].values(): for device in ap_info[API_AP][API_ID].values():
registry.async_get_or_create( registry.async_get_or_create(
config_entry_id=entry.entry_id, config_entry_id=entry.entry_id,

View File

@ -21,22 +21,24 @@ DATA_SCHEMA = vol.Schema(
) )
def validate_input(hass: core.HomeAssistant, data): async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect. """Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user. Data has the keys from DATA_SCHEMA with values provided by the user.
""" """
try: try:
ruckus = Ruckus(data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]) ruckus = await Ruckus.create(
data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
)
except AuthenticationError as error: except AuthenticationError as error:
raise InvalidAuth from error raise InvalidAuth from error
except ConnectionError as error: except ConnectionError as error:
raise CannotConnect from error raise CannotConnect from error
mesh_name = ruckus.mesh_name() mesh_name = await ruckus.mesh_name()
system_info = ruckus.system_info() system_info = await ruckus.system_info()
try: try:
host_serial = system_info[API_SYSTEM_OVERVIEW][API_SERIAL] host_serial = system_info[API_SYSTEM_OVERVIEW][API_SERIAL]
except KeyError as error: except KeyError as error:
@ -58,9 +60,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors = {} errors = {}
if user_input is not None: if user_input is not None:
try: try:
info = await self.hass.async_add_executor_job( info = await validate_input(self.hass, user_input)
validate_input, self.hass, user_input
)
except CannotConnect: except CannotConnect:
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
except InvalidAuth: except InvalidAuth:

View File

@ -37,9 +37,7 @@ class RuckusUnleashedDataUpdateCoordinator(DataUpdateCoordinator):
async def _fetch_clients(self) -> dict: async def _fetch_clients(self) -> dict:
"""Fetch clients from the API and format them.""" """Fetch clients from the API and format them."""
clients = await self.hass.async_add_executor_job( clients = await self.ruckus.current_active_clients()
self.ruckus.current_active_clients
)
return {e[API_MAC]: e for e in clients[API_CURRENT_ACTIVE_CLIENTS][API_CLIENTS]} return {e[API_MAC]: e for e in clients[API_CURRENT_ACTIVE_CLIENTS][API_CLIENTS]}
async def _async_update_data(self) -> dict: async def _async_update_data(self) -> dict:

View File

@ -3,7 +3,7 @@
"name": "Ruckus Unleashed", "name": "Ruckus Unleashed",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/ruckus_unleashed", "documentation": "https://www.home-assistant.io/integrations/ruckus_unleashed",
"requirements": ["pyruckus==0.12"], "requirements": ["pyruckus==0.16"],
"codeowners": ["@gabe565"], "codeowners": ["@gabe565"],
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pexpect", "pyruckus"] "loggers": ["pexpect", "pyruckus"]

View File

@ -1783,7 +1783,7 @@ pyrisco==0.3.1
pyrituals==0.0.6 pyrituals==0.0.6
# homeassistant.components.ruckus_unleashed # homeassistant.components.ruckus_unleashed
pyruckus==0.12 pyruckus==0.16
# homeassistant.components.sabnzbd # homeassistant.components.sabnzbd
pysabnzbd==1.1.1 pysabnzbd==1.1.1

View File

@ -1217,7 +1217,7 @@ pyrisco==0.3.1
pyrituals==0.0.6 pyrituals==0.0.6
# homeassistant.components.ruckus_unleashed # homeassistant.components.ruckus_unleashed
pyruckus==0.12 pyruckus==0.16
# homeassistant.components.sabnzbd # homeassistant.components.sabnzbd
pysabnzbd==1.1.1 pysabnzbd==1.1.1

View File

@ -31,7 +31,7 @@ async def test_setup_entry_login_error(hass):
"""Test entry setup failed due to login error.""" """Test entry setup failed due to login error."""
entry = mock_config_entry() entry = mock_config_entry()
with patch( with patch(
"homeassistant.components.ruckus_unleashed.Ruckus", "homeassistant.components.ruckus_unleashed.Ruckus.connect",
side_effect=AuthenticationError, side_effect=AuthenticationError,
): ):
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -45,7 +45,7 @@ async def test_setup_entry_connection_error(hass):
"""Test entry setup failed due to connection error.""" """Test entry setup failed due to connection error."""
entry = mock_config_entry() entry = mock_config_entry()
with patch( with patch(
"homeassistant.components.ruckus_unleashed.Ruckus", "homeassistant.components.ruckus_unleashed.Ruckus.connect",
side_effect=ConnectionError, side_effect=ConnectionError,
): ):
entry.add_to_hass(hass) entry.add_to_hass(hass)