Skip to content

Commit

Permalink
Merge pull request #57 from reey/master
Browse files Browse the repository at this point in the history
add support for reconnecting wireless clients
  • Loading branch information
MarkGodwin authored Sep 29, 2024
2 parents f7ec0de + 1464d4f commit d73e316
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tplink_omada_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
command_known_clients,
command_poe,
command_reboot,
command_reconnect_client,
command_set_client_name,
command_set_device_led,
command_switch,
Expand Down Expand Up @@ -55,6 +56,7 @@ def main(argv: Sequence[str] | None = None) -> int:
command_known_clients.arg_parser(subparsers)
command_poe.arg_parser(subparsers)
command_reboot.arg_parser(subparsers)
command_reconnect_client.arg_parser(subparsers)
command_certificate.arg_parser(subparsers)
command_set_client_name.arg_parser(subparsers)
command_set_device_led.arg_parser(subparsers)
Expand Down
29 changes: 29 additions & 0 deletions src/tplink_omada_client/cli/command_reconnect_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Implementation for 'client' command"""

from argparse import _SubParsersAction
from .config import get_target_config, to_omada_connection
from .util import get_client_mac, get_target_argument


async def command_reconnect_client(args) -> int:
"""Executes 'reconnect-client' command"""
controller = get_target_argument(args)
config = get_target_config(controller)

async with to_omada_connection(config) as client:
site_client = await client.get_site_client(config.site)
mac = await get_client_mac(site_client, args["mac"])
await site_client.reconnect_client(mac)
return 0


def arg_parser(subparsers: _SubParsersAction) -> None:
"""Configures arguments parser for 'reconnect-client' command"""
reconnect_parser = subparsers.add_parser("reconnect-client", help="Reconnects a client")

reconnect_parser.add_argument(
"mac",
help="The MAC address or name of the client",
)

reconnect_parser.set_defaults(func=command_reconnect_client)
8 changes: 8 additions & 0 deletions src/tplink_omada_client/omadasiteclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ async def unblock_client(self, mac_or_client: str | OmadaNetworkClient) -> None:
mac = mac_or_client
await self._api.request("post", self._api.format_url(f"cmd/clients/{mac}/unblock", self._site_id))

async def reconnect_client(self, mac_or_client: str | OmadaNetworkClient) -> None:
"""Reconnect the specified client."""
if isinstance(mac_or_client, OmadaConnectedClient):
mac = mac_or_client.mac
else:
mac = mac_or_client
await self._api.request("post", self._api.format_url(f"cmd/clients/{mac}/reconnect", self._site_id))

async def get_client(self, mac_or_client: str | OmadaNetworkClient) -> OmadaClientDetails:
"""Get the details of a client"""
if isinstance(mac_or_client, OmadaConnectedClient):
Expand Down

0 comments on commit d73e316

Please sign in to comment.