mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
UniFi - Sites don't declare role on UniFiOS 1.7.0 beta (#35555)
* New way to identify role, compatible with standalone controller or as part of unifios * Remove error * Bump dependency to v22 * Remove unused import
This commit is contained in:
parent
eddb5c6c3f
commit
785b8d2bd1
@ -32,12 +32,7 @@ from .const import (
|
|||||||
LOGGER,
|
LOGGER,
|
||||||
)
|
)
|
||||||
from .controller import get_controller
|
from .controller import get_controller
|
||||||
from .errors import (
|
from .errors import AlreadyConfigured, AuthenticationRequired, CannotConnect
|
||||||
AlreadyConfigured,
|
|
||||||
AuthenticationRequired,
|
|
||||||
CannotConnect,
|
|
||||||
NoLocalUser,
|
|
||||||
)
|
|
||||||
|
|
||||||
DEFAULT_PORT = 8443
|
DEFAULT_PORT = 8443
|
||||||
DEFAULT_SITE_ID = "default"
|
DEFAULT_SITE_ID = "default"
|
||||||
@ -134,8 +129,6 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN):
|
|||||||
|
|
||||||
for site in self.sites.values():
|
for site in self.sites.values():
|
||||||
if desc == site["desc"]:
|
if desc == site["desc"]:
|
||||||
if "role" not in site:
|
|
||||||
raise NoLocalUser
|
|
||||||
self.config[CONF_SITE_ID] = site["name"]
|
self.config[CONF_SITE_ID] = site["name"]
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -154,9 +147,6 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN):
|
|||||||
except AlreadyConfigured:
|
except AlreadyConfigured:
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
except NoLocalUser:
|
|
||||||
return self.async_abort(reason="no_local_user")
|
|
||||||
|
|
||||||
if len(self.sites) == 1:
|
if len(self.sites) == 1:
|
||||||
self.desc = next(iter(self.sites.values()))["desc"]
|
self.desc = next(iter(self.sites.values()))["desc"]
|
||||||
return await self.async_step_site(user_input={})
|
return await self.async_step_site(user_input={})
|
||||||
|
@ -290,9 +290,11 @@ class UniFiController:
|
|||||||
for site in sites.values():
|
for site in sites.values():
|
||||||
if self.site == site["name"]:
|
if self.site == site["name"]:
|
||||||
self._site_name = site["desc"]
|
self._site_name = site["desc"]
|
||||||
self._site_role = site["role"]
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
description = await self.api.site_description()
|
||||||
|
self._site_role = description[0]["site_role"]
|
||||||
|
|
||||||
except CannotConnect:
|
except CannotConnect:
|
||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
|
@ -22,9 +22,5 @@ class LoginRequired(UnifiException):
|
|||||||
"""Component got logged out."""
|
"""Component got logged out."""
|
||||||
|
|
||||||
|
|
||||||
class NoLocalUser(UnifiException):
|
|
||||||
"""No local user."""
|
|
||||||
|
|
||||||
|
|
||||||
class UserLevel(UnifiException):
|
class UserLevel(UnifiException):
|
||||||
"""User level too low."""
|
"""User level too low."""
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Ubiquiti UniFi",
|
"name": "Ubiquiti UniFi",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/unifi",
|
"documentation": "https://www.home-assistant.io/integrations/unifi",
|
||||||
"requirements": ["aiounifi==21"],
|
"requirements": ["aiounifi==22"],
|
||||||
"codeowners": ["@Kane610"],
|
"codeowners": ["@Kane610"],
|
||||||
"quality_scale": "platinum"
|
"quality_scale": "platinum"
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
"unknown_client_mac": "No client available on that MAC address"
|
"unknown_client_mac": "No client available on that MAC address"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "Controller site is already configured",
|
"already_configured": "Controller site is already configured"
|
||||||
"no_local_user": "No local user found, configure a local account on controller and try again"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -221,7 +221,7 @@ aiopylgtv==0.3.3
|
|||||||
aioswitcher==1.2.0
|
aioswitcher==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==21
|
aiounifi==22
|
||||||
|
|
||||||
# homeassistant.components.wwlln
|
# homeassistant.components.wwlln
|
||||||
aiowwlln==2.0.2
|
aiowwlln==2.0.2
|
||||||
|
@ -107,7 +107,7 @@ aiopylgtv==0.3.3
|
|||||||
aioswitcher==1.2.0
|
aioswitcher==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==21
|
aiounifi==22
|
||||||
|
|
||||||
# homeassistant.components.wwlln
|
# homeassistant.components.wwlln
|
||||||
aiowwlln==2.0.2
|
aiowwlln==2.0.2
|
||||||
|
@ -222,52 +222,6 @@ async def test_flow_fails_site_already_configured(hass, aioclient_mock):
|
|||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_fails_site_has_no_local_user(hass, aioclient_mock):
|
|
||||||
"""Test config flow."""
|
|
||||||
entry = MockConfigEntry(
|
|
||||||
domain=UNIFI_DOMAIN, data={"controller": {"host": "1.2.3.4", "site": "site_id"}}
|
|
||||||
)
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
UNIFI_DOMAIN, context={"source": "user"}
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
||||||
assert result["step_id"] == "user"
|
|
||||||
|
|
||||||
aioclient_mock.get("https://1.2.3.4:1234", status=302)
|
|
||||||
|
|
||||||
aioclient_mock.post(
|
|
||||||
"https://1.2.3.4:1234/api/login",
|
|
||||||
json={"data": "login successful", "meta": {"rc": "ok"}},
|
|
||||||
headers={"content-type": "application/json"},
|
|
||||||
)
|
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
"https://1.2.3.4:1234/api/self/sites",
|
|
||||||
json={
|
|
||||||
"data": [{"desc": "Site name", "name": "site_id"}],
|
|
||||||
"meta": {"rc": "ok"},
|
|
||||||
},
|
|
||||||
headers={"content-type": "application/json"},
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"],
|
|
||||||
user_input={
|
|
||||||
CONF_HOST: "1.2.3.4",
|
|
||||||
CONF_USERNAME: "username",
|
|
||||||
CONF_PASSWORD: "password",
|
|
||||||
CONF_PORT: 1234,
|
|
||||||
CONF_VERIFY_SSL: True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "no_local_user"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_fails_user_credentials_faulty(hass, aioclient_mock):
|
async def test_flow_fails_user_credentials_faulty(hass, aioclient_mock):
|
||||||
"""Test config flow."""
|
"""Test config flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -66,6 +66,7 @@ ENTRY_OPTIONS = {}
|
|||||||
CONFIGURATION = []
|
CONFIGURATION = []
|
||||||
|
|
||||||
SITES = {"Site name": {"desc": "Site name", "name": "site_id", "role": "admin"}}
|
SITES = {"Site name": {"desc": "Site name", "name": "site_id", "role": "admin"}}
|
||||||
|
DESCRIPTION = [{"name": "username", "site_name": "site_id", "site_role": "admin"}]
|
||||||
|
|
||||||
|
|
||||||
async def setup_unifi_integration(
|
async def setup_unifi_integration(
|
||||||
@ -73,6 +74,7 @@ async def setup_unifi_integration(
|
|||||||
config=ENTRY_CONFIG,
|
config=ENTRY_CONFIG,
|
||||||
options=ENTRY_OPTIONS,
|
options=ENTRY_OPTIONS,
|
||||||
sites=SITES,
|
sites=SITES,
|
||||||
|
site_description=DESCRIPTION,
|
||||||
clients_response=None,
|
clients_response=None,
|
||||||
devices_response=None,
|
devices_response=None,
|
||||||
clients_all_response=None,
|
clients_all_response=None,
|
||||||
@ -130,6 +132,8 @@ async def setup_unifi_integration(
|
|||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
||||||
"aiounifi.Controller.login", return_value=True,
|
"aiounifi.Controller.login", return_value=True,
|
||||||
), patch("aiounifi.Controller.sites", return_value=sites), patch(
|
), patch("aiounifi.Controller.sites", return_value=sites), patch(
|
||||||
|
"aiounifi.Controller.site_description", return_value=site_description
|
||||||
|
), patch(
|
||||||
"aiounifi.Controller.request", new=mock_request
|
"aiounifi.Controller.request", new=mock_request
|
||||||
), patch.object(
|
), patch.object(
|
||||||
aiounifi.websocket.WSClient, "start", return_value=True
|
aiounifi.websocket.WSClient, "start", return_value=True
|
||||||
|
@ -19,8 +19,8 @@ from homeassistant.setup import async_setup_component
|
|||||||
|
|
||||||
from .test_controller import (
|
from .test_controller import (
|
||||||
CONTROLLER_HOST,
|
CONTROLLER_HOST,
|
||||||
|
DESCRIPTION,
|
||||||
ENTRY_CONFIG,
|
ENTRY_CONFIG,
|
||||||
SITES,
|
|
||||||
setup_unifi_integration,
|
setup_unifi_integration,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -289,12 +289,12 @@ async def test_controller_not_client(hass):
|
|||||||
|
|
||||||
async def test_not_admin(hass):
|
async def test_not_admin(hass):
|
||||||
"""Test that switch platform only work on an admin account."""
|
"""Test that switch platform only work on an admin account."""
|
||||||
sites = deepcopy(SITES)
|
description = deepcopy(DESCRIPTION)
|
||||||
sites["Site name"]["role"] = "not admin"
|
description[0]["site_role"] = "not admin"
|
||||||
controller = await setup_unifi_integration(
|
controller = await setup_unifi_integration(
|
||||||
hass,
|
hass,
|
||||||
options={CONF_TRACK_CLIENTS: False, CONF_TRACK_DEVICES: False},
|
options={CONF_TRACK_CLIENTS: False, CONF_TRACK_DEVICES: False},
|
||||||
sites=sites,
|
site_description=description,
|
||||||
clients_response=[CLIENT_1],
|
clients_response=[CLIENT_1],
|
||||||
devices_response=[DEVICE_1],
|
devices_response=[DEVICE_1],
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user