2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

98_monitoring: notifyRegexpChanged

git-svn-id: https://svn.fhem.de/fhem/trunk@17168 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
igami 2018-08-19 05:43:46 +00:00
parent 5058301290
commit 1ddd6dd7fb

View File

@ -9,18 +9,17 @@
# #
# This file is part of FHEM. # This file is part of FHEM.
# #
# FHEM is free software: you can redistribute it and/or modify # FHEM is free software: you can redistribute it and/or modify it under the
# it under the terms of the GNU General Public License as published by # terms of the GNU General Public License as published by the Free Software
# the Free Software Foundation, either version 2 of the License, or # Foundation, either version 2 of the License, or (at your option) any later
# (at your option) any later version. # version.
# #
# FHEM is distributed in the hope that it will be useful, # FHEM is distributed in the hope that it will be useful, but WITHOUT ANY
# but WITHOUT ANY WARRANTY; without even the implied warranty of # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License along with
# along with FHEM. If not, see <http://www.gnu.org/licenses/>. # FHEM. If not, see <http://www.gnu.org/licenses/>.
# packages #################################################################### # packages ####################################################################
package main; package main;
@ -54,23 +53,23 @@ sub monitoring_Initialize($) {
$hash->{AttrFn} = $TYPE."_Attr"; $hash->{AttrFn} = $TYPE."_Attr";
$hash->{NotifyFn} = $TYPE."_Notify"; $hash->{NotifyFn} = $TYPE."_Notify";
$hash->{AttrList} = "" $hash->{AttrList} =
. "addStateEvent:1,0 " "addStateEvent:1,0 ".
. "blacklist:textField-long " "blacklist:textField-long ".
. "disable:1,0 " "disable:1,0 ".
. "disabledForIntervals " "disabledForIntervals ".
. "errorFuncAdd:textField-long " "errorFuncAdd:textField-long ".
. "errorFuncRemove:textField-long " "errorFuncRemove:textField-long ".
. "errorWait " "errorWait ".
. "errorReturn:textField-long " "errorReturn:textField-long ".
. "getDefault:all,error,warning " "getDefault:all,error,warning ".
. "setActiveFunc:textField-long " "setActiveFunc:textField-long ".
. "warningFuncAdd:textField-long " "warningFuncAdd:textField-long ".
. "warningFuncRemove:textField-long " "warningFuncRemove:textField-long ".
. "warningWait " "warningWait ".
. "warningReturn:textField-long " "warningReturn:textField-long ".
. "whitelist:textField-long " "whitelist:textField-long ".
. $readingFnAttributes $readingFnAttributes
; ;
} }
@ -106,20 +105,20 @@ sub monitoring_Set($@) {
my $argument = shift @a; my $argument = shift @a;
my $value = join(" ", @a) if (@a); my $value = join(" ", @a) if (@a);
my %monitoring_sets = ( my %monitoring_sets = (
"active" => "active:noArg" "active" => "active:noArg",
, "clear" => "clear:all,error,warning" "clear" => "clear:all,error,warning",
, "errorAdd" => "errorAdd:textField" "errorAdd" => "errorAdd:textField",
, "errorRemove" => "errorRemove:" "errorRemove" => "errorRemove:".
. join(",", ReadingsVal($SELF, "error", "")) join(",", ReadingsVal($SELF, "error", "")),
, "inactive" => "inactive:noArg" "inactive" => "inactive:noArg",
, "warningAdd" => "warningAdd:textField" "warningAdd" => "warningAdd:textField",
, "warningRemove" => "warningRemove:" "warningRemove" => "warningRemove:".
. join(",", ReadingsVal($SELF, "warning", "")) join(",", ReadingsVal($SELF, "warning", ""))
); );
return( return(
"Unknown argument $argument, choose one of " "Unknown argument $argument, choose one of ".
. join(" ", sort(values %monitoring_sets)) join(" ", sort(values %monitoring_sets))
) unless(exists($monitoring_sets{$argument})); ) unless(exists($monitoring_sets{$argument}));
if($argument eq "active"){ if($argument eq "active"){
@ -185,16 +184,16 @@ sub monitoring_Get($@) {
my $value = join(" ", @a) if (@a); my $value = join(" ", @a) if (@a);
my $default = AttrVal($SELF, "getDefault", "all"); my $default = AttrVal($SELF, "getDefault", "all");
my %monitoring_gets = ( my %monitoring_gets = (
"all" => "all:noArg" "all" => "all:noArg",
, "default" => "default:noArg" "default" => "default:noArg",
, "error" => "error:noArg" "error" => "error:noArg",
, "warning" => "warning:noArg" "warning" => "warning:noArg"
); );
my @ret; my @ret;
return( return(
"Unknown argument $argument, choose one of " "Unknown argument $argument, choose one of ".
. join(" ", sort(values %monitoring_gets)) join(" ", sort(values %monitoring_gets))
) unless(exists($monitoring_gets{$argument})); ) unless(exists($monitoring_gets{$argument}));
if($argument eq "all" || ($argument eq "default" && $default eq "all")){ if($argument eq "all" || ($argument eq "default" && $default eq "all")){
@ -267,10 +266,10 @@ sub monitoring_Notify($$) {
my $TYPE = $hash->{TYPE}; my $TYPE = $hash->{TYPE};
return if( return if(
!$init_done !$init_done ||
|| IsDisabled($SELF) IsDisabled($SELF) ||
|| IsDisabled($name) IsDisabled($name) ||
|| $SELF eq $name # do not process own events $SELF eq $name # do not process own events
); );
my $events = deviceEvents($dev_hash, AttrVal($SELF, "addStateEvent", 0)); my $events = deviceEvents($dev_hash, AttrVal($SELF, "addStateEvent", 0));
@ -286,9 +285,9 @@ sub monitoring_Notify($$) {
my ($addRegex, $removeRegex) = split(/[\s]+/, InternalVal($SELF, "DEF", "")); my ($addRegex, $removeRegex) = split(/[\s]+/, InternalVal($SELF, "DEF", ""));
return unless( return unless(
$addRegex =~ m/^$name:/ $addRegex =~ m/^$name:/ ||
|| $removeRegex && $removeRegex =~ m/^$name:/ $removeRegex && $removeRegex =~ m/^$name:/ ||
|| $events $events
); );
my @blacklist; my @blacklist;
@ -322,16 +321,16 @@ sub monitoring_Notify($$) {
$listWait = 0 unless(looks_like_number($listWait)); $listWait = 0 unless(looks_like_number($listWait));
if($listFuncAdd eq "preset" && $listFuncRemove eq "preset"){ if($listFuncAdd eq "preset" && $listFuncRemove eq "preset"){
Log3($SELF, 5 Log3(
, "$TYPE ($SELF) " $SELF, 5 "$TYPE ($SELF) ".
. $list."FuncAdd and " $list."FuncAdd and $list"."FuncRemove are preset"
. $list."FuncRemove are preset"
); );
if(!$removeRegex){ if(!$removeRegex){
if($listWait == 0){ if($listWait == 0){
Log3($SELF, 2 Log3(
, "$TYPE ($SELF) set \"$list"."Wait\" while \"$list" $SELF, 2, "$TYPE ($SELF) ".
. "FuncAdd\" and \"$list"."FuncRemove\" are same" "set \"$list"."Wait\" while \"$list".
"FuncAdd\" and \"$list"."FuncRemove\" are same"
) if($list eq "error"); ) if($list eq "error");
next; next;
@ -340,18 +339,16 @@ sub monitoring_Notify($$) {
Log3($SELF, 5, "$TYPE ($SELF) only addRegex is defined"); Log3($SELF, 5, "$TYPE ($SELF) only addRegex is defined");
monitoring_modify("$SELF|$list|remove|$name"); monitoring_modify("$SELF|$list|remove|$name");
monitoring_modify( monitoring_modify("$SELF|$list|add|$name|$listWait");
"$SELF|$list|add|$name|$listWait"
);
next; next;
} }
else{ else{
next unless($list eq "error" || AttrVal($SELF, "errorWait", undef)); next unless($list eq "error" || AttrVal($SELF, "errorWait", undef));
Log3($SELF, 5 Log3(
, "$TYPE ($SELF) addRegex ($addRegex) " $SELF, 5, "$TYPE ($SELF) ".
. "and removeRegex ($removeRegex) are defined" "addRegex ($addRegex) and removeRegex ($removeRegex) are defined"
); );
monitoring_modify("$SELF|$list|remove|$name") if($removeMatch); monitoring_modify("$SELF|$list|remove|$name") if($removeMatch);
@ -368,9 +365,10 @@ sub monitoring_Notify($$) {
if($listFuncRemove eq "preset"){ if($listFuncRemove eq "preset"){
if($listWait == 0){ if($listWait == 0){
Log3($SELF, 2 Log3(
, "$TYPE ($SELF) set \"$list"."Wait\" while \"$list" $SELF, 2, "$TYPE ($SELF) ".
. "FuncAdd\" and \"$list"."FuncRemove\" are same" "set \"$list"."Wait\" while \"$list".
"FuncAdd\" and \"$list"."FuncRemove\" are same"
) if($list eq "error"); ) if($list eq "error");
next; next;
@ -380,9 +378,9 @@ sub monitoring_Notify($$) {
} }
} }
else{ else{
Log3($SELF, 5 Log3(
, "$TYPE ($SELF) addRegex ($addRegex) " $SELF, 5, "$TYPE ($SELF) ".
. "and removeRegex ($removeRegex) are defined" "addRegex ($addRegex) and removeRegex ($removeRegex) are defined"
); );
$listFuncRemove = 1 if($listFuncRemove eq "preset" && $removeMatch); $listFuncRemove = 1 if($listFuncRemove eq "preset" && $removeMatch);
@ -420,12 +418,12 @@ sub monitoring_modify($) {
my $reading = $list."Add_".$value; my $reading = $list."Add_".$value;
Log3( Log3(
$SELF, 5 , "$TYPE ($SELF)" $SELF, 5 , "$TYPE ($SELF)".
. "\n entering monitoring_modify" "\n entering monitoring_modify".
. "\n reading: $list" "\n reading: $list".
. "\n operation: $operation" "\n operation: $operation".
. "\n value: $value" "\n value: $value".
. "\n at: ".($at ? FmtDateTime($at) : "now") "\n at: ".($at ? FmtDateTime($at) : "now")
); );
if($operation eq "add"){ if($operation eq "add"){
@ -437,9 +435,7 @@ sub monitoring_modify($) {
if($at){ if($at){
return if($hash->{READINGS}{$reading}); return if($hash->{READINGS}{$reading});
readingsSingleUpdate( readingsSingleUpdate($hash, $reading, FmtDateTime($at), 0);
$hash, $reading, FmtDateTime($at), 0
);
InternalTimer($at, "monitoring_modify", $arg); InternalTimer($at, "monitoring_modify", $arg);
return; return;
@ -483,7 +479,7 @@ sub monitoring_NOTIFYDEV($) {
; ;
$NOTIFYDEV =~ s/\s/,/g; $NOTIFYDEV =~ s/\s/,/g;
$hash->{NOTIFYDEV} = $NOTIFYDEV; notifyRegexpChanged($hash, $NOTIFYDEV);
} }
sub monitoring_RemoveInternalTimer($) { sub monitoring_RemoveInternalTimer($) {