From 6e69beab1316802987b3cb94592498f0ef33984a Mon Sep 17 00:00:00 2001 From: "mark.r.godwin@gmail.com" <10632972+MarkGodwin@users.noreply.github.com> Date: Sun, 28 May 2023 10:13:54 +0000 Subject: [PATCH] Add get_port_profile --- src/tplink_omada_client/omadasiteclient.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tplink_omada_client/omadasiteclient.py b/src/tplink_omada_client/omadasiteclient.py index a87b214..b5f0c04 100644 --- a/src/tplink_omada_client/omadasiteclient.py +++ b/src/tplink_omada_client/omadasiteclient.py @@ -264,8 +264,8 @@ async def get_switch_port_overrides( ) # Otherwise the profile's config values are returned - profiles = await self.get_port_profiles() - prof = next((p for p in profiles if p.profile_id == port.profile_id), None) + prof = await self.get_port_profile(port.profile_id) + # The API doesn't provide the PoE mode of the switch (couldn't even find in Omada # GUI how to set the PoE mode of a switch). Thus, use True as a default value. poe_mode = (prof.poe_mode != PoEMode.DISABLED) @@ -373,6 +373,15 @@ async def update_switch_port( # Read back the new port settings return await self.get_switch_port(mac, port) + async def get_port_profile(self, profile_id: str) -> OmadaPortProfile: + profiles = await self.get_port_profiles() + + profile = next((p for p in profiles if p.profile_id == profile_id), None) + + if not profile: + raise InvalidDevice(f"Port profile {profile_id} does not exist") + return profile + async def get_port_profiles(self) -> List[OmadaPortProfile]: """Lists the available switch port profiles that can be applied."""