From b45e1d034b8ffcacf5c6bd36de2e04acf252ba4a Mon Sep 17 00:00:00 2001 From: martinp876 <> Date: Tue, 3 Jun 2014 14:53:45 +0000 Subject: [PATCH] add listDevice to actionDetector git-svn-id: https://svn.fhem.de/fhem/trunk@6040 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_CUL_HM.pm | 93 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index 58ab1eea0..0c65b8a4a 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -211,6 +211,7 @@ sub CUL_HM_updateConfig($){ $attr{$name}{"event-on-change-reading"} = AttrVal($name, "event-on-change-reading", ".*") if(!$nAttr); + $attr{$name}{model} = "ActionDetector"; delete $hash->{helper}{role}; $hash->{helper}{role}{vrt} = 1; next; @@ -2581,11 +2582,36 @@ sub CUL_HM_Get($@) {#+++++++++++++++++ get command+++++++++++++++++++++++++++++ @h = split(" ", $h) if($h); if(!defined($h)) { - my @arr; - push @arr, keys %{$culHmGlobalGets} if(!$roleV); - push @arr, keys %{$culHmVrtGets} if($roleV); - push @arr, keys %{$culHmSubTypeGets->{$st}} if($culHmSubTypeGets->{$st}); - push @arr, keys %{$culHmModelGets->{$md}} if($culHmModelGets->{$md}); + my @arr = (); + if(!$roleV) {foreach(keys %{$culHmGlobalGets} ){push @arr,"$_:".$culHmGlobalGets->{$_} }}; + if($roleV) {foreach(keys %{$culHmVrtGets} ){push @arr,"$_:".$culHmVrtGets->{$_} }}; + if($culHmSubTypeGets->{$st}){foreach(keys %{$culHmSubTypeGets->{$st}}){push @arr,"$_:".${$culHmSubTypeGets->{$st}}{$_} }}; + if($culHmModelGets->{$md}) {foreach(keys %{$culHmModelGets->{$md}} ){push @arr,"$_:".${$culHmModelGets->{$md}}{$_} }}; + + foreach(@arr){ + my ($cmd,$val) = split(":",$_,2); + Log 1,"General $_ : $cmd,$val"; + if (!$val || + $val !~ m/^\[.*\]$/ || + $val =~ m/\[.*\[/ || + $val =~ m/(\<|\>)]/ + ){ + $_ = $cmd; + } + else{ + $val =~ s/(\[|\])//g; + my @vArr = split('\|',$val); + foreach (@vArr){ + if ($_ =~ m/(.*)\.\.(.*)/ ){ + my @list = map { ($_.".0", $_+0.5) } (($1+0)..($2+0)); + pop @list; + $_ = join(",",@list); + } + } + $_ = "$cmd:".join(",",@vArr); + } + } + my $usg = "Unknown argument $cmd, choose one of ".join(" ",sort @arr); return $usg; @@ -2750,17 +2776,34 @@ sub CUL_HM_Get($@) {#+++++++++++++++++ get command+++++++++++++++++++++++++++++ close(aSave); } elsif($cmd eq "listDevice"){ ############################################### - - my @dl = grep !/^$/, - map{AttrVal($_,"IOgrp","") =~ m/^$name/ ? $_ : ""} - keys %defs; - my @rl; - foreach (@dl){ - my(undef,$pref) = split":",$attr{$_}{IOgrp},2; - $pref = "---" if (!$pref); - push @rl, "$defs{$_}{IODev}->{NAME} / $pref $_ "; + if ($md eq "CCU-FHEM"){ + my @dl = grep !/^$/, + map{AttrVal($_,"IOgrp","") =~ m/^$name/ ? $_ : ""} + keys %defs; + my @rl; + foreach (@dl){ + my(undef,$pref) = split":",$attr{$_}{IOgrp},2; + $pref = "---" if (!$pref); + push @rl, "$defs{$_}{IODev}->{NAME} / $pref $_ "; + } + return "devices using $name\ncurrent IO / preferred\n ".join "\n ", sort @rl; + } + elsif ($md eq "ActionDetector"){ + my $re = $a[2]?$a[2]:"all"; + if($re && $re =~ m/^(all|alive|unknown|dead|notAlive)$/){ + my @fnd = map {$_.":".$defs{$name}{READINGS}{$_}{VAL}} + grep /^status_/, + keys %{$defs{ActionDetector}{READINGS}}; + if ($re eq "notAlive"){ @fnd = grep !/:alive$/,@fnd; } + elsif ($re eq "all") {; } + else { @fnd = grep /:$a[2]$/,@fnd;} + $_ =~ s/status_(.*):.*/$1/ foreach(@fnd); + push @fnd,"empty" if (!scalar(@fnd)); + return join",",@fnd; + } else{ + return "please enter parameter [alive|unknown|dead|notAlive]"; + } } - return "devices using $name\ncurrent IO / preferred\n ".join "\n ", sort @rl; } Log3 $name,3,"CUL_HM get $name " . join(" ", @a[1..$#a]); @@ -7763,7 +7806,15 @@ sub CUL_HM_tempListTmpl(@) { ################################################## restore will not delete any peered channels, it will just add peer channels.
  • listDevice
    - returns a list of Devices using the ccu service to assign an IO.
    +
  • when used with ccu it returns a list of Devices using the ccu service to assign an IO.
    +
  • +
  • when used with ActionDetector user will get a comma separated list of entities being assigned to the action detector
    + get ActionDetector listDevice # returns all assigned entities
    + get ActionDetector listDevice notActive# returns entities which habe not status alive
    + get ActionDetector listDevice alive # returns entities with status alive
    + get ActionDetector listDevice unknown # returns entities with status unknown
    + get ActionDetector listDevice dead # returns entities with status dead
    +

  • @@ -8975,7 +9026,15 @@ sub CUL_HM_tempListTmpl(@) { ################################################## "restore" löscht keine verknüpften Kanäle, es fügt nur neue Peers hinzu.
  • listDevice
    - gibt eine Lister der Devices, welche den ccu service zum zuweisen der IOs zurück
    +
  • bei einer CCU gibt es eine Liste der Devices, welche den ccu service zum zuweisen der IOs zurück
    +
  • +
  • beim ActionDetector wird eine Komma geteilte Liste der Entities zurückgegeben
    + get ActionDetector listDevice # returns alle assigned entities
    + get ActionDetector listDevice notActive# returns entities ohne status alive
    + get ActionDetector listDevice alive # returns entities mit status alive
    + get ActionDetector listDevice unknown # returns entities mit status unknown
    + get ActionDetector listDevice dead # returns entities mit status dead
    +