From 6094e83d149eb06002a77c5d0c865c075a40dd42 Mon Sep 17 00:00:00 2001 From: HomeAuto_User <> Date: Sun, 2 Feb 2020 21:45:50 +0000 Subject: [PATCH] 88_Timer: fix2 list "Probably associated with" Forum: #1015549 git-svn-id: https://svn.fhem.de/fhem/trunk@21098 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/88_Timer.pm | 77 +++++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index c25967dd1..b0aadc1d8 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 88_Timer: fix2 list "Probably associated with" Forum: #1015549 - new: 70_DENON_AVR: initial commit. - bugfix: 93_DbLog: fix warning, Forum: #107950 - feature: 98_weekprofile: new command import_profile diff --git a/fhem/FHEM/88_Timer.pm b/fhem/FHEM/88_Timer.pm index 5a5d8d343..1800987ca 100644 --- a/fhem/FHEM/88_Timer.pm +++ b/fhem/FHEM/88_Timer.pm @@ -267,7 +267,8 @@ sub Timer_Set($$$@) { my $deleteTimer = "Timer_$cmd2"."_set:textField-long"; Timer_delFromUserattr($hash,$deleteTimer); - addStructChange("modify", $name, "attr $name userattr Timer_$cmd2"); # note with question mark + Timer_PawList($hash); # list, Probably associated with + addStructChange("modify", $name, "attr $name userattr Timer_$cmd2"); # note with question mark } return $setList if ( $a[0] eq "?"); @@ -378,6 +379,8 @@ sub Timer_Get($$$@) { CommandAttr($hash,"$name $attr_values_names[$i] $attr_values[$i]"); } + Timer_PawList($hash); # list, Probably associated with + readingsSingleUpdate($hash, "state" , "Timers loaded", 1); FW_directNotify("FILTER=(room=)?$name", "#FHEMWEB:WEB", "location.reload('true')", ""); Timer_Check($hash); @@ -408,6 +411,7 @@ sub Timer_Attr() { if ($attrName =~ /^Timer_\d{2}_set$/) { my $err = perlSyntaxCheck($attrValue, ()); # check PERL Code + InternalTimer(gettimeofday()+0.1, "Timer_PawList", $hash); return $err if($err); } } @@ -425,6 +429,11 @@ sub Timer_Attr() { $cnt_attr_userattr = 0; } } + + if ($attrName =~ /^Timer_\d{2}_set$/) { + Log3 $name, 3, "$name: Attr | Attributes $attrName deleted"; + InternalTimer(gettimeofday()+0.1, "Timer_PawList", $hash); + } } } @@ -804,26 +813,7 @@ sub FW_pushed_savebutton { readingsBulkUpdate($hash, "state" , $state, 1); readingsEndUpdate($hash, 1); - ## Probably associated with - added to list ## - ### check must work after changed setreadings to new value ### - ## all device must check, for right value in .associatedWith - my $associatedWith = ReadingsVal($name, ".associatedWith", ""); - - foreach my $d (sort keys %{$hash->{READINGS}}) { - if ($d =~ /^Timer_(\d+)$/) { - my @values = split("," , ReadingsVal($name, $d, "")); - if ($values[7] ne "DEF") { - #Log3 $name, 5, "$name: FW_pushed_savebutton | Reading .associatedWith check: ".$values[6]." with ".$values[7]; - if (not grep /$values[6]/, $associatedWith) { - #Log3 $name, 5, "$name: FW_pushed_savebutton | Reading .associatedWith added ".$values[6]; - $associatedWith = $associatedWith eq "" ? $values[6] : $associatedWith.",".$values[6]; - } - } - } - } - Log3 $name, 5, "$name: FW_pushed_savebutton | Reading .associatedWith is: ".$associatedWith; - CommandSetReading(undef, "$name .associatedWith $associatedWith"); - ## current list "Probably associated with" finish ## + Timer_PawList($hash); # list, Probably associated with ## popup user message (jump to javascript) ## if ($popup != 0) { @@ -971,6 +961,51 @@ sub Timer_Check($) { readingsEndUpdate($hash, 1); } +### list, Probably associated with ### +sub Timer_PawList($) { + my ($hash) = @_; + my $name = $hash->{NAME}; + my $associatedWith = ""; + + Log3 $name, 5, "$name: Timer_PawList is running"; + + foreach my $d (keys %{$hash->{READINGS}}) { + if ($d =~ /^Timer_(\d+)$/) { + my @values = split("," , ReadingsVal($name, $d, "")); + ### clear value, "Probably associated with" ne DEF + if ($values[7] ne "DEF") { + if (not grep /$values[6]/, $associatedWith) { + $associatedWith = $associatedWith eq "" ? $values[6] : $associatedWith.",".$values[6]; + } + ### Self-administration test, "Probably associated with" for DEF + } elsif ($values[7] eq "DEF") { + my $Timer_set_attr = AttrVal($name, $d."_set", ""); + if ($Timer_set_attr ne "") { + Log3 $name, 5, "$name: Timer_PawList | look at DEF: ".$Timer_set_attr; + $Timer_set_attr =~ /(get|set)\s(\w+)\s/; + if ($2) { + Log3 $name, 5, "$name: Timer_PawList | found in DEF: ".$2; + if (not grep /$2/, $associatedWith) { + $associatedWith = $associatedWith eq "" ? $2 : $associatedWith.",".$2; + } + } + } + } + ### END ### + } + } + + Log3 $name, 5, "$name: Timer_PawList | Reading .associatedWith is: ".$associatedWith; + if ($associatedWith ne "") { + CommandSetReading(undef, "$name .associatedWith $associatedWith"); + } else { + readingsDelete($hash,".associatedWith") if(ReadingsVal($name, ".associatedWith", undef)); + } + ## current list "Probably associated with" finish ## +} + +########################################## + # Eval-Rückgabewert für erfolgreiches # Laden des Moduls 1;