98_count.pm: add parameter "raw"

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@18543 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2019-02-09 12:13:20 +00:00
parent 11ed34201c
commit 6b97fd3317

View File

@ -5,7 +5,6 @@ use strict;
use warnings; use warnings;
sub count_Initialize($$) { sub count_Initialize($$) {
$cmds{count} = { Fn => "CommandCount", $cmds{count} = { Fn => "CommandCount",
Hlp=>"[filter],count devices"}; Hlp=>"[filter],count devices"};
} }
@ -14,14 +13,16 @@ sub CommandCount($$)
{ {
my ($cl, $param) = @_; my ($cl, $param) = @_;
my $str = ""; my $str = "";
my $fill = ""; my $fill = $str;
my $n = 0; my $n = 0;
my $raw = $n;
if(!$param) { # List of all devices if(!$param) { # List of all devices
$n = keys %defs; $n = keys %defs;
$fill = "s" if $n != 1; $fill = "s" if $n != 1;
$str = "\nCount: $n device$fill in total.\n"; $str = "\nCount: $n device$fill in total.\n";
} else { # devspecArray } else { # devspecArray
$raw = $param =~ s/ raw$//i;
$n = 0; $n = 0;
my @list = devspec2array($param,$cl); my @list = devspec2array($param,$cl);
$n = int(@list); $n = int(@list);
@ -34,7 +35,8 @@ sub CommandCount($$)
$str = "\nCount: $n device$fill for devspec $param\n"; $str = "\nCount: $n device$fill for devspec $param\n";
} }
return $str; return $str unless $raw;
return $n;
} }
1; 1;
@ -48,10 +50,12 @@ sub CommandCount($$)
<a name="count"></a> <a name="count"></a>
<h3>count</h3> <h3>count</h3>
<ul> <ul>
<code>count [devspec]</code> <code>count [devspec] [raw]</code>
<br><br> <br><br>
Count devices specified by devspec.<br/> Count devices specified by devspec.<br/>
If no devspec given, count will return number of totally defined devices.<br/> If no devspec given, count will return number of totally defined devices.<br/>
Count will return the plain number of devices if "raw" passed as last part of the command.<br/>
This is useful for processing the number of devices itself.<br/>
</ul> </ul>
=end html =end html