Mark UniFi power cycle button as unavailable if PoE is not enabled on port (#122035)
This commit is contained in:
parent
4bcdb551d4
commit
aeabe3ab95
2 changed files with 45 additions and 2 deletions
|
@ -8,7 +8,7 @@ from __future__ import annotations
|
|||
from collections.abc import Callable, Coroutine
|
||||
from dataclasses import dataclass
|
||||
import secrets
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import aiounifi
|
||||
from aiounifi.interfaces.api_handlers import ItemEvent
|
||||
|
@ -44,6 +44,17 @@ from .entity import (
|
|||
async_wlan_device_info_fn,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .hub import UnifiHub
|
||||
|
||||
|
||||
@callback
|
||||
def async_port_power_cycle_available_fn(hub: UnifiHub, obj_id: str) -> bool:
|
||||
"""Check if port allows power cycle action."""
|
||||
if not async_device_available_fn(hub, obj_id):
|
||||
return False
|
||||
return bool(hub.api.ports[obj_id].poe_enable)
|
||||
|
||||
|
||||
async def async_restart_device_control_fn(
|
||||
api: aiounifi.Controller, obj_id: str
|
||||
|
@ -96,7 +107,7 @@ ENTITY_DESCRIPTIONS: tuple[UnifiButtonEntityDescription, ...] = (
|
|||
entity_category=EntityCategory.CONFIG,
|
||||
device_class=ButtonDeviceClass.RESTART,
|
||||
api_handler_fn=lambda api: api.ports,
|
||||
available_fn=async_device_available_fn,
|
||||
available_fn=async_port_power_cycle_available_fn,
|
||||
control_fn=async_power_cycle_port_control_fn,
|
||||
device_info_fn=async_device_device_info_fn,
|
||||
name_fn=lambda port: f"{port.name} Power Cycle",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue