mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-15 06:38:42 +00:00
Add support for feature units (#843)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
This commit is contained in:
19
kasa/cli.py
19
kasa/cli.py
@@ -598,9 +598,10 @@ async def state(ctx, dev: Device):
|
||||
echo("\t[bold]== Children ==[/bold]")
|
||||
for child in dev.children:
|
||||
echo(f"\t* {child.alias} ({child.model}, {child.device_type})")
|
||||
for feat in child.features.values():
|
||||
for id_, feat in child.features.items():
|
||||
try:
|
||||
echo(f"\t\t{feat.name}: {feat.value}")
|
||||
unit = f" {feat.unit}" if feat.unit else ""
|
||||
echo(f"\t\t{feat.name} ({id_}): {feat.value}{unit}")
|
||||
except Exception as ex:
|
||||
echo(f"\t\t{feat.name}: got exception (%s)" % ex)
|
||||
echo()
|
||||
@@ -614,12 +615,8 @@ async def state(ctx, dev: Device):
|
||||
|
||||
echo("\n\t[bold]== Device-specific information == [/bold]")
|
||||
for id_, feature in dev.features.items():
|
||||
echo(f"\t{feature.name} ({id_}): {feature.value}")
|
||||
|
||||
if dev.has_emeter:
|
||||
echo("\n\t[bold]== Current State ==[/bold]")
|
||||
emeter_status = dev.emeter_realtime
|
||||
echo(f"\t{emeter_status}")
|
||||
unit = f" {feature.unit}" if feature.unit else ""
|
||||
echo(f"\t{feature.name} ({id_}): {feature.value}{unit}")
|
||||
|
||||
echo("\n\t[bold]== Modules ==[/bold]")
|
||||
for module in dev.modules.values():
|
||||
@@ -1177,7 +1174,8 @@ async def feature(dev: Device, child: str, name: str, value):
|
||||
def _print_features(dev):
|
||||
for name, feat in dev.features.items():
|
||||
try:
|
||||
echo(f"\t{feat.name} ({name}): {feat.value}")
|
||||
unit = f" {feat.unit}" if feat.unit else ""
|
||||
echo(f"\t{feat.name} ({name}): {feat.value}{unit}")
|
||||
except Exception as ex:
|
||||
echo(f"\t{feat.name} ({name}): [red]{ex}[/red]")
|
||||
|
||||
@@ -1198,7 +1196,8 @@ async def feature(dev: Device, child: str, name: str, value):
|
||||
feat = dev.features[name]
|
||||
|
||||
if value is None:
|
||||
echo(f"{feat.name} ({name}): {feat.value}")
|
||||
unit = f" {feat.unit}" if feat.unit else ""
|
||||
echo(f"{feat.name} ({name}): {feat.value}{unit}")
|
||||
return feat.value
|
||||
|
||||
echo(f"Setting {name} to {value}")
|
||||
|
||||
Reference in New Issue
Block a user