UniFi - Fix block functionality (#32625)
* Fix block functionality * Remove unrelated changes * Bump dependency to v15 * Run requirement script
This commit is contained in:
parent
0a25e86fab
commit
16d7f84be7
6 changed files with 32 additions and 6 deletions
|
@ -162,7 +162,7 @@ class UniFiController:
|
|||
WIRELESS_GUEST_CONNECTED,
|
||||
):
|
||||
self.update_wireless_clients()
|
||||
elif data.get("clients") or data.get("devices"):
|
||||
elif "clients" in data or "devices" in data:
|
||||
async_dispatcher_send(self.hass, self.signal_update)
|
||||
|
||||
@property
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/unifi",
|
||||
"requirements": [
|
||||
"aiounifi==14"
|
||||
"aiounifi==15"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
|
|
|
@ -262,7 +262,7 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchDevice, RestoreEntity):
|
|||
"""Shortcut to the switch port that client is connected to."""
|
||||
try:
|
||||
return self.device.ports[self.client.sw_port]
|
||||
except TypeError:
|
||||
except (AttributeError, KeyError, TypeError):
|
||||
LOGGER.warning(
|
||||
"Entity %s reports faulty device %s or port %s",
|
||||
self.entity_id,
|
||||
|
@ -282,7 +282,7 @@ class UniFiBlockClientSwitch(UniFiClient, SwitchDevice):
|
|||
@property
|
||||
def is_on(self):
|
||||
"""Return true if client is allowed to connect."""
|
||||
return not self.client.blocked
|
||||
return not self.is_blocked
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on connectivity for client."""
|
||||
|
@ -291,3 +291,10 @@ class UniFiBlockClientSwitch(UniFiClient, SwitchDevice):
|
|||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn off connectivity for client."""
|
||||
await self.controller.api.clients.async_block(self.client.mac)
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend."""
|
||||
if self.is_blocked:
|
||||
return "mdi:network-off"
|
||||
return "mdi:network"
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
import logging
|
||||
|
||||
from aiounifi.api import SOURCE_EVENT
|
||||
from aiounifi.events import (
|
||||
WIRED_CLIENT_BLOCKED,
|
||||
WIRED_CLIENT_UNBLOCKED,
|
||||
WIRELESS_CLIENT_BLOCKED,
|
||||
WIRELESS_CLIENT_UNBLOCKED,
|
||||
)
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -9,6 +17,9 @@ from homeassistant.helpers.entity import Entity
|
|||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CLIENT_BLOCKED = (WIRED_CLIENT_BLOCKED, WIRELESS_CLIENT_BLOCKED)
|
||||
CLIENT_UNBLOCKED = (WIRED_CLIENT_UNBLOCKED, WIRELESS_CLIENT_UNBLOCKED)
|
||||
|
||||
|
||||
class UniFiClient(Entity):
|
||||
"""Base class for UniFi clients."""
|
||||
|
@ -18,7 +29,9 @@ class UniFiClient(Entity):
|
|||
self.client = client
|
||||
self.controller = controller
|
||||
self.listeners = []
|
||||
|
||||
self.is_wired = self.client.mac not in controller.wireless_clients
|
||||
self.is_blocked = self.client.blocked
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Client entity created."""
|
||||
|
@ -41,6 +54,12 @@ class UniFiClient(Entity):
|
|||
"""Update the clients state."""
|
||||
if self.is_wired and self.client.mac in self.controller.wireless_clients:
|
||||
self.is_wired = False
|
||||
|
||||
if self.client.last_updated == SOURCE_EVENT:
|
||||
|
||||
if self.client.event.event in CLIENT_BLOCKED + CLIENT_UNBLOCKED:
|
||||
self.is_blocked = self.client.event.event in CLIENT_BLOCKED
|
||||
|
||||
LOGGER.debug("Updating client %s %s", self.entity_id, self.client.mac)
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ aiopylgtv==0.3.3
|
|||
aioswitcher==2019.4.26
|
||||
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==14
|
||||
aiounifi==15
|
||||
|
||||
# homeassistant.components.wwlln
|
||||
aiowwlln==2.0.2
|
||||
|
|
|
@ -81,7 +81,7 @@ aiopylgtv==0.3.3
|
|||
aioswitcher==2019.4.26
|
||||
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==14
|
||||
aiounifi==15
|
||||
|
||||
# homeassistant.components.wwlln
|
||||
aiowwlln==2.0.2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue