Files
python-kasa/kasa/cli/wifi.py
ZeliardM 30a8fd45a8
Some checks failed
CI / Perform Lint Checks (3.13) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
New Wi-Fi handling for SMARTCAM devices (#1639)
Updated scanning and joining Wi-Fi for SMARTCAM devices that may use a
newer connection process.
2026-02-22 00:03:52 +01:00

61 lines
1.3 KiB
Python

"""Module for cli wifi commands."""
from __future__ import annotations
import asyncclick as click
from kasa import (
Device,
KasaException,
)
from .common import (
echo,
pass_dev,
)
@click.group()
def wifi() -> None:
"""Commands to control wifi settings."""
@wifi.command()
@pass_dev
async def scan(dev):
"""Scan for available wifi networks."""
echo("Scanning for wifi networks, wait a second..")
devs = await dev.wifi_scan()
echo(f"Found {len(devs)} wifi networks!")
for dev in devs:
echo(f"\t {dev}")
return devs
@wifi.command()
@click.argument("ssid")
@click.option(
"--keytype",
default="",
help="KeyType (Not needed for SmartCamDevice).",
)
@click.option("--password", prompt=True, hide_input=True)
@pass_dev
async def join(dev: Device, ssid: str, password: str, keytype: str):
"""Join the given wifi network."""
echo(f"Asking the device to connect to {ssid}..")
try:
res = await dev.wifi_join(ssid, password, keytype=keytype)
except KasaException as e:
if type(e) is KasaException:
echo(str(e))
return
raise
echo(
f"Response: {res} - if the device is not able to join the network, "
f"it will revert back to its previous state."
)
return res