Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for reconnecting wireless clients #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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