UniFi - Fix block functionality (#32625)

* Fix block functionality

* Remove unrelated changes

* Bump dependency to v15

* Run requirement script
This commit is contained in:
Robert Svensson 2020-03-10 18:27:25 +01:00 committed by GitHub
parent 0a25e86fab
commit 16d7f84be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 6 deletions

View file

@ -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()