Add cli vacuum commands

This commit is contained in:
Teemu Rytilahti 2025-01-12 18:30:44 +01:00
parent 83d169d35c
commit a19753e814
2 changed files with 63 additions and 0 deletions

View File

@ -93,6 +93,7 @@ def _legacy_type_to_class(_type: str) -> Any:
"hsv": "light", "hsv": "light",
"temperature": "light", "temperature": "light",
"effect": "light", "effect": "light",
"vacuum": "vacuum",
}, },
result_callback=json_formatter_cb, result_callback=json_formatter_cb,
) )

62
kasa/cli/vacuum.py Normal file
View File

@ -0,0 +1,62 @@
"""Module for cli vacuum commands.."""
from __future__ import annotations
import asyncclick as click
from PIL import ImageShow
from kasa import (
Device,
Module,
)
from .common import (
error,
pass_dev_or_child,
)
@click.group(invoke_without_command=True)
@click.pass_context
async def vacuum(ctx: click.Context) -> None:
"""Vacuum commands."""
@vacuum.group(invoke_without_command=True, name="map")
@pass_dev_or_child
async def map_group(dev: Device):
"""Return map."""
if not (map := dev.modules.get(Module.Map)):
error("This device does not support maps.")
return
click.echo(map.map_info)
click.echo(map.map_data)
click.echo("Use `kasa vacuum map show` to display the map")
@map_group.command()
@pass_dev_or_child
async def show(dev: Device):
"""Show current map."""
if not (map := dev.modules.get(Module.Map)):
error("This device does not support maps.")
return
img = map.get_map_image()
img = img.resize((4 * img.width, 4 * img.height))
ImageShow.show(img)
@map_group.command()
@pass_dev_or_child
async def path(dev: Device):
"""Show current path."""
if not (map := dev.modules.get(Module.Map)):
error("This device does not support maps.")
return
data = map.get_path()
print(data)