@@ -403,11 +403,6 @@ def _nop_echo(*args, **kwargs):
403
403
"provided or they are ignored\n "
404
404
f"discovering for { discovery_timeout } seconds.."
405
405
)
406
- else :
407
- echo (
408
- "No --type or --device-family and --encrypt-type defined, "
409
- + f"discovering for { discovery_timeout } seconds.."
410
- )
411
406
dev = await Discover .discover_single (
412
407
host ,
413
408
port = port ,
@@ -613,9 +608,7 @@ def _echo_features(
613
608
id_ : feat for id_ , feat in features .items () if feat .category == category
614
609
}
615
610
616
- if not features :
617
- return
618
- echo (f"[bold]{ title } [/bold]" )
611
+ echo (f"{ indent } [bold]{ title } [/bold]" )
619
612
for _ , feat in features .items ():
620
613
try :
621
614
echo (f"{ indent } { feat } " )
@@ -627,33 +620,40 @@ def _echo_features(
627
620
echo (f"{ indent } { feat .name } ({ feat .id } ): [red]got exception ({ ex } )[/red]" )
628
621
629
622
630
- def _echo_all_features (features , * , verbose = False , title_prefix = None ):
623
+ def _echo_all_features (features , * , verbose = False , title_prefix = None , indent = "" ):
631
624
"""Print out all features by category."""
632
625
if title_prefix is not None :
633
- echo (f"[bold]\n \t == { title_prefix } ==[/bold]" )
626
+ echo (f"[bold]\n { indent } == { title_prefix } ==[/bold]" )
634
627
_echo_features (
635
628
features ,
636
- title = "\n \t == Primary features ==" ,
629
+ title = "== Primary features ==" ,
637
630
category = Feature .Category .Primary ,
638
631
verbose = verbose ,
632
+ indent = indent ,
639
633
)
634
+ echo ()
640
635
_echo_features (
641
636
features ,
642
- title = "\n \t == Information ==" ,
637
+ title = "== Information ==" ,
643
638
category = Feature .Category .Info ,
644
639
verbose = verbose ,
640
+ indent = indent ,
645
641
)
642
+ echo ()
646
643
_echo_features (
647
644
features ,
648
- title = "\n \t == Configuration ==" ,
645
+ title = "== Configuration ==" ,
649
646
category = Feature .Category .Config ,
650
647
verbose = verbose ,
648
+ indent = indent ,
651
649
)
650
+ echo ()
652
651
_echo_features (
653
652
features ,
654
- title = "\n \t == Debug ==" ,
653
+ title = "== Debug ==" ,
655
654
category = Feature .Category .Debug ,
656
655
verbose = verbose ,
656
+ indent = indent ,
657
657
)
658
658
659
659
@@ -665,38 +665,42 @@ async def state(ctx, dev: Device):
665
665
verbose = ctx .parent .params .get ("verbose" , False ) if ctx .parent else False
666
666
667
667
echo (f"[bold]== { dev .alias } - { dev .model } ==[/bold]" )
668
- echo (f"\t Host: { dev .host } " )
669
- echo (f"\t Port: { dev .port } " )
670
- echo (f"\t Device state: { dev .is_on } " )
668
+ echo (f"Host: { dev .host } " )
669
+ echo (f"Port: { dev .port } " )
670
+ echo (f"Device state: { dev .is_on } " )
671
+
672
+ echo (f"Time: { dev .time } (tz: { dev .timezone } " )
673
+ echo (f"Hardware: { dev .hw_info ['hw_ver' ]} " )
674
+ echo (f"Software: { dev .hw_info ['sw_ver' ]} " )
675
+ echo (f"MAC (rssi): { dev .mac } ({ dev .rssi } )" )
676
+ if verbose :
677
+ echo (f"Location: { dev .location } " )
678
+
679
+ _echo_all_features (dev .features , verbose = verbose )
680
+ echo ()
681
+
671
682
if dev .children :
672
- echo ("\t == Children ==" )
683
+ echo ("[bold] == Children ==[/bold] " )
673
684
for child in dev .children :
674
685
_echo_all_features (
675
686
child .features ,
676
- title_prefix = f"{ child .alias } ({ child .model } , { child . device_type } )" ,
687
+ title_prefix = f"{ child .alias } ({ child .model } )" ,
677
688
verbose = verbose ,
689
+ indent = "\t " ,
678
690
)
679
691
680
692
echo ()
681
693
682
- echo ("\t [bold]== Generic information ==[/bold]" )
683
- echo (f"\t Time: { dev .time } (tz: { dev .timezone } " )
684
- echo (f"\t Hardware: { dev .hw_info ['hw_ver' ]} " )
685
- echo (f"\t Software: { dev .hw_info ['sw_ver' ]} " )
686
- echo (f"\t MAC (rssi): { dev .mac } ({ dev .rssi } )" )
687
- echo (f"\t Location: { dev .location } " )
688
-
689
- _echo_all_features (dev .features , verbose = verbose )
690
-
691
- echo ("\n \t [bold]== Modules ==[/bold]" )
692
- for module in dev .modules .values ():
693
- echo (f"\t [green]+ { module } [/green]" )
694
-
695
694
if verbose :
695
+ echo ("\n \t [bold]== Modules ==[/bold]" )
696
+ for module in dev .modules .values ():
697
+ echo (f"\t [green]+ { module } [/green]" )
698
+
696
699
echo ("\n \t [bold]== Protocol information ==[/bold]" )
697
700
echo (f"\t Credentials hash: { dev .credentials_hash } " )
698
701
echo ()
699
702
_echo_discovery_info (dev ._discovery_info )
703
+
700
704
return dev .internal_state
701
705
702
706
@@ -1261,25 +1265,29 @@ async def shell(dev: Device):
1261
1265
@click .argument ("value" , required = False )
1262
1266
@click .option ("--child" , required = False )
1263
1267
@pass_dev
1264
- async def feature (dev : Device , child : str , name : str , value ):
1268
+ @click .pass_context
1269
+ async def feature (ctx : click .Context , dev : Device , child : str , name : str , value ):
1265
1270
"""Access and modify features.
1266
1271
1267
1272
If no *name* is given, lists available features and their values.
1268
1273
If only *name* is given, the value of named feature is returned.
1269
1274
If both *name* and *value* are set, the described setting is changed.
1270
1275
"""
1276
+ verbose = ctx .parent .params .get ("verbose" , False ) if ctx .parent else False
1277
+
1271
1278
if child is not None :
1272
1279
echo (f"Targeting child device { child } " )
1273
1280
dev = dev .get_child_device (child )
1274
1281
if not name :
1275
- _echo_features (dev .features , " \n [bold]== Features ==[/bold] \n " , indent = "" )
1282
+ _echo_all_features (dev .features , verbose = verbose , indent = "" )
1276
1283
1277
1284
if dev .children :
1278
1285
for child_dev in dev .children :
1279
- _echo_features (
1286
+ _echo_all_features (
1280
1287
child_dev .features ,
1281
- f"\n [bold]== Child { child_dev .alias } ==\n " ,
1282
- indent = "" ,
1288
+ verbose = verbose ,
1289
+ title_prefix = f"Child { child_dev .alias } " ,
1290
+ indent = "\t " ,
1283
1291
)
1284
1292
1285
1293
return
0 commit comments