1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/unifi/unifi_client.py
epenet a27d483009
Remove unifi from mypy ignore list (#74456)
* Remove unifi diagnostics from mypy ignore list

* Remove unifi init from mypy ignore list

* Remove unifi device tracker from mypy ignore list

* Adjust doc string

* Adjust doc string

* Remove unifi entity base from mypy ignore list

* Keep comprehension

* Remove unifi config flow from mypy ignore list

* Fix circular import
2022-07-06 10:25:53 +02:00

59 lines
1.8 KiB
Python

"""Base class for UniFi clients."""
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.entity import DeviceInfo
from .unifi_entity_base import UniFiBase
class UniFiClientBase(UniFiBase):
"""Base class for UniFi clients (without device info)."""
def __init__(self, client, controller) -> None:
"""Set up client."""
super().__init__(client, controller)
self._is_wired = client.mac not in controller.wireless_clients
self.client = self._item
@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.
"""
if self._is_wired and self.client.mac in self.controller.wireless_clients:
self._is_wired = False
if self.controller.option_ignore_wired_bug:
return self.client.is_wired
return self._is_wired
@property
def unique_id(self):
"""Return a unique identifier for this switch."""
return f"{self.TYPE}-{self.client.mac}"
@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
class UniFiClient(UniFiClientBase):
"""Base class for UniFi clients (with device info)."""
@property
def device_info(self) -> DeviceInfo:
"""Return a client description for device registry."""
return DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, self.client.mac)},
default_manufacturer=self.client.oui,
default_name=self.name,
)