Fix ruckus_unleashed for python 3.11 (#94835)
Co-authored-by: Tony <29752086+ms264556@users.noreply.github.com>
This commit is contained in:
parent
739eeeccb0
commit
ef7a246f09
13 changed files with 430 additions and 299 deletions
|
@ -1057,8 +1057,8 @@ build.json @home-assistant/supervisor
|
||||||
/tests/components/rss_feed_template/ @home-assistant/core
|
/tests/components/rss_feed_template/ @home-assistant/core
|
||||||
/homeassistant/components/rtsp_to_webrtc/ @allenporter
|
/homeassistant/components/rtsp_to_webrtc/ @allenporter
|
||||||
/tests/components/rtsp_to_webrtc/ @allenporter
|
/tests/components/rtsp_to_webrtc/ @allenporter
|
||||||
/homeassistant/components/ruckus_unleashed/ @gabe565
|
/homeassistant/components/ruckus_unleashed/ @gabe565 @lanrat
|
||||||
/tests/components/ruckus_unleashed/ @gabe565
|
/tests/components/ruckus_unleashed/ @gabe565 @lanrat
|
||||||
/homeassistant/components/ruuvi_gateway/ @akx
|
/homeassistant/components/ruuvi_gateway/ @akx
|
||||||
/tests/components/ruuvi_gateway/ @akx
|
/tests/components/ruuvi_gateway/ @akx
|
||||||
/homeassistant/components/ruuvitag_ble/ @akx
|
/homeassistant/components/ruuvitag_ble/ @akx
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
"""The Ruckus Unleashed integration."""
|
"""The Ruckus Unleashed integration."""
|
||||||
|
import logging
|
||||||
|
|
||||||
from pyruckus import Ruckus
|
from aioruckus import AjaxSession
|
||||||
|
from aioruckus.exceptions import AuthenticationError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
API_AP,
|
API_AP_DEVNAME,
|
||||||
API_DEVICE_NAME,
|
API_AP_FIRMWAREVERSION,
|
||||||
API_ID,
|
API_AP_MAC,
|
||||||
API_MAC,
|
API_AP_MODEL,
|
||||||
API_MODEL,
|
API_SYS_SYSINFO,
|
||||||
API_SYSTEM_OVERVIEW,
|
API_SYS_SYSINFO_VERSION,
|
||||||
API_VERSION,
|
|
||||||
COORDINATOR,
|
COORDINATOR,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
MANUFACTURER,
|
MANUFACTURER,
|
||||||
|
@ -24,35 +25,45 @@ from .const import (
|
||||||
)
|
)
|
||||||
from .coordinator import RuckusUnleashedDataUpdateCoordinator
|
from .coordinator import RuckusUnleashedDataUpdateCoordinator
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
|
|
||||||
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 Ruckus.create(
|
ruckus = AjaxSession.async_create(
|
||||||
entry.data[CONF_HOST],
|
entry.data[CONF_HOST],
|
||||||
entry.data[CONF_USERNAME],
|
entry.data[CONF_USERNAME],
|
||||||
entry.data[CONF_PASSWORD],
|
entry.data[CONF_PASSWORD],
|
||||||
)
|
)
|
||||||
except ConnectionError as error:
|
await ruckus.login()
|
||||||
raise ConfigEntryNotReady from error
|
except (ConnectionRefusedError, ConnectionError) as conerr:
|
||||||
|
raise ConfigEntryNotReady from conerr
|
||||||
|
except AuthenticationError as autherr:
|
||||||
|
raise ConfigEntryAuthFailed from autherr
|
||||||
|
|
||||||
coordinator = RuckusUnleashedDataUpdateCoordinator(hass, ruckus=ruckus)
|
coordinator = RuckusUnleashedDataUpdateCoordinator(hass, ruckus=ruckus)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
system_info = await ruckus.system_info()
|
system_info = await ruckus.api.get_system_info()
|
||||||
|
|
||||||
registry = dr.async_get(hass)
|
registry = dr.async_get(hass)
|
||||||
ap_info = await ruckus.ap_info()
|
aps = await ruckus.api.get_aps()
|
||||||
for device in ap_info[API_AP][API_ID].values():
|
for access_point in aps:
|
||||||
|
_LOGGER.debug("AP [%s] %s", access_point[API_AP_MAC], entry.entry_id)
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device[API_MAC])},
|
connections={(dr.CONNECTION_NETWORK_MAC, access_point[API_AP_MAC])},
|
||||||
identifiers={(dr.CONNECTION_NETWORK_MAC, device[API_MAC])},
|
identifiers={(DOMAIN, access_point[API_AP_MAC])},
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
name=device[API_DEVICE_NAME],
|
name=access_point[API_AP_DEVNAME],
|
||||||
model=device[API_MODEL],
|
model=access_point[API_AP_MODEL],
|
||||||
sw_version=system_info[API_SYSTEM_OVERVIEW][API_VERSION],
|
sw_version=access_point.get(
|
||||||
|
API_AP_FIRMWAREVERSION,
|
||||||
|
system_info[API_SYS_SYSINFO][API_SYS_SYSINFO_VERSION],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
@ -68,11 +79,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
for listener in hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENERS]:
|
for listener in hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENERS]:
|
||||||
listener()
|
listener()
|
||||||
|
await hass.data[DOMAIN][entry.entry_id][COORDINATOR].ruckus.close()
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
|
@ -1,22 +1,29 @@
|
||||||
"""Config flow for Ruckus Unleashed integration."""
|
"""Config flow for Ruckus Unleashed integration."""
|
||||||
import logging
|
from collections.abc import Mapping
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pyruckus import Ruckus
|
from aioruckus import AjaxSession, SystemStat
|
||||||
from pyruckus.exceptions import AuthenticationError
|
from aioruckus.exceptions import AuthenticationError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, core, exceptions
|
from homeassistant import config_entries, core, exceptions
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import API_SERIAL, API_SYSTEM_OVERVIEW, DOMAIN
|
from .const import (
|
||||||
|
API_MESH_NAME,
|
||||||
_LOGGER = logging.getLogger(__package__)
|
API_SYS_SYSINFO,
|
||||||
|
API_SYS_SYSINFO_SERIAL,
|
||||||
|
DOMAIN,
|
||||||
|
KEY_SYS_SERIAL,
|
||||||
|
KEY_SYS_TITLE,
|
||||||
|
)
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema(
|
DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("host"): str,
|
vol.Required(CONF_HOST): str,
|
||||||
vol.Required("username"): str,
|
vol.Required(CONF_USERNAME): str,
|
||||||
vol.Required("password"): str,
|
vol.Required(CONF_PASSWORD): str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,26 +35,22 @@ async def validate_input(hass: core.HomeAssistant, data):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ruckus = await Ruckus.create(
|
async with AjaxSession.async_create(
|
||||||
data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
|
data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
|
||||||
|
) as ruckus:
|
||||||
|
system_info = await ruckus.api.get_system_info(
|
||||||
|
SystemStat.SYSINFO,
|
||||||
)
|
)
|
||||||
except AuthenticationError as error:
|
mesh_name = (await ruckus.api.get_mesh_info())[API_MESH_NAME]
|
||||||
raise InvalidAuth from error
|
zd_serial = system_info[API_SYS_SYSINFO][API_SYS_SYSINFO_SERIAL]
|
||||||
except ConnectionError as error:
|
|
||||||
raise CannotConnect from error
|
|
||||||
|
|
||||||
mesh_name = await ruckus.mesh_name()
|
|
||||||
|
|
||||||
system_info = await ruckus.system_info()
|
|
||||||
try:
|
|
||||||
host_serial = system_info[API_SYSTEM_OVERVIEW][API_SERIAL]
|
|
||||||
except KeyError as error:
|
|
||||||
raise CannotConnect from error
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": mesh_name,
|
KEY_SYS_TITLE: mesh_name,
|
||||||
"serial": host_serial,
|
KEY_SYS_SERIAL: zd_serial,
|
||||||
}
|
}
|
||||||
|
except AuthenticationError as autherr:
|
||||||
|
raise InvalidAuth from autherr
|
||||||
|
except (ConnectionRefusedError, ConnectionError, KeyError) as connerr:
|
||||||
|
raise CannotConnect from connerr
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
@ -55,7 +58,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
errors = {}
|
errors = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
|
@ -65,18 +70,32 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except InvalidAuth:
|
except InvalidAuth:
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
_LOGGER.exception("Unexpected exception")
|
|
||||||
errors["base"] = "unknown"
|
|
||||||
else:
|
else:
|
||||||
await self.async_set_unique_id(info["serial"])
|
await self.async_set_unique_id(info[KEY_SYS_SERIAL])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(title=info["title"], data=user_input)
|
return self.async_create_entry(
|
||||||
|
title=info[KEY_SYS_TITLE], data=user_input
|
||||||
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
||||||
|
"""Perform reauth upon an API authentication error."""
|
||||||
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Dialog that informs the user that reauth is required."""
|
||||||
|
if user_input is None:
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="reauth_confirm",
|
||||||
|
data_schema=DATA_SCHEMA,
|
||||||
|
)
|
||||||
|
return await self.async_step_user()
|
||||||
|
|
||||||
|
|
||||||
class CannotConnect(exceptions.HomeAssistantError):
|
class CannotConnect(exceptions.HomeAssistantError):
|
||||||
"""Error to indicate we cannot connect."""
|
"""Error to indicate we cannot connect."""
|
||||||
|
|
|
@ -3,23 +3,35 @@ from homeassistant.const import Platform
|
||||||
|
|
||||||
DOMAIN = "ruckus_unleashed"
|
DOMAIN = "ruckus_unleashed"
|
||||||
PLATFORMS = [Platform.DEVICE_TRACKER]
|
PLATFORMS = [Platform.DEVICE_TRACKER]
|
||||||
SCAN_INTERVAL = 180
|
SCAN_INTERVAL = 30
|
||||||
|
|
||||||
MANUFACTURER = "Ruckus"
|
MANUFACTURER = "Ruckus"
|
||||||
|
|
||||||
COORDINATOR = "coordinator"
|
COORDINATOR = "coordinator"
|
||||||
UNDO_UPDATE_LISTENERS = "undo_update_listeners"
|
UNDO_UPDATE_LISTENERS = "undo_update_listeners"
|
||||||
|
|
||||||
API_CLIENTS = "clients"
|
KEY_SYS_CLIENTS = "clients"
|
||||||
API_NAME = "host_name"
|
KEY_SYS_TITLE = "title"
|
||||||
API_MAC = "mac_address"
|
KEY_SYS_SERIAL = "serial"
|
||||||
API_IP = "user_ip"
|
|
||||||
API_SYSTEM_OVERVIEW = "system_overview"
|
API_MESH_NAME = "name"
|
||||||
API_SERIAL = "serial_number"
|
API_MESH_PSK = "psk"
|
||||||
API_DEVICE_NAME = "device_name"
|
|
||||||
API_MODEL = "model"
|
API_CLIENT_HOSTNAME = "hostname"
|
||||||
API_VERSION = "version"
|
API_CLIENT_MAC = "mac"
|
||||||
API_AP = "ap"
|
API_CLIENT_IP = "ip"
|
||||||
API_ID = "id"
|
API_CLIENT_AP_MAC = "ap"
|
||||||
API_CURRENT_ACTIVE_CLIENTS = "current_active_clients"
|
|
||||||
API_ACCESS_POINT = "access_point"
|
API_AP_MAC = "mac"
|
||||||
|
API_AP_SERIALNUMBER = "serial"
|
||||||
|
API_AP_DEVNAME = "devname"
|
||||||
|
API_AP_MODEL = "model"
|
||||||
|
API_AP_FIRMWAREVERSION = "version"
|
||||||
|
|
||||||
|
API_SYS_SYSINFO = "sysinfo"
|
||||||
|
API_SYS_SYSINFO_VERSION = "version"
|
||||||
|
API_SYS_SYSINFO_SERIAL = "serial"
|
||||||
|
API_SYS_IDENTITY = "identity"
|
||||||
|
API_SYS_IDENTITY_NAME = "name"
|
||||||
|
API_SYS_UNLEASHEDNETWORK = "unleashed-network"
|
||||||
|
API_SYS_UNLEASHEDNETWORK_TOKEN = "unleashed-network-token"
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyruckus import Ruckus
|
from aioruckus import AjaxSession
|
||||||
from pyruckus.exceptions import AuthenticationError
|
from aioruckus.exceptions import AuthenticationError
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import (
|
from .const import API_CLIENT_MAC, DOMAIN, KEY_SYS_CLIENTS, SCAN_INTERVAL
|
||||||
API_CLIENTS,
|
|
||||||
API_CURRENT_ACTIVE_CLIENTS,
|
|
||||||
API_MAC,
|
|
||||||
DOMAIN,
|
|
||||||
SCAN_INTERVAL,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__package__)
|
_LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
|
@ -22,7 +16,7 @@ _LOGGER = logging.getLogger(__package__)
|
||||||
class RuckusUnleashedDataUpdateCoordinator(DataUpdateCoordinator):
|
class RuckusUnleashedDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
"""Coordinator to manage data from Ruckus Unleashed client."""
|
"""Coordinator to manage data from Ruckus Unleashed client."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, *, ruckus: Ruckus) -> None:
|
def __init__(self, hass: HomeAssistant, *, ruckus: AjaxSession) -> None:
|
||||||
"""Initialize global Ruckus Unleashed data updater."""
|
"""Initialize global Ruckus Unleashed data updater."""
|
||||||
self.ruckus = ruckus
|
self.ruckus = ruckus
|
||||||
|
|
||||||
|
@ -37,12 +31,15 @@ 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.ruckus.current_active_clients()
|
clients = await self.ruckus.api.get_active_clients()
|
||||||
return {e[API_MAC]: e for e in clients[API_CURRENT_ACTIVE_CLIENTS][API_CLIENTS]}
|
_LOGGER.debug("fetched %d active clients", len(clients))
|
||||||
|
return {client[API_CLIENT_MAC]: client for client in clients}
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict:
|
async def _async_update_data(self) -> dict:
|
||||||
"""Fetch Ruckus Unleashed data."""
|
"""Fetch Ruckus Unleashed data."""
|
||||||
try:
|
try:
|
||||||
return {API_CLIENTS: await self._fetch_clients()}
|
return {KEY_SYS_CLIENTS: await self._fetch_clients()}
|
||||||
except (AuthenticationError, ConnectionError) as error:
|
except AuthenticationError as autherror:
|
||||||
raise UpdateFailed(error) from error
|
raise UpdateFailed(autherror) from autherror
|
||||||
|
except (ConnectionRefusedError, ConnectionError) as conerr:
|
||||||
|
raise UpdateFailed(conerr) from conerr
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Support for Ruckus Unleashed devices."""
|
"""Support for Ruckus Unleashed devices."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import ScannerEntity, SourceType
|
from homeassistant.components.device_tracker import ScannerEntity, SourceType
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
@ -9,14 +11,16 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
API_CLIENTS,
|
API_CLIENT_HOSTNAME,
|
||||||
API_NAME,
|
API_CLIENT_IP,
|
||||||
COORDINATOR,
|
COORDINATOR,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
MANUFACTURER,
|
KEY_SYS_CLIENTS,
|
||||||
UNDO_UPDATE_LISTENERS,
|
UNDO_UPDATE_LISTENERS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
@ -46,12 +50,15 @@ def add_new_entities(coordinator, async_add_entities, tracked):
|
||||||
"""Add new tracker entities from the router."""
|
"""Add new tracker entities from the router."""
|
||||||
new_tracked = []
|
new_tracked = []
|
||||||
|
|
||||||
for mac in coordinator.data[API_CLIENTS]:
|
for mac in coordinator.data[KEY_SYS_CLIENTS]:
|
||||||
if mac in tracked:
|
if mac in tracked:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
device = coordinator.data[API_CLIENTS][mac]
|
device = coordinator.data[KEY_SYS_CLIENTS][mac]
|
||||||
new_tracked.append(RuckusUnleashedDevice(coordinator, mac, device[API_NAME]))
|
_LOGGER.debug("adding new device: [%s] %s", mac, device[API_CLIENT_HOSTNAME])
|
||||||
|
new_tracked.append(
|
||||||
|
RuckusUnleashedDevice(coordinator, mac, device[API_CLIENT_HOSTNAME])
|
||||||
|
)
|
||||||
tracked.add(mac)
|
tracked.add(mac)
|
||||||
|
|
||||||
async_add_entities(new_tracked)
|
async_add_entities(new_tracked)
|
||||||
|
@ -66,7 +73,7 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
|
||||||
if (
|
if (
|
||||||
entity.config_entry_id == entry.entry_id
|
entity.config_entry_id == entry.entry_id
|
||||||
and entity.platform == DOMAIN
|
and entity.platform == DOMAIN
|
||||||
and entity.unique_id not in coordinator.data[API_CLIENTS]
|
and entity.unique_id not in coordinator.data[KEY_SYS_CLIENTS]
|
||||||
):
|
):
|
||||||
missing.append(
|
missing.append(
|
||||||
RuckusUnleashedDevice(
|
RuckusUnleashedDevice(
|
||||||
|
@ -75,6 +82,7 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
|
||||||
)
|
)
|
||||||
tracked.add(entity.unique_id)
|
tracked.add(entity.unique_id)
|
||||||
|
|
||||||
|
_LOGGER.debug("added %d missing devices", len(missing))
|
||||||
async_add_entities(missing)
|
async_add_entities(missing)
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,17 +103,25 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
if self.is_connected:
|
|
||||||
return (
|
return (
|
||||||
self.coordinator.data[API_CLIENTS][self._mac][API_NAME]
|
self._name
|
||||||
or f"{MANUFACTURER} {self._mac}"
|
if not self.is_connected
|
||||||
|
else self.coordinator.data[KEY_SYS_CLIENTS][self._mac][API_CLIENT_HOSTNAME]
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ip_address(self) -> str:
|
||||||
|
"""Return the ip address."""
|
||||||
|
return (
|
||||||
|
self.coordinator.data[KEY_SYS_CLIENTS][self._mac][API_CLIENT_IP]
|
||||||
|
if self.is_connected
|
||||||
|
else None
|
||||||
)
|
)
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""Return true if the device is connected to the network."""
|
"""Return true if the device is connected to the network."""
|
||||||
return self._mac in self.coordinator.data[API_CLIENTS]
|
return self._mac in self.coordinator.data[KEY_SYS_CLIENTS]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> SourceType:
|
def source_type(self) -> SourceType:
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"domain": "ruckus_unleashed",
|
"domain": "ruckus_unleashed",
|
||||||
"name": "Ruckus Unleashed",
|
"name": "Ruckus Unleashed",
|
||||||
"codeowners": ["@gabe565"],
|
"codeowners": ["@gabe565", "@lanrat"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/ruckus_unleashed",
|
"documentation": "https://www.home-assistant.io/integrations/ruckus_unleashed",
|
||||||
|
"integration_type": "hub",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["pexpect", "pyruckus"],
|
"loggers": ["aioruckus", "xmltodict"],
|
||||||
"requirements": ["pyruckus==0.16"]
|
"requirements": ["aioruckus==0.31", "xmltodict==0.13.0"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,9 @@ aiorecollect==1.0.8
|
||||||
# homeassistant.components.ridwell
|
# homeassistant.components.ridwell
|
||||||
aioridwell==2023.07.0
|
aioridwell==2023.07.0
|
||||||
|
|
||||||
|
# homeassistant.components.ruckus_unleashed
|
||||||
|
aioruckus==0.31
|
||||||
|
|
||||||
# homeassistant.components.ruuvi_gateway
|
# homeassistant.components.ruuvi_gateway
|
||||||
aioruuvigateway==0.1.0
|
aioruuvigateway==0.1.0
|
||||||
|
|
||||||
|
@ -1975,9 +1978,6 @@ pyrituals==0.0.6
|
||||||
# homeassistant.components.thread
|
# homeassistant.components.thread
|
||||||
pyroute2==0.7.5
|
pyroute2==0.7.5
|
||||||
|
|
||||||
# homeassistant.components.ruckus_unleashed
|
|
||||||
pyruckus==0.16
|
|
||||||
|
|
||||||
# homeassistant.components.rympro
|
# homeassistant.components.rympro
|
||||||
pyrympro==0.0.7
|
pyrympro==0.0.7
|
||||||
|
|
||||||
|
@ -2719,6 +2719,7 @@ xknxproject==3.2.0
|
||||||
# homeassistant.components.bluesound
|
# homeassistant.components.bluesound
|
||||||
# homeassistant.components.fritz
|
# homeassistant.components.fritz
|
||||||
# homeassistant.components.rest
|
# homeassistant.components.rest
|
||||||
|
# homeassistant.components.ruckus_unleashed
|
||||||
# homeassistant.components.startca
|
# homeassistant.components.startca
|
||||||
# homeassistant.components.ted5000
|
# homeassistant.components.ted5000
|
||||||
# homeassistant.components.zestimate
|
# homeassistant.components.zestimate
|
||||||
|
|
|
@ -307,6 +307,9 @@ aiorecollect==1.0.8
|
||||||
# homeassistant.components.ridwell
|
# homeassistant.components.ridwell
|
||||||
aioridwell==2023.07.0
|
aioridwell==2023.07.0
|
||||||
|
|
||||||
|
# homeassistant.components.ruckus_unleashed
|
||||||
|
aioruckus==0.31
|
||||||
|
|
||||||
# homeassistant.components.ruuvi_gateway
|
# homeassistant.components.ruuvi_gateway
|
||||||
aioruuvigateway==0.1.0
|
aioruuvigateway==0.1.0
|
||||||
|
|
||||||
|
@ -1467,9 +1470,6 @@ pyrituals==0.0.6
|
||||||
# homeassistant.components.thread
|
# homeassistant.components.thread
|
||||||
pyroute2==0.7.5
|
pyroute2==0.7.5
|
||||||
|
|
||||||
# homeassistant.components.ruckus_unleashed
|
|
||||||
pyruckus==0.16
|
|
||||||
|
|
||||||
# homeassistant.components.rympro
|
# homeassistant.components.rympro
|
||||||
pyrympro==0.0.7
|
pyrympro==0.0.7
|
||||||
|
|
||||||
|
@ -2001,6 +2001,7 @@ xknxproject==3.2.0
|
||||||
# homeassistant.components.bluesound
|
# homeassistant.components.bluesound
|
||||||
# homeassistant.components.fritz
|
# homeassistant.components.fritz
|
||||||
# homeassistant.components.rest
|
# homeassistant.components.rest
|
||||||
|
# homeassistant.components.ruckus_unleashed
|
||||||
# homeassistant.components.startca
|
# homeassistant.components.startca
|
||||||
# homeassistant.components.ted5000
|
# homeassistant.components.ted5000
|
||||||
# homeassistant.components.zestimate
|
# homeassistant.components.zestimate
|
||||||
|
|
|
@ -1,45 +1,61 @@
|
||||||
"""Tests for the Ruckus Unleashed integration."""
|
"""Tests for the Ruckus Unleashed integration."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
from aioruckus import AjaxSession, RuckusAjaxApi
|
||||||
|
|
||||||
from homeassistant.components.ruckus_unleashed import DOMAIN
|
|
||||||
from homeassistant.components.ruckus_unleashed.const import (
|
from homeassistant.components.ruckus_unleashed.const import (
|
||||||
API_ACCESS_POINT,
|
API_AP_DEVNAME,
|
||||||
API_AP,
|
API_AP_MAC,
|
||||||
API_DEVICE_NAME,
|
API_AP_MODEL,
|
||||||
API_ID,
|
API_AP_SERIALNUMBER,
|
||||||
API_IP,
|
API_CLIENT_AP_MAC,
|
||||||
API_MAC,
|
API_CLIENT_HOSTNAME,
|
||||||
API_MODEL,
|
API_CLIENT_IP,
|
||||||
API_NAME,
|
API_CLIENT_MAC,
|
||||||
API_SERIAL,
|
API_MESH_NAME,
|
||||||
API_SYSTEM_OVERVIEW,
|
API_MESH_PSK,
|
||||||
API_VERSION,
|
API_SYS_IDENTITY,
|
||||||
|
API_SYS_IDENTITY_NAME,
|
||||||
|
API_SYS_SYSINFO,
|
||||||
|
API_SYS_SYSINFO_SERIAL,
|
||||||
|
API_SYS_SYSINFO_VERSION,
|
||||||
|
API_SYS_UNLEASHEDNETWORK,
|
||||||
|
API_SYS_UNLEASHEDNETWORK_TOKEN,
|
||||||
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
DEFAULT_TITLE = "Ruckus Mesh"
|
|
||||||
DEFAULT_UNIQUE_ID = "123456789012"
|
|
||||||
DEFAULT_SYSTEM_INFO = {
|
DEFAULT_SYSTEM_INFO = {
|
||||||
API_SYSTEM_OVERVIEW: {
|
API_SYS_IDENTITY: {API_SYS_IDENTITY_NAME: "RuckusUnleashed"},
|
||||||
API_SERIAL: DEFAULT_UNIQUE_ID,
|
API_SYS_SYSINFO: {
|
||||||
API_VERSION: "v1.0.0",
|
API_SYS_SYSINFO_SERIAL: "123456789012",
|
||||||
}
|
API_SYS_SYSINFO_VERSION: "200.7.10.202 build 141",
|
||||||
|
},
|
||||||
|
API_SYS_UNLEASHEDNETWORK: {
|
||||||
|
API_SYS_UNLEASHEDNETWORK_TOKEN: "un1234567890121680060227001"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
DEFAULT_AP_INFO = {
|
|
||||||
API_AP: {
|
DEFAULT_MESH_INFO = {
|
||||||
API_ID: {
|
API_MESH_NAME: "Ruckus Mesh",
|
||||||
"1": {
|
API_MESH_PSK: "",
|
||||||
API_MAC: "00:11:22:33:44:55",
|
|
||||||
API_DEVICE_NAME: "Test Device",
|
|
||||||
API_MODEL: "r510",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_AP_INFO = [
|
||||||
|
{
|
||||||
|
API_AP_MAC: "00:11:22:33:44:55",
|
||||||
|
API_AP_DEVNAME: "Test Device",
|
||||||
|
API_AP_MODEL: "r510",
|
||||||
|
API_AP_SERIALNUMBER: DEFAULT_SYSTEM_INFO[API_SYS_SYSINFO][
|
||||||
|
API_SYS_SYSINFO_SERIAL
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
CONF_HOST: "1.1.1.1",
|
CONF_HOST: "1.1.1.1",
|
||||||
CONF_USERNAME: "test-username",
|
CONF_USERNAME: "test-username",
|
||||||
|
@ -48,25 +64,28 @@ CONFIG = {
|
||||||
|
|
||||||
TEST_CLIENT_ENTITY_ID = "device_tracker.ruckus_test_device"
|
TEST_CLIENT_ENTITY_ID = "device_tracker.ruckus_test_device"
|
||||||
TEST_CLIENT = {
|
TEST_CLIENT = {
|
||||||
API_IP: "1.1.1.2",
|
API_CLIENT_IP: "1.1.1.2",
|
||||||
API_MAC: "AA:BB:CC:DD:EE:FF",
|
API_CLIENT_MAC: "AA:BB:CC:DD:EE:FF",
|
||||||
API_NAME: "Ruckus Test Device",
|
API_CLIENT_HOSTNAME: "Ruckus Test Device",
|
||||||
API_ACCESS_POINT: "00:11:22:33:44:55",
|
API_CLIENT_AP_MAC: DEFAULT_AP_INFO[0][API_AP_MAC],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_TITLE = DEFAULT_MESH_INFO[API_MESH_NAME]
|
||||||
|
DEFAULT_UNIQUEID = DEFAULT_SYSTEM_INFO[API_SYS_SYSINFO][API_SYS_SYSINFO_SERIAL]
|
||||||
|
|
||||||
|
|
||||||
def mock_config_entry() -> MockConfigEntry:
|
def mock_config_entry() -> MockConfigEntry:
|
||||||
"""Return a Ruckus Unleashed mock config entry."""
|
"""Return a Ruckus Unleashed mock config entry."""
|
||||||
return MockConfigEntry(
|
return MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
title=DEFAULT_TITLE,
|
title=DEFAULT_TITLE,
|
||||||
unique_id=DEFAULT_UNIQUE_ID,
|
unique_id=DEFAULT_UNIQUEID,
|
||||||
data=CONFIG,
|
data=CONFIG,
|
||||||
options=None,
|
options=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def init_integration(hass) -> MockConfigEntry:
|
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Set up the Ruckus Unleashed integration in Home Assistant."""
|
"""Set up the Ruckus Unleashed integration in Home Assistant."""
|
||||||
entry = mock_config_entry()
|
entry = mock_config_entry()
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
@ -76,27 +95,103 @@ async def init_integration(hass) -> MockConfigEntry:
|
||||||
dr.async_get(hass).async_get_or_create(
|
dr.async_get(hass).async_get_or_create(
|
||||||
name="Device from other integration",
|
name="Device from other integration",
|
||||||
config_entry_id=other_config_entry.entry_id,
|
config_entry_id=other_config_entry.entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, TEST_CLIENT[API_MAC])},
|
connections={(dr.CONNECTION_NETWORK_MAC, TEST_CLIENT[API_CLIENT_MAC])},
|
||||||
)
|
)
|
||||||
with patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
with RuckusAjaxApiPatchContext():
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value=DEFAULT_SYSTEM_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.ap_info",
|
|
||||||
return_value=DEFAULT_AP_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._fetch_clients",
|
|
||||||
return_value={
|
|
||||||
TEST_CLIENT[API_MAC]: TEST_CLIENT,
|
|
||||||
},
|
|
||||||
):
|
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
|
class RuckusAjaxApiPatchContext:
|
||||||
|
"""Context Manager which mocks the Ruckus AjaxSession and RuckusAjaxApi."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
login_mock: AsyncMock = None,
|
||||||
|
system_info: dict | None = None,
|
||||||
|
mesh_info: dict | None = None,
|
||||||
|
active_clients: list[dict] | AsyncMock | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize Ruckus Mock Context Manager."""
|
||||||
|
self.login_mock = login_mock
|
||||||
|
self.system_info = system_info
|
||||||
|
self.mesh_info = mesh_info
|
||||||
|
self.active_clients = active_clients
|
||||||
|
self.patchers = []
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
"""Patch RuckusAjaxApi and AjaxSession methods."""
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(RuckusAjaxApi, "_get_conf", new=AsyncMock(return_value={}))
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(
|
||||||
|
RuckusAjaxApi, "get_aps", new=AsyncMock(return_value=DEFAULT_AP_INFO)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(
|
||||||
|
RuckusAjaxApi,
|
||||||
|
"get_system_info",
|
||||||
|
new=AsyncMock(
|
||||||
|
return_value=DEFAULT_SYSTEM_INFO
|
||||||
|
if self.system_info is None
|
||||||
|
else self.system_info
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(
|
||||||
|
RuckusAjaxApi,
|
||||||
|
"get_mesh_info",
|
||||||
|
new=AsyncMock(
|
||||||
|
return_value=DEFAULT_MESH_INFO
|
||||||
|
if self.mesh_info is None
|
||||||
|
else self.mesh_info
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(
|
||||||
|
RuckusAjaxApi,
|
||||||
|
"get_active_clients",
|
||||||
|
new=self.active_clients
|
||||||
|
if isinstance(self.active_clients, AsyncMock)
|
||||||
|
else AsyncMock(
|
||||||
|
return_value=[TEST_CLIENT]
|
||||||
|
if self.active_clients is None
|
||||||
|
else self.active_clients
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(
|
||||||
|
AjaxSession,
|
||||||
|
"login",
|
||||||
|
new=self.login_mock or AsyncMock(return_value=self),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(AjaxSession, "close", new=AsyncMock(return_value=None))
|
||||||
|
)
|
||||||
|
|
||||||
|
def _patched_async_create(
|
||||||
|
host: str, username: str, password: str
|
||||||
|
) -> "AjaxSession":
|
||||||
|
return AjaxSession(None, host, username, password)
|
||||||
|
|
||||||
|
self.patchers.append(
|
||||||
|
patch.object(AjaxSession, "async_create", new=_patched_async_create)
|
||||||
|
)
|
||||||
|
|
||||||
|
for patcher in self.patchers:
|
||||||
|
patcher.start()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
"""Remove RuckusAjaxApi and AjaxSession patches."""
|
||||||
|
for patcher in self.patchers:
|
||||||
|
patcher.stop()
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
"""Test the Ruckus Unleashed config flow."""
|
"""Test the Ruckus Unleashed config flow."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from pyruckus.exceptions import AuthenticationError
|
from aioruckus.const import (
|
||||||
|
ERROR_CONNECT_TEMPORARY,
|
||||||
|
ERROR_CONNECT_TIMEOUT,
|
||||||
|
ERROR_LOGIN_INCORRECT,
|
||||||
|
)
|
||||||
|
from aioruckus.exceptions import AuthenticationError
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.ruckus_unleashed.const import DOMAIN
|
from homeassistant.components.ruckus_unleashed.const import DOMAIN
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import utcnow
|
from homeassistant.util import utcnow
|
||||||
|
|
||||||
from . import CONFIG, DEFAULT_SYSTEM_INFO, DEFAULT_TITLE
|
from . import CONFIG, DEFAULT_TITLE, RuckusAjaxApiPatchContext, mock_config_entry
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
|
@ -22,16 +28,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(), patch(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value=DEFAULT_SYSTEM_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.async_setup_entry",
|
"homeassistant.components.ruckus_unleashed.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
|
@ -53,9 +50,8 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
login_mock=AsyncMock(side_effect=AuthenticationError(ERROR_LOGIN_INCORRECT))
|
||||||
side_effect=AuthenticationError,
|
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -66,15 +62,44 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
assert result2["errors"] == {"base": "invalid_auth"}
|
assert result2["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_user_reauth(hass: HomeAssistant) -> None:
|
||||||
|
"""Test reauth."""
|
||||||
|
entry = mock_config_entry()
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}
|
||||||
|
)
|
||||||
|
|
||||||
|
flows = hass.config_entries.flow.async_progress()
|
||||||
|
assert len(flows) == 1
|
||||||
|
assert "flow_id" in flows[0]
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
flows[0]["flow_id"],
|
||||||
|
user_input={
|
||||||
|
CONF_HOST: "1.2.3.4",
|
||||||
|
CONF_USERNAME: "new_name",
|
||||||
|
CONF_PASSWORD: "new_pass",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
|
assert result2["step_id"] == "user"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
login_mock=AsyncMock(side_effect=ConnectionError(ERROR_CONNECT_TIMEOUT))
|
||||||
side_effect=ConnectionError,
|
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -85,15 +110,16 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
async def test_form_unexpected_response(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle unknown error."""
|
"""Test we handle unknown error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
login_mock=AsyncMock(
|
||||||
side_effect=Exception,
|
side_effect=ConnectionRefusedError(ERROR_CONNECT_TEMPORARY)
|
||||||
|
)
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -101,7 +127,7 @@ async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == "form"
|
assert result2["type"] == "form"
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect_unknown_serial(hass: HomeAssistant) -> None:
|
async def test_form_cannot_connect_unknown_serial(hass: HomeAssistant) -> None:
|
||||||
|
@ -112,16 +138,7 @@ async def test_form_cannot_connect_unknown_serial(hass: HomeAssistant) -> None:
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(system_info={}):
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value={},
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
CONFIG,
|
CONFIG,
|
||||||
|
@ -137,16 +154,7 @@ async def test_form_duplicate_error(hass: HomeAssistant) -> None:
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext():
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value=DEFAULT_SYSTEM_INFO,
|
|
||||||
):
|
|
||||||
await hass.config_entries.flow.async_configure(
|
await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
CONFIG,
|
CONFIG,
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
"""The sensor tests for the Ruckus Unleashed platform."""
|
"""The sensor tests for the Ruckus Unleashed platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.components.ruckus_unleashed import API_MAC, DOMAIN
|
from aioruckus.const import ERROR_CONNECT_EOF, ERROR_LOGIN_INCORRECT
|
||||||
|
from aioruckus.exceptions import AuthenticationError
|
||||||
|
|
||||||
|
from homeassistant.components.ruckus_unleashed import DOMAIN
|
||||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE
|
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
@ -10,12 +13,9 @@ from homeassistant.helpers.entity_component import async_update_entity
|
||||||
from homeassistant.util import utcnow
|
from homeassistant.util import utcnow
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
DEFAULT_AP_INFO,
|
DEFAULT_UNIQUEID,
|
||||||
DEFAULT_SYSTEM_INFO,
|
|
||||||
DEFAULT_TITLE,
|
|
||||||
DEFAULT_UNIQUE_ID,
|
|
||||||
TEST_CLIENT,
|
|
||||||
TEST_CLIENT_ENTITY_ID,
|
TEST_CLIENT_ENTITY_ID,
|
||||||
|
RuckusAjaxApiPatchContext,
|
||||||
init_integration,
|
init_integration,
|
||||||
mock_config_entry,
|
mock_config_entry,
|
||||||
)
|
)
|
||||||
|
@ -28,12 +28,7 @@ async def test_client_connected(hass: HomeAssistant) -> None:
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
future = utcnow() + timedelta(minutes=60)
|
future = utcnow() + timedelta(minutes=60)
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext():
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._fetch_clients",
|
|
||||||
return_value={
|
|
||||||
TEST_CLIENT[API_MAC]: TEST_CLIENT,
|
|
||||||
},
|
|
||||||
):
|
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await async_update_entity(hass, TEST_CLIENT_ENTITY_ID)
|
await async_update_entity(hass, TEST_CLIENT_ENTITY_ID)
|
||||||
|
@ -47,10 +42,7 @@ async def test_client_disconnected(hass: HomeAssistant) -> None:
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
future = utcnow() + timedelta(minutes=60)
|
future = utcnow() + timedelta(minutes=60)
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(active_clients={}):
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._fetch_clients",
|
|
||||||
return_value={},
|
|
||||||
):
|
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -64,9 +56,24 @@ async def test_clients_update_failed(hass: HomeAssistant) -> None:
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
future = utcnow() + timedelta(minutes=60)
|
future = utcnow() + timedelta(minutes=60)
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._fetch_clients",
|
active_clients=AsyncMock(side_effect=ConnectionError(ERROR_CONNECT_EOF))
|
||||||
side_effect=ConnectionError,
|
):
|
||||||
|
async_fire_time_changed(hass, future)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
await async_update_entity(hass, TEST_CLIENT_ENTITY_ID)
|
||||||
|
test_client = hass.states.get(TEST_CLIENT_ENTITY_ID)
|
||||||
|
assert test_client.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
|
async def test_clients_update_auth_failed(hass: HomeAssistant) -> None:
|
||||||
|
"""Test failed update with bad auth."""
|
||||||
|
await init_integration(hass)
|
||||||
|
|
||||||
|
future = utcnow() + timedelta(minutes=60)
|
||||||
|
with RuckusAjaxApiPatchContext(
|
||||||
|
active_clients=AsyncMock(side_effect=AuthenticationError(ERROR_LOGIN_INCORRECT))
|
||||||
):
|
):
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -85,27 +92,12 @@ async def test_restoring_clients(hass: HomeAssistant) -> None:
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
"device_tracker",
|
"device_tracker",
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DEFAULT_UNIQUE_ID,
|
DEFAULT_UNIQUEID,
|
||||||
suggested_object_id="ruckus_test_device",
|
suggested_object_id="ruckus_test_device",
|
||||||
config_entry=entry,
|
config_entry=entry,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with RuckusAjaxApiPatchContext(active_clients={}):
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value=DEFAULT_SYSTEM_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.ap_info",
|
|
||||||
return_value=DEFAULT_AP_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._fetch_clients",
|
|
||||||
return_value={},
|
|
||||||
):
|
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
"""Test the Ruckus Unleashed config flow."""
|
"""Test the Ruckus Unleashed config flow."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from pyruckus.exceptions import AuthenticationError
|
from aioruckus.const import ERROR_CONNECT_TIMEOUT, ERROR_LOGIN_INCORRECT
|
||||||
|
from aioruckus.exceptions import AuthenticationError
|
||||||
|
|
||||||
from homeassistant.components.ruckus_unleashed import (
|
from homeassistant.components.ruckus_unleashed import DOMAIN, MANUFACTURER
|
||||||
API_AP,
|
from homeassistant.components.ruckus_unleashed.const import (
|
||||||
API_DEVICE_NAME,
|
API_AP_DEVNAME,
|
||||||
API_ID,
|
API_AP_MAC,
|
||||||
API_MAC,
|
API_AP_MODEL,
|
||||||
API_MODEL,
|
API_SYS_SYSINFO,
|
||||||
API_SYSTEM_OVERVIEW,
|
API_SYS_SYSINFO_VERSION,
|
||||||
API_VERSION,
|
|
||||||
DOMAIN,
|
|
||||||
MANUFACTURER,
|
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -22,7 +20,7 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from . import (
|
from . import (
|
||||||
DEFAULT_AP_INFO,
|
DEFAULT_AP_INFO,
|
||||||
DEFAULT_SYSTEM_INFO,
|
DEFAULT_SYSTEM_INFO,
|
||||||
DEFAULT_TITLE,
|
RuckusAjaxApiPatchContext,
|
||||||
init_integration,
|
init_integration,
|
||||||
mock_config_entry,
|
mock_config_entry,
|
||||||
)
|
)
|
||||||
|
@ -31,9 +29,8 @@ from . import (
|
||||||
async def test_setup_entry_login_error(hass: HomeAssistant) -> None:
|
async def test_setup_entry_login_error(hass: HomeAssistant) -> None:
|
||||||
"""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 RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
login_mock=AsyncMock(side_effect=AuthenticationError(ERROR_LOGIN_INCORRECT))
|
||||||
side_effect=AuthenticationError,
|
|
||||||
):
|
):
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
result = await hass.config_entries.async_setup(entry.entry_id)
|
result = await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
@ -45,9 +42,8 @@ async def test_setup_entry_login_error(hass: HomeAssistant) -> None:
|
||||||
async def test_setup_entry_connection_error(hass: HomeAssistant) -> None:
|
async def test_setup_entry_connection_error(hass: HomeAssistant) -> None:
|
||||||
"""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 RuckusAjaxApiPatchContext(
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
login_mock=AsyncMock(side_effect=ConnectionError(ERROR_CONNECT_TIMEOUT))
|
||||||
side_effect=ConnectionError,
|
|
||||||
):
|
):
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
@ -60,19 +56,22 @@ async def test_router_device_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test a router device is created."""
|
"""Test a router device is created."""
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
device_info = DEFAULT_AP_INFO[API_AP][API_ID]["1"]
|
device_info = DEFAULT_AP_INFO[0]
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(CONNECTION_NETWORK_MAC, device_info[API_MAC])},
|
identifiers={(CONNECTION_NETWORK_MAC, device_info[API_AP_MAC])},
|
||||||
connections={(CONNECTION_NETWORK_MAC, device_info[API_MAC])},
|
connections={(CONNECTION_NETWORK_MAC, device_info[API_AP_MAC])},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert device
|
assert device
|
||||||
assert device.manufacturer == MANUFACTURER
|
assert device.manufacturer == MANUFACTURER
|
||||||
assert device.model == device_info[API_MODEL]
|
assert device.model == device_info[API_AP_MODEL]
|
||||||
assert device.name == device_info[API_DEVICE_NAME]
|
assert device.name == device_info[API_AP_DEVNAME]
|
||||||
assert device.sw_version == DEFAULT_SYSTEM_INFO[API_SYSTEM_OVERVIEW][API_VERSION]
|
assert (
|
||||||
|
device.sw_version
|
||||||
|
== DEFAULT_SYSTEM_INFO[API_SYS_SYSINFO][API_SYS_SYSINFO_VERSION]
|
||||||
|
)
|
||||||
assert device.via_device_id is None
|
assert device.via_device_id is None
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,31 +82,9 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
with RuckusAjaxApiPatchContext():
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||||
assert not hass.data.get(DOMAIN)
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_config_not_ready_during_setup(hass: HomeAssistant) -> None:
|
|
||||||
"""Test we throw a ConfigNotReady if Coordinator update fails."""
|
|
||||||
entry = mock_config_entry()
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.mesh_name",
|
|
||||||
return_value=DEFAULT_TITLE,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.Ruckus.system_info",
|
|
||||||
return_value=DEFAULT_SYSTEM_INFO,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.ruckus_unleashed.RuckusUnleashedDataUpdateCoordinator._async_update_data",
|
|
||||||
side_effect=ConnectionError,
|
|
||||||
):
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue