UniFi - Logs spam with not adding disabled entity (#34479)

* Proposed solution, unfortunately this makes the implementation less pretty

* Clarify why mac is registered in init
This commit is contained in:
Robert Svensson 2020-04-21 06:17:14 +02:00 committed by GitHub
parent bc5a2da7b7
commit f12bd7ad99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 5 deletions

View File

@ -120,6 +120,7 @@ def add_entities(controller, async_add_entities):
class UniFiClientTracker(UniFiClient, ScannerEntity):
"""Representation of a network client."""
DOMAIN = DOMAIN
TYPE = CLIENT_TRACKER
def __init__(self, client, controller):
@ -241,12 +242,13 @@ class UniFiClientTracker(UniFiClient, ScannerEntity):
class UniFiDeviceTracker(UniFiBase, ScannerEntity):
"""Representation of a network infrastructure device."""
DOMAIN = DOMAIN
TYPE = DEVICE_TRACKER
def __init__(self, device, controller):
"""Set up tracked device."""
super().__init__(controller)
self.device = device
super().__init__(controller)
@property
def mac(self):

View File

@ -53,6 +53,8 @@ def add_entities(controller, async_add_entities):
class UniFiBandwidthSensor(UniFiClient):
"""UniFi bandwidth sensor base class."""
DOMAIN = DOMAIN
@property
def name(self) -> str:
"""Return the name of the client."""

View File

@ -138,6 +138,7 @@ def add_entities(controller, async_add_entities, switches_off):
class UniFiPOEClientSwitch(UniFiClient, SwitchDevice, RestoreEntity):
"""Representation of a client that uses POE."""
DOMAIN = DOMAIN
TYPE = POE_SWITCH
def __init__(self, client, controller):
@ -232,6 +233,7 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchDevice, RestoreEntity):
class UniFiBlockClientSwitch(UniFiClient, SwitchDevice):
"""Representation of a blockable client."""
DOMAIN = DOMAIN
TYPE = BLOCK_SWITCH
@property

View File

@ -36,8 +36,8 @@ class UniFiClient(UniFiBase):
def __init__(self, client, controller) -> None:
"""Set up client."""
super().__init__(controller)
self.client = client
super().__init__(controller)
self._is_wired = self.client.mac not in controller.wireless_clients
self.is_blocked = self.client.blocked

View File

@ -9,11 +9,16 @@ from homeassistant.helpers.entity_registry import async_entries_for_device
class UniFiBase(Entity):
"""UniFi entity base class."""
DOMAIN = ""
TYPE = ""
def __init__(self, controller) -> None:
"""Set up UniFi entity base."""
"""Set up UniFi entity base.
Register mac to controller entities to cover disabled entities.
"""
self.controller = controller
self.controller.entities[self.DOMAIN][self.TYPE].add(self.mac)
@property
def mac(self):
@ -22,7 +27,6 @@ class UniFiBase(Entity):
async def async_added_to_hass(self) -> None:
"""Entity created."""
self.controller.entities[self.platform.domain][self.TYPE].add(self.mac)
for signal, method in (
(self.controller.signal_reachable, self.async_update_callback),
(self.controller.signal_options_update, self.options_updated),
@ -32,7 +36,7 @@ class UniFiBase(Entity):
async def async_will_remove_from_hass(self) -> None:
"""Disconnect object when removed."""
self.controller.entities[self.platform.domain][self.TYPE].remove(self.mac)
self.controller.entities[self.DOMAIN][self.TYPE].remove(self.mac)
async def async_remove(self):
"""Clean up when removing entity.