1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

UniFi block clients (#25478)

* Allow blocking clients on UniFi networks
This commit is contained in:
Robert Svensson
2019-07-25 16:56:56 +02:00
committed by GitHub
parent 59c62a261b
commit b6934f0cd0
10 changed files with 157 additions and 43 deletions

View File

@@ -13,7 +13,8 @@ from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import (
CONF_CONTROLLER, CONF_SITE_ID, CONTROLLER_ID, LOGGER, UNIFI_CONFIG)
CONF_BLOCK_CLIENT, CONF_CONTROLLER, CONF_SITE_ID, CONTROLLER_ID, LOGGER,
UNIFI_CONFIG)
from .errors import AuthenticationRequired, CannotConnect
@@ -52,6 +53,11 @@ class UniFiController:
"""Return the site user role of this controller."""
return self._site_role
@property
def block_clients(self):
"""Return list of clients to block."""
return self.unifi_config.get(CONF_BLOCK_CLIENT, [])
@property
def mac(self):
"""Return the mac address of this controller."""
@@ -84,6 +90,8 @@ class UniFiController:
with async_timeout.timeout(10):
await self.api.clients.update()
await self.api.devices.update()
if self.block_clients:
await self.api.clients_all.update()
except aiounifi.LoginRequired:
try:
@@ -128,14 +136,14 @@ class UniFiController:
except CannotConnect:
raise ConfigEntryNotReady
except Exception: # pylint: disable=broad-except
except Exception as err: # pylint: disable=broad-except
LOGGER.error(
'Unknown error connecting with UniFi controller.')
'Unknown error connecting with UniFi controller: %s', err)
return False
for unifi_config in hass.data[UNIFI_CONFIG]:
if self.host == unifi_config[CONF_HOST] and \
self.site == unifi_config[CONF_SITE_ID]:
self.site_name == unifi_config[CONF_SITE_ID]:
self.unifi_config = unifi_config
break