Initial TapoCamera support (#1165)

Adds experimental support for the Tapo Camera protocol also used by the H200 hub.
Creates a new SslAesTransport and a derived SmartCamera and SmartCameraProtocol.
This commit is contained in:
Steven B.
2024-10-16 16:53:52 +01:00
committed by GitHub
parent 380fbb93c3
commit dcc36e1dfe
13 changed files with 770 additions and 11 deletions

View File

@@ -35,6 +35,7 @@ TYPES = [
"strip",
"lightstrip",
"smart",
"camera",
]
ENCRYPT_TYPES = [encrypt_type.value for encrypt_type in DeviceEncryptionType]
@@ -172,6 +173,14 @@ def _legacy_type_to_class(_type):
type=int,
help="The login version for device authentication. Defaults to 2",
)
@click.option(
"--https/--no-https",
envvar="KASA_HTTPS",
default=False,
is_flag=True,
type=bool,
help="Set flag if the device encryption uses https.",
)
@click.option(
"--timeout",
envvar="KASA_TIMEOUT",
@@ -209,6 +218,14 @@ def _legacy_type_to_class(_type):
envvar="KASA_CREDENTIALS_HASH",
help="Hashed credentials used to authenticate to the device.",
)
@click.option(
"--experimental",
default=False,
is_flag=True,
type=bool,
envvar="KASA_EXPERIMENTAL",
help="Enable experimental mode for devices not yet fully supported.",
)
@click.version_option(package_name="python-kasa")
@click.pass_context
async def cli(
@@ -221,6 +238,7 @@ async def cli(
debug,
type,
encrypt_type,
https,
device_family,
login_version,
json,
@@ -229,6 +247,7 @@ async def cli(
username,
password,
credentials_hash,
experimental,
):
"""A tool for controlling TP-Link smart home devices.""" # noqa
# no need to perform any checks if we are just displaying the help
@@ -237,6 +256,11 @@ async def cli(
ctx.obj = object()
return
if experimental:
from kasa.experimental.enabled import Enabled
Enabled.set(True)
logging_config: dict[str, Any] = {
"level": logging.DEBUG if debug > 0 else logging.INFO
}
@@ -295,12 +319,21 @@ async def cli(
return await ctx.invoke(discover)
device_updated = False
if type is not None and type != "smart":
if type is not None and type not in {"smart", "camera"}:
from kasa.deviceconfig import DeviceConfig
config = DeviceConfig(host=host, port_override=port, timeout=timeout)
dev = _legacy_type_to_class(type)(host, config=config)
elif type == "smart" or (device_family and encrypt_type):
elif type in {"smart", "camera"} or (device_family and encrypt_type):
if type == "camera":
if not experimental:
error(
"Camera is an experimental type, please enable with --experimental"
)
encrypt_type = "AES"
https = True
device_family = "SMART.IPCAMERA"
from kasa.device import Device
from kasa.deviceconfig import (
DeviceConfig,
@@ -311,10 +344,12 @@ async def cli(
if not encrypt_type:
encrypt_type = "KLAP"
ctype = DeviceConnectionParameters(
DeviceFamily(device_family),
DeviceEncryptionType(encrypt_type),
login_version,
https,
)
config = DeviceConfig(
host=host,