MarkGodwin / tplink-omada-api

MIT License
16 stars 12 forks source link

Add the ability to request a neutral SwitchPortOverrides for a particular port #20

Closed odouville closed 1 year ago

odouville commented 1 year ago

This allows to change the PoE mode of a single port, using ports overrides, without changing any other setting of the port, no matter how they are currently set.

The PoE switching method in the Home Assistant TP-Link Omada integration could then be changed from:

    async def _async_turn_on_off_poe(self, enable: bool) -> None:
        self.port_details = await self.omada_client.update_switch_port(
            self.device,
            self.port_details,
            overrides=SwitchPortOverrides(enable_poe=enable),
        )
        self._refresh_state()

To:

    async def _async_turn_on_off_poe(self, enable: bool) -> None:
        overrides = await self.omada_client.get_switch_port_overrides(device, port_details)
        overrides.enable_poe = enable
        self.port_details = await self.omada_client.update_switch_port(
            self.device,
            self.port_details,
            overrides,
        )
        self._refresh_state()

Hence without changing any of the port other settings.

The counterpart is that it uses one more API call to get the port status, and one more again if the port has no active overrides yet (in order to populate the neutral override settings with the port associated profile settings, which should mostly happen only once).

MarkGodwin commented 1 year ago

You're right, this is worth doing. I already have an open PR on the HA integration to add gateway wan/lan connectivity sensors, so it will take a while before I can integrate this.