Bump aiounifi to v35 (#79040)
* Update imports Replace constants with enums * Import new request objects * Bump aiounifi to v35
This commit is contained in:
parent
42bd664305
commit
bfd12730f2
11 changed files with 98 additions and 84 deletions
|
@ -8,13 +8,14 @@ Support for controlling deep packet inspection (DPI) restriction groups.
|
|||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from aiounifi.api import SOURCE_EVENT
|
||||
from aiounifi.events import (
|
||||
WIRED_CLIENT_BLOCKED,
|
||||
WIRED_CLIENT_UNBLOCKED,
|
||||
WIRELESS_CLIENT_BLOCKED,
|
||||
WIRELESS_CLIENT_UNBLOCKED,
|
||||
from aiounifi.interfaces.api_handlers import SOURCE_EVENT
|
||||
from aiounifi.models.client import ClientBlockRequest
|
||||
from aiounifi.models.device import (
|
||||
DeviceSetOutletRelayRequest,
|
||||
DeviceSetPoePortModeRequest,
|
||||
)
|
||||
from aiounifi.models.dpi_restriction_app import DPIRestrictionAppEnableRequest
|
||||
from aiounifi.models.event import EventKey
|
||||
|
||||
from homeassistant.components.switch import DOMAIN, SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -39,8 +40,8 @@ DPI_SWITCH = "dpi"
|
|||
POE_SWITCH = "poe"
|
||||
OUTLET_SWITCH = "outlet"
|
||||
|
||||
CLIENT_BLOCKED = (WIRED_CLIENT_BLOCKED, WIRELESS_CLIENT_BLOCKED)
|
||||
CLIENT_UNBLOCKED = (WIRED_CLIENT_UNBLOCKED, WIRELESS_CLIENT_UNBLOCKED)
|
||||
CLIENT_BLOCKED = (EventKey.WIRED_CLIENT_BLOCKED, EventKey.WIRELESS_CLIENT_BLOCKED)
|
||||
CLIENT_UNBLOCKED = (EventKey.WIRED_CLIENT_UNBLOCKED, EventKey.WIRELESS_CLIENT_UNBLOCKED)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
@ -272,11 +273,19 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Enable POE for client."""
|
||||
await self.device.set_port_poe_mode(self.client.switch_port, self.poe_mode)
|
||||
await self.controller.api.request(
|
||||
DeviceSetPoePortModeRequest.create(
|
||||
self.device, self.client.switch_port, self.poe_mode
|
||||
)
|
||||
)
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Disable POE for client."""
|
||||
await self.device.set_port_poe_mode(self.client.switch_port, "off")
|
||||
await self.controller.api.request(
|
||||
DeviceSetPoePortModeRequest.create(
|
||||
self.device, self.client.switch_port, "off"
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
@ -324,9 +333,9 @@ class UniFiBlockClientSwitch(UniFiClient, SwitchEntity):
|
|||
"""Update the clients state."""
|
||||
if (
|
||||
self.client.last_updated == SOURCE_EVENT
|
||||
and self.client.event.event in CLIENT_BLOCKED + CLIENT_UNBLOCKED
|
||||
and self.client.event.key in CLIENT_BLOCKED + CLIENT_UNBLOCKED
|
||||
):
|
||||
self._is_blocked = self.client.event.event in CLIENT_BLOCKED
|
||||
self._is_blocked = self.client.event.key in CLIENT_BLOCKED
|
||||
|
||||
super().async_update_callback()
|
||||
|
||||
|
@ -337,11 +346,15 @@ class UniFiBlockClientSwitch(UniFiClient, SwitchEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on connectivity for client."""
|
||||
await self.controller.api.clients.unblock(self.client.mac)
|
||||
await self.controller.api.request(
|
||||
ClientBlockRequest.create(self.client.mac, False)
|
||||
)
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off connectivity for client."""
|
||||
await self.controller.api.clients.block(self.client.mac)
|
||||
await self.controller.api.request(
|
||||
ClientBlockRequest.create(self.client.mac, True)
|
||||
)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
|
@ -449,7 +462,9 @@ class UniFiDPIRestrictionSwitch(UniFiBase, SwitchEntity):
|
|||
"""Restrict access of apps related to DPI group."""
|
||||
return await asyncio.gather(
|
||||
*[
|
||||
self.controller.api.dpi_apps.enable(app_id)
|
||||
self.controller.api.request(
|
||||
DPIRestrictionAppEnableRequest.create(app_id, True)
|
||||
)
|
||||
for app_id in self._item.dpiapp_ids
|
||||
]
|
||||
)
|
||||
|
@ -458,7 +473,9 @@ class UniFiDPIRestrictionSwitch(UniFiBase, SwitchEntity):
|
|||
"""Remove restriction of apps related to DPI group."""
|
||||
return await asyncio.gather(
|
||||
*[
|
||||
self.controller.api.dpi_apps.disable(app_id)
|
||||
self.controller.api.request(
|
||||
DPIRestrictionAppEnableRequest.create(app_id, False)
|
||||
)
|
||||
for app_id in self._item.dpiapp_ids
|
||||
]
|
||||
)
|
||||
|
@ -509,11 +526,15 @@ class UniFiOutletSwitch(UniFiBase, SwitchEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Enable outlet relay."""
|
||||
await self._item.set_outlet_relay_state(self._outlet_index, True)
|
||||
await self.controller.api.request(
|
||||
DeviceSetOutletRelayRequest.create(self._item, self._outlet_index, True)
|
||||
)
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Disable outlet relay."""
|
||||
await self._item.set_outlet_relay_state(self._outlet_index, False)
|
||||
await self.controller.api.request(
|
||||
DeviceSetOutletRelayRequest.create(self._item, self._outlet_index, False)
|
||||
)
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue