2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 22:56:34 +00:00

devspec: attr=value

git-svn-id: https://svn.fhem.de/fhem/trunk@335 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2009-01-17 10:01:56 +00:00
parent d0c3f77b9e
commit 90f6cb6505
3 changed files with 53 additions and 20 deletions

View File

@ -478,9 +478,11 @@
- feature: Removed msghist for multiple FHZ handling, IODev attribute added
- bugfix: cut off string "(counter)" from fallback value in 13_KS300.pm
- feature: daily/monthly cumulated values for EMWZ/EMGZ/EMWM with 15_CUL_EM
by Klaus
- feature: 01_FHEMWEB.pm: multiple room assignments
fixedrange with optional [day|week|month|year]
attr title and label for flexible .gplot files
- feature: fhem.pl: attr global logdir used by wildcard %ld
- feature: do not block on disconnected devices (FHZ/CM11/CUL)
- bugfix: deleting at definition in the at command
- bugfix: deleting a notify/at/watchdog definition in a notify/at/watchdog
- feature: devspec <attr>=<value>. E.g. set room=kitchen off; list disabled=

View File

@ -225,8 +225,10 @@ A line ending with \ will be concatenated with the next one, so long lines
<li>a range of devices, separated by dash (-)</li>
<li>a regular expression, if the the spec contains on e of the following
characters: ^*[]$</li>
<li>an internal attribute of the device, followed by a colon and then a
regexp for this attribute. Known attributes are DEF, STATE and TYPE.</li>
<li>an attribute of the device, followed by an equal sign (=) and then a
regexp for this attribute. As attribute you can specify either attributes
set with the attr command or one of the "internal" attributes DEF, STATE
and TYPE.</li>
</ul>
Example:
<ul>
@ -236,8 +238,9 @@ A line ending with \ will be concatenated with the next one, so long lines
<code>set lamp.* on</code><br>
<code>set lamp1-lamp3 on</code><br>
<code>set lamp1-lamp3,lamp3 on</code><br>
<code>list DEF:1234.*</code><br>
<code>list TYPE:FS20</code><br>
<code>set room=kitchen off</code><br>
<code>list disabled=</code><br>
<code>list TYPE=FS20</code><br>
</ul>
Notes:
<ul>

View File

@ -45,6 +45,7 @@ sub AnalyzeInput($);
sub AssignIoPort($);
sub CallFn(@);
sub CommandChain($$);
sub CollectAttrNames();
sub DoClose($);
sub Dispatch($$);
sub FmtDateTime($);
@ -135,6 +136,7 @@ use vars qw(%cmds); # Global command name hash. To be expanded
use vars qw($reread_active);
my %attrnames; # hash of attrnames needed by devspec2array
my $server; # Server socket
my $currlogfile; # logfile, without wildcards
my $logopened = 0; # logfile opened or using stdout
@ -149,7 +151,7 @@ my %intAt; # Internal at timer hash.
my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0;
my $AttrList = "room comment";
my $cvsid = '$Id: fhem.pl,v 1.66 2009-01-15 09:13:42 rudolfkoenig Exp $';
my $cvsid = '$Id: fhem.pl,v 1.67 2009-01-17 10:01:56 rudolfkoenig Exp $';
my $namedef =
"where <name> is either:\n" .
"- a single device name\n" .
@ -274,6 +276,7 @@ if($pfn) {
print PID $$ . "\n";
close(PID);
}
CollectAttrNames();
$init_done = 1;
Log 0, "Server started (version $attr{global}{version}, pid $$)";
@ -596,27 +599,36 @@ devspec2array($)
my %knownattr = ( "DEF"=>1, "STATE"=>1, "TYPE"=>1 );
my ($name) = @_;
return "" if(!defined($name));
return $name if(defined($defs{$name}));
my @ret;
if($name =~ m/(.*):(.*)/ && $knownattr{$1}) {
my $lattr = $1;
my $re = $2;
foreach my $l (sort keys %defs) {
push @ret, $l
if(!$re || ($defs{$l}{$lattr} && $defs{$l}{$lattr} =~ m/$re/));
}
return $name if(!@ret); # No match, return the input
return @ret;
}
my ($isattr, @ret);
foreach my $l (split(",", $name)) { # List
if($l =~ m/(.*)=(.*)/) {
my ($lattr,$re) = ($1, $2);
if($knownattr{$lattr}) {
foreach my $l (sort keys %defs) {
push @ret, $l
if($defs{$l}{$lattr} && (!$re || $defs{$l}{$lattr} =~ m/$re/));
}
} elsif($attrnames{$lattr}) {
foreach my $l (sort keys %attr) {
push @ret, $l
if($attr{$l}{$lattr} && (!$re || $attr{$l}{$lattr} =~ m/$re/));
}
}
$isattr = 1;
next;
}
if($l =~ m/[*\[\]^\$]/) { # Regexp
push @ret, grep($_ =~ m/$l/, sort keys %defs);
next;
}
if($l =~ m/-/) { # Range
my ($lower, $upper) = split("-", $l, 2);
push @ret, grep($_ ge $lower && $_ le $upper, sort keys %defs);
@ -625,7 +637,7 @@ devspec2array($)
push @ret, $l;
}
return $name if(!@ret); # No match, return the input
return $name if(!@ret && !$isattr); # No match, return the input
return @ret;
}
@ -1128,6 +1140,7 @@ CommandDeleteAttr($$)
}
}
CollectAttrNames();
return join("\n", @rets);
}
@ -1436,6 +1449,7 @@ CommandAttr($$)
$defs{$sdev}{IODev} = $defs{$a[2]} if($a[1] eq "IODev");
}
CollectAttrNames() if($init_done);
return join("\n", @rets);
}
@ -1455,6 +1469,7 @@ CommandDefaultAttr($$)
} else {
$defaultattr{$a[0]} = $a[1];
}
CollectAttrNames() if($init_done);
return undef;
}
@ -2024,3 +2039,16 @@ Dispatch($$)
return @found;
}
###########################
# Build the hash used by devspec2array
sub
CollectAttrNames()
{
%attrnames = ();
foreach my $d (keys %attr) {
foreach my $a (keys %{ $attr{$d} }) {
$attrnames{$a} = 1;
}
}
}