From 736adb01796e22c30f21cb59881afd4250869a3f Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sat, 17 Jan 2009 10:01:56 +0000 Subject: [PATCH] devspec: attr=value git-svn-id: https://svn.fhem.de/fhem/trunk@335 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 6 +++-- fhem/docs/commandref.html | 11 +++++--- fhem/fhem.pl | 56 +++++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index f464caae6..590ac9d31 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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 =. E.g. set room=kitchen off; list disabled= diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index d9ce3353f..a109c204d 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -225,8 +225,10 @@ A line ending with \ will be concatenated with the next one, so long lines
  • a range of devices, separated by dash (-)
  • a regular expression, if the the spec contains on e of the following characters: ^*[]$
  • -
  • an internal attribute of the device, followed by a colon and then a - regexp for this attribute. Known attributes are DEF, STATE and TYPE.
  • +
  • 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.
  • Example:
      @@ -236,8 +238,9 @@ A line ending with \ will be concatenated with the next one, so long lines set lamp.* on
      set lamp1-lamp3 on
      set lamp1-lamp3,lamp3 on
      - list DEF:1234.*
      - list TYPE:FS20
      + set room=kitchen off
      + list disabled=
      + list TYPE=FS20
    Notes:
      diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 8b5e4c0c1..6e3c2e03d 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -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 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; + } + } +}