mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
98_dewpoint.pm: Fix event processing when updating STATE
git-svn-id: https://svn.fhem.de/fhem/trunk@15927 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9835ea0971
commit
e5112a15d4
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- bugfix: 98_dewpoint.pm: Fix event processing when updating STATE
|
||||||
- bugfix: 73_ElectricityCalculator.pm: Spelling error
|
- bugfix: 73_ElectricityCalculator.pm: Spelling error
|
||||||
- change: 74_XiaomiBTLESens: Code clean
|
- change: 74_XiaomiBTLESens: Code clean
|
||||||
- feature: 21_HEOSPlayer: add input URL as set command
|
- feature: 21_HEOSPlayer: add input URL as set command
|
||||||
|
@ -203,15 +203,15 @@ dewpoint_Notify($$)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $max = int(@{$dev->{CHANGED}});
|
my $nev = int(@{$dev->{CHANGED}});
|
||||||
my $n = -1;
|
|
||||||
my $lastval;
|
|
||||||
|
|
||||||
|
# if we use the "T H" syntax we must track the index of the state event
|
||||||
|
my $i_state_ev;
|
||||||
|
|
||||||
my $temperature = "";
|
my $temperature = "";
|
||||||
my $humidity = "";
|
my $humidity = "";
|
||||||
|
|
||||||
for (my $i = 0; $i < $max; $i++) {
|
for (my $i = 0; $i < $nev; $i++) {
|
||||||
my $s = $dev->{CHANGED}[$i];
|
my $s = $dev->{CHANGED}[$i];
|
||||||
|
|
||||||
Log3($hashName, 5, "dewpoint_notify: s='$s'");
|
Log3($hashName, 5, "dewpoint_notify: s='$s'");
|
||||||
@ -224,10 +224,8 @@ dewpoint_Notify($$)
|
|||||||
next if(!defined($val));
|
next if(!defined($val));
|
||||||
Log3($hashName, 5, "dewpoint_notify: evName='$evName' val=$val'");
|
Log3($hashName, 5, "dewpoint_notify: evName='$evName' val=$val'");
|
||||||
if (($evName eq "T:") && ($temp_name eq "T")) {
|
if (($evName eq "T:") && ($temp_name eq "T")) {
|
||||||
$n = $i;
|
$i_state_ev = $i;
|
||||||
#my ($evName1, $val1, $evName2, $val2, $rest) = split(" ", $s, 5); # resets $1
|
#my ($evName1, $val1, $evName2, $val2, $rest) = split(" ", $s, 5); # resets $1
|
||||||
#$lastval = $evName1." ".$val1." ".$evName2." ".$val2;
|
|
||||||
$lastval = $s;
|
|
||||||
if ($s =~ /T: ([-+]?[0-9]*\.[0-9]+|[-+]?[0-9]+)/) {
|
if ($s =~ /T: ([-+]?[0-9]*\.[0-9]+|[-+]?[0-9]+)/) {
|
||||||
$temperature = $1;
|
$temperature = $1;
|
||||||
}
|
}
|
||||||
@ -245,13 +243,11 @@ dewpoint_Notify($$)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($n == -1) { $n = $max; }
|
|
||||||
|
|
||||||
#if (($temperature eq "") || ($humidity eq "")) { return undef; } # no way to calculate dewpoint!
|
#if (($temperature eq "") || ($humidity eq "")) { return undef; } # no way to calculate dewpoint!
|
||||||
|
|
||||||
# Check if Attribute timeout is set
|
# Check if Attribute timeout is set
|
||||||
my $timeout = AttrVal($hash->{NAME}, "max_timediff", $dewpoint_time_diff_default);
|
my $timeout = AttrVal($hash->{NAME}, "max_timediff", $dewpoint_time_diff_default);
|
||||||
Log3($hashName, 5,"dewpoint timeout=$timeout");
|
Log3($hashName, 5,"dewpoint max_timediff=$timeout");
|
||||||
|
|
||||||
if (($humidity eq "") && (($temperature eq ""))) {
|
if (($humidity eq "") && (($temperature eq ""))) {
|
||||||
return undef; # no way to calculate dewpoint!
|
return undef; # no way to calculate dewpoint!
|
||||||
@ -318,8 +314,16 @@ dewpoint_Notify($$)
|
|||||||
if ($temp_name ne "T") {
|
if ($temp_name ne "T") {
|
||||||
$current = $dewpoint;
|
$current = $dewpoint;
|
||||||
readingsBulkUpdate($dev, $sensor, $current);
|
readingsBulkUpdate($dev, $sensor, $current);
|
||||||
|
readingsEndUpdate($dev, 1);
|
||||||
} else {
|
} else {
|
||||||
# state begins with "T:". append dewpoint or insert before BAT
|
# explicit manipulation of STATE here
|
||||||
|
# first call readingsEndUpdate to finish STATE processing in the referenced device...
|
||||||
|
|
||||||
|
readingsEndUpdate($dev, 1);
|
||||||
|
|
||||||
|
# ... then update STATE
|
||||||
|
# STATE begins with "T:". append dewpoint or insert before BAT
|
||||||
|
my $lastval = $dev->{CHANGED}[$i_state_ev];
|
||||||
if ($lastval =~ /BAT:/) {
|
if ($lastval =~ /BAT:/) {
|
||||||
$current = $lastval;
|
$current = $lastval;
|
||||||
$current =~ s/BAT:/$sensor: $dewpoint BAT:/g;
|
$current =~ s/BAT:/$sensor: $dewpoint BAT:/g;
|
||||||
@ -334,12 +338,14 @@ dewpoint_Notify($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dev->{STATE} = $current;
|
$dev->{STATE} = $current;
|
||||||
addEvent($dev, $current);
|
# the state event must be REPLACED
|
||||||
|
$dev->{CHANGED}[$i_state_ev] = $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate($dev, 1);
|
# remove cached "state:..." events if any
|
||||||
$dev->{CHANGEDWITHSTATE} = [];
|
$dev->{CHANGEDWITHSTATE} = [];
|
||||||
Log3($hashName, 5, "dewpoint_notify: current=$current");
|
Log3($hashName, 5, "dewpoint_notify: current=$current");
|
||||||
|
|
||||||
} elsif ($cmd_type eq "fan") {
|
} elsif ($cmd_type eq "fan") {
|
||||||
# >define <name> dewpoint fan devicename devicename-outside min-temp [diff-temp]
|
# >define <name> dewpoint fan devicename devicename-outside min-temp [diff-temp]
|
||||||
#
|
#
|
||||||
@ -370,13 +376,14 @@ dewpoint_Notify($$)
|
|||||||
Log3($hashName, 3, "dewpoint_notify: CHANGE fan $current");
|
Log3($hashName, 3, "dewpoint_notify: CHANGE fan $current");
|
||||||
$dev->{READINGS}{$sensor}{TIME} = $tn;
|
$dev->{READINGS}{$sensor}{TIME} = $tn;
|
||||||
$dev->{READINGS}{$sensor}{VAL} = $current;
|
$dev->{READINGS}{$sensor}{VAL} = $current;
|
||||||
$dev->{CHANGED}[$n++] = $sensor . ": " . $current;
|
$dev->{CHANGED}[$nev++] = $sensor . ": " . $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log3($hashName, 1, "dewpoint_notify: fan devname_out=$devname_out no temperature or humidity available"
|
Log3($hashName, 1, "dewpoint_notify: fan devname_out=$devname_out no temperature or humidity available"
|
||||||
. " for dewpoint calculation");
|
. " for dewpoint calculation");
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif ($cmd_type eq "alarm") {
|
} elsif ($cmd_type eq "alarm") {
|
||||||
# >define <name> dewpoint alarm devicename devicename-reference diff
|
# >define <name> dewpoint alarm devicename devicename-reference diff
|
||||||
#
|
#
|
||||||
@ -412,7 +419,7 @@ dewpoint_Notify($$)
|
|||||||
Log3($hashName, 5, "dewpoint_notify: CHANGE alarm $current");
|
Log3($hashName, 5, "dewpoint_notify: CHANGE alarm $current");
|
||||||
$dev->{READINGS}{$sensor}{TIME} = $tn;
|
$dev->{READINGS}{$sensor}{TIME} = $tn;
|
||||||
$dev->{READINGS}{$sensor}{VAL} = $current;
|
$dev->{READINGS}{$sensor}{VAL} = $current;
|
||||||
$dev->{CHANGED}[$n++] = $sensor . ": " . $current;
|
$dev->{CHANGED}[$nev++] = $sensor . ": " . $current;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log3($hashName, 1, "dewpoint_notify: alarm devname_out=$devname_out no temperature or humidity available"
|
Log3($hashName, 1, "dewpoint_notify: alarm devname_out=$devname_out no temperature or humidity available"
|
||||||
@ -424,6 +431,7 @@ dewpoint_Notify($$)
|
|||||||
Log3($hashName, 1, "Error notify_dewpoint: <2> unknown cmd_type ".$cmd_type);
|
Log3($hashName, 1, "Error notify_dewpoint: <2> unknown cmd_type ".$cmd_type);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user