Add Uplink info to UniFi Device tracker attributes (#123032)

Add device uplink mac sensor
This commit is contained in:
Ian 2024-08-19 22:57:03 -07:00 committed by GitHub
parent 8260264416
commit d99f1631ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 89 additions and 1 deletions

View file

@ -174,6 +174,12 @@ def async_device_outlet_supported_fn(hub: UnifiHub, obj_id: str) -> bool:
return hub.api.devices[obj_id].outlet_ac_power_budget is not None
@callback
def async_device_uplink_mac_supported_fn(hub: UnifiHub, obj_id: str) -> bool:
"""Determine if a device supports reading uplink MAC address."""
return "uplink_mac" in hub.api.devices[obj_id].raw.get("uplink", {})
def device_system_stats_supported_fn(
stat_index: int, hub: UnifiHub, obj_id: str
) -> bool:
@ -571,6 +577,19 @@ ENTITY_DESCRIPTIONS: tuple[UnifiSensorEntityDescription, ...] = (
unique_id_fn=lambda hub, obj_id: f"device_temperature-{obj_id}",
value_fn=lambda hub, device: device.general_temperature,
),
UnifiSensorEntityDescription[Devices, Device](
key="Device Uplink MAC",
entity_category=EntityCategory.DIAGNOSTIC,
api_handler_fn=lambda api: api.devices,
available_fn=async_device_available_fn,
device_info_fn=async_device_device_info_fn,
name_fn=lambda device: "Uplink MAC",
object_fn=lambda api, obj_id: api.devices[obj_id],
unique_id_fn=lambda hub, obj_id: f"device_uplink_mac-{obj_id}",
supported_fn=async_device_uplink_mac_supported_fn,
value_fn=lambda hub, device: device.raw.get("uplink", {}).get("uplink_mac"),
is_connected_fn=lambda hub, obj_id: hub.api.devices[obj_id].state == 1,
),
UnifiSensorEntityDescription[Devices, Device](
key="Device State",
device_class=SensorDeviceClass.ENUM,