2020-01-31 19:23:25 +00:00
|
|
|
"""Base class for UniFi clients."""
|
|
|
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
2021-05-01 22:37:19 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2020-01-31 19:23:25 +00:00
|
|
|
|
2020-04-23 14:48:24 +00:00
|
|
|
from .unifi_entity_base import UniFiBase
|
|
|
|
|
2020-01-31 19:23:25 +00:00
|
|
|
|
2020-04-19 19:30:06 +00:00
|
|
|
class UniFiClient(UniFiBase):
|
2020-01-31 19:23:25 +00:00
|
|
|
"""Base class for UniFi clients."""
|
|
|
|
|
|
|
|
def __init__(self, client, controller) -> None:
|
|
|
|
"""Set up client."""
|
2020-05-08 22:34:18 +00:00
|
|
|
super().__init__(client, controller)
|
2020-03-10 17:27:25 +00:00
|
|
|
|
2020-05-08 22:34:18 +00:00
|
|
|
self._is_wired = client.mac not in controller.wireless_clients
|
2021-01-20 22:58:02 +00:00
|
|
|
self.client = self._item
|
2020-01-31 19:23:25 +00:00
|
|
|
|
2020-04-17 06:39:01 +00:00
|
|
|
@property
|
|
|
|
def is_wired(self):
|
|
|
|
"""Return if the client is wired.
|
|
|
|
|
|
|
|
Allows disabling logic to keep track of clients affected by UniFi wired bug marking wireless devices as wired. This is useful when running a network not only containing UniFi APs.
|
|
|
|
"""
|
2020-05-08 20:19:27 +00:00
|
|
|
if self._is_wired and self.client.mac in self.controller.wireless_clients:
|
|
|
|
self._is_wired = False
|
|
|
|
|
2020-04-17 06:39:01 +00:00
|
|
|
if self.controller.option_ignore_wired_bug:
|
|
|
|
return self.client.is_wired
|
2021-01-20 22:58:02 +00:00
|
|
|
|
2020-04-17 06:39:01 +00:00
|
|
|
return self._is_wired
|
|
|
|
|
2020-04-19 19:30:06 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return a unique identifier for this switch."""
|
|
|
|
return f"{self.TYPE}-{self.client.mac}"
|
|
|
|
|
2020-01-31 19:23:25 +00:00
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
|
|
|
"""Return the name of the client."""
|
|
|
|
return self.client.name or self.client.hostname
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return if controller is available."""
|
|
|
|
return self.controller.available
|
|
|
|
|
|
|
|
@property
|
2021-05-01 22:37:19 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2020-01-31 19:23:25 +00:00
|
|
|
"""Return a client description for device registry."""
|
2021-10-28 16:26:21 +00:00
|
|
|
return DeviceInfo(
|
|
|
|
connections={(CONNECTION_NETWORK_MAC, self.client.mac)},
|
|
|
|
default_manufacturer=self.client.oui,
|
|
|
|
default_name=self.name,
|
|
|
|
)
|