I have several device names longer then 20 characters, which messes up the padding when using cmd: list devspec value. Increasing this to 30 seems to work well in my case. This could be hardcoded also.
Before patch:
Ntf_EnO_DimToStoredValue active
Ntf_EnO_Occupancy_Low_Battery active
Ntf_EnO_Smoke_Alarm active
Ntf_EnO_Smoke_Dead_Sensor active
Ntf_EnO_Smoke_Low_Battery active
Ntf_EnO_Sync_FUD61 active
With patch:
attr global listNamePadding 30
Ntf_EnO_DimToStoredValue active
Ntf_EnO_Occupancy_Low_Battery active
Ntf_EnO_Smoke_Alarm active
Ntf_EnO_Smoke_Dead_Sensor active
Ntf_EnO_Smoke_Low_Battery active
Ntf_EnO_Sync_FUD61 active
--- - 2019-10-05 12:25:57.074228921 +0200
+++ /srv/fhem/fhem.pl 2019-10-05 12:24:38.000000000 +0200
@@ -342,6 +342,7 @@
language:EN,DE
lastinclude
latitude
+ listNamePadding
logdir
logfile
longitude
@@ -2460,6 +2461,7 @@
CommandList($$)
{
my ($cl, $param) = @_;
+ my $namefmt = '%-'.AttrVal('global', 'listNamePadding', 20).'s';
my $str = "";
if($param =~ m/^-r *(.*)$/i) {
@@ -2498,7 +2500,7 @@
next if(IsIgnored($d) || ($cl && !Authorized($cl, "devicename", $d, 1)));
my $t = $defs{$d}{TYPE};
$str .= "\n$t:\n" if($t ne $lt);
- $str .= sprintf(" %-20s (%s)\n", $d, $defs{$d}{STATE});
+ $str .= sprintf(" $namefmt (%s)\n", $d, $defs{$d}{STATE});
$lt = $t;
}
@@ -2525,13 +2527,13 @@
$val = ($val->{NAME} ? $val->{NAME} : # ???
join(" ", map { "$_=$val->{$_}" } sort keys %{$val}));
}
- $str .= sprintf("%-20s %*s %*s %s\n", $first?$sdev:'',
+ $str .= sprintf("$namefmt %*s %*s %s\n", $first?$sdev:'',
$arg[2]?19:0, '', $arg[2]?-15:0, $arg[2]?$n:'', $val);
} elsif($defs{$sdev}{READINGS} &&
defined($defs{$sdev}{READINGS}{$n})
&& (!$fType || $fType eq "r:")) {
- $str .= sprintf("%-20s %s %*s %s\n", $first?$sdev:'',
+ $str .= sprintf("$namefmt %s %*s %s\n", $first?$sdev:'',
$defs{$sdev}{READINGS}{$n}{TIME},
$arg[2]?-15:0, $arg[2]?$n:'',
$defs{$sdev}{READINGS}{$n}{VAL});
@@ -2539,7 +2541,7 @@
} elsif($attr{$sdev} &&
defined($attr{$sdev}{$n})
&& (!$fType || $fType eq "a:")) {
- $str .= sprintf("%-20s %*s %*s %s\n", $first?$sdev:'',
+ $str .= sprintf("$namefmt %*s %*s %s\n", $first?$sdev:'',
$arg[2]?19:0, '', $arg[2]?-15:0, $arg[2]?$n:'',
$attr{$sdev}{$n});
Anybody else interested in this patch?
Objections?
Zitat von: rudolfkoenig am 05 Oktober 2019, 19:44:30
Anybody else interested in this patch?
Objections?
Maybe this value can be passed as a parameter to the command 'list' instead.
list .+ NR REGEXP padding=30
Zitat von: Nestor am 05 Oktober 2019, 20:14:02
There is also a bug when multiple values are requested and the first value is not defined but the second is, the name will not be printed.
Patch with fix:
--- - 2019-10-06 07:42:47.000000000 +0200
+++ fhem.pl 2019-10-06 07:40:48.000000000 +0200
@@ -2527,6 +2527,7 @@
}
$str .= sprintf("%-20s %*s %*s %s\n", $first?$sdev:'',
$arg[2]?19:0, '', $arg[2]?-15:0, $arg[2]?$n:'', $val);
+ $first = 0;
} elsif($defs{$sdev}{READINGS} &&
defined($defs{$sdev}{READINGS}{$n})
@@ -2535,6 +2536,7 @@
$defs{$sdev}{READINGS}{$n}{TIME},
$arg[2]?-15:0, $arg[2]?$n:'',
$defs{$sdev}{READINGS}{$n}{VAL});
+ $first = 0;
} elsif($attr{$sdev} &&
defined($attr{$sdev}{$n})
@@ -2542,10 +2544,10 @@
$str .= sprintf("%-20s %*s %*s %s\n", $first?$sdev:'',
$arg[2]?19:0, '', $arg[2]?-15:0, $arg[2]?$n:'',
$attr{$sdev}{$n});
+ $first = 0;
}
}
- $first = 0;
}
}
And yet another patch which fixes unescaped entities in the list cmd documentation and adds undocumented prefixes for value argument.
--- - 2019-10-06 11:58:26.000000000 +0200
+++ docs/commandref_frame.html 2019-10-06 11:55:02.000000000 +0200
@@ -941,7 +941,7 @@
<a name="list"></a>
<h3>list</h3>
<ul>
- <code>list [devspec] [value]</code><br>
+ <code>list [devspec] [value ...]</code><br>
or<br>
<code>list {-r|-R} devspec</code><br>
<br><br>
@@ -951,13 +951,13 @@
See the <a href="#devspec">Device specification</a> section for details on
<devspec>.
<br>
- If value is specified, then output this property (like DEF, TYPE, etc) or
- reading (actuator, measured-temp) for all devices from the devspec.
+ If <tt><value></tt> is specified, then output this property (internal, reading or attribute) for all devices from the devspec.
+ <tt><Value></tt> can be restricted with prefix <tt>i:</tt> for internals, <tt>r:</tt> for readings and <tt>a:</tt> for attributes.
<br><br>
Example:
- <pre><code> fhem> list
+ <pre><code> fhem> list
- Type list <name> for detailed info.
+ Type list <name> for detailed info.
Internal:
global (Internal)
@@ -988,7 +988,7 @@
</code></pre>
If specifying <code>name</code>, then a detailed status for <code>name</code>
will be displayed, e.g.:
- <pre><code> fhem> list fl
+ <pre><code> fhem> list fl
Internals:
CODE 5102
Thanks for the hint, I fixed the bug mentioned in the 3rd post, and the documentation (both english and german).
For the first patch: if there are at least 2 user voting for it, I will integrate it.