mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
98_weekprofile: send values for on/off instead of "on"/"off"
git-svn-id: https://svn.fhem.de/fhem/trunk@16140 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
59f39ebf6e
commit
c1fe8aaa2d
@ -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.
|
||||
- changed: 98_weekprofile: send values for on/off instead of "on"/"off"
|
||||
- feature: 93_DbRep: V7.9.0, new attribute "avgTimeWeightMean" (averageValue)
|
||||
some code review and corrections
|
||||
- bugfix: 88_xs1Bridge: fix Code
|
||||
|
@ -14,6 +14,8 @@ use warnings;
|
||||
use JSON; #libjson-perl
|
||||
use Data::Dumper;
|
||||
|
||||
use Storable qw(dclone);
|
||||
|
||||
use vars qw(%defs);
|
||||
use vars qw($FW_ME);
|
||||
use vars qw($FW_wname);
|
||||
@ -82,6 +84,17 @@ sub weekprofile_timeToMinutes($)
|
||||
return $hours * 60 + $minutes;
|
||||
}
|
||||
##############################################
|
||||
sub myAttrVal($$$)
|
||||
{
|
||||
my ($me,$name,$def) = @_;
|
||||
my $val = AttrVal($me, $name, $def);
|
||||
|
||||
if (defined($val) && ($name eq 'tempON' || $name eq 'tempOFF')) {
|
||||
$val = sprintf("%.1f", $val);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
##############################################
|
||||
sub weekprofile_getDeviceType($$;$)
|
||||
{
|
||||
my ($me,$device,$sndrcv) = @_;
|
||||
@ -209,8 +222,8 @@ sub weekprofile_readDayProfile($@)
|
||||
for(my $i = 0; $i < scalar(@temps); $i+=1){
|
||||
Log3 $me, 4, "$me(ReadDayProfile): temp $i $temps[$i]";
|
||||
$temps[$i] =~s/[^\d.]//g; #only numbers
|
||||
my $tempON = AttrVal($me, "tempON", undef);
|
||||
my $tempOFF = AttrVal($me, "tempOFF", undef);
|
||||
my $tempON = myAttrVal($me, "tempON", undef);
|
||||
my $tempOFF = myAttrVal($me, "tempOFF", undef);
|
||||
|
||||
$temps[$i] =~s/$tempOFF/off/g if (defined($tempOFF)); # temp off
|
||||
$temps[$i] =~s/$tempON/on/g if (defined($tempON)); # temp on
|
||||
@ -290,6 +303,8 @@ sub weekprofile_sendDevProfile(@)
|
||||
|
||||
my $devPrf = weekprofile_readDevProfile($device,$type,$me);
|
||||
|
||||
|
||||
|
||||
# only send changed days
|
||||
my @dayToTransfer = ();
|
||||
foreach my $day (@shortDays){
|
||||
@ -321,19 +336,33 @@ sub weekprofile_sendDevProfile(@)
|
||||
return undef;
|
||||
}
|
||||
|
||||
#make a copy because of replacements
|
||||
my $prfData= dclone($prf->{DATA});
|
||||
my $tempON = myAttrVal($me, "tempON", "30.5");
|
||||
my $tempOFF = myAttrVal($me, "tempOFF", "4.5");
|
||||
|
||||
#replace variables with values
|
||||
foreach my $day (@dayToTransfer){
|
||||
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||
$prfData->{$day}->{"temp"}[$i] = $tempON if ($prfData->{$day}->{"temp"}[$i] =~/on/i);
|
||||
$prfData->{$day}->{"temp"}[$i] = $tempOFF if ($prfData->{$day}->{"temp"}[$i] =~/off/i);
|
||||
}
|
||||
}
|
||||
|
||||
my $cmd;
|
||||
if($type eq "MAX") {
|
||||
$cmd = "set $device weekProfile ";
|
||||
foreach my $day (@dayToTransfer){
|
||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
||||
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||
|
||||
$cmd.=$day.' ';
|
||||
|
||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||
my $endTime = $prf->{DATA}->{$day}->{"time"}[$i];
|
||||
my $endTime = $prfData->{$day}->{"time"}[$i];
|
||||
|
||||
$endTime = ($endTime eq "24:00") ? ' ' : ','.$endTime.',';
|
||||
$cmd.=$prf->{DATA}->{$day}->{"temp"}[$i].$endTime;
|
||||
$cmd.=$prfData->{$day}->{"temp"}[$i].$endTime;
|
||||
}
|
||||
}
|
||||
} elsif ($type eq "CUL_HM") {
|
||||
@ -344,9 +373,9 @@ sub weekprofile_sendDevProfile(@)
|
||||
$cmd .= $day;
|
||||
$cmd .= ($k < $dayCnt-1) ? " prep": " exec";
|
||||
|
||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
||||
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||
$cmd .= " ".$prf->{DATA}->{$day}->{"time"}[$i]." ".$prf->{DATA}->{$day}->{"temp"}[$i];
|
||||
$cmd .= " ".$prfData->{$day}->{"time"}[$i]." ".$prfData->{$day}->{"temp"}[$i];
|
||||
}
|
||||
$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
||||
$k++;
|
||||
@ -361,10 +390,10 @@ sub weekprofile_sendDevProfile(@)
|
||||
my $dpTime = "P1_ENDTIME_$reading";
|
||||
my $dpTemp = "P1_TEMPERATURE_$reading";
|
||||
|
||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
||||
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||
$cmd .= " " . $dpTemp . "_" . ($i + 1) . "=" . $prf->{DATA}->{$day}->{"temp"}[$i];
|
||||
$cmd .= " " . $dpTime . "_" . ($i + 1) . "=" . weekprofile_timeToMinutes($prf->{DATA}->{$day}->{"time"}[$i]);
|
||||
$cmd .= " " . $dpTemp . "_" . ($i + 1) . "=" . $prfData->{$day}->{"temp"}[$i];
|
||||
$cmd .= " " . $dpTime . "_" . ($i + 1) . "=" . weekprofile_timeToMinutes($prfData->{$day}->{"time"}[$i]);
|
||||
}
|
||||
|
||||
#$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
||||
@ -1036,7 +1065,7 @@ sub weekprofile_Attr($$$)
|
||||
weekprofile_writeProfilesToFile($hash) if ($attrName eq 'configFile');
|
||||
|
||||
if ($attrName eq 'tempON') {
|
||||
my $tempOFF = AttrVal($me, "tempOFF", $attrVal);
|
||||
my $tempOFF = myAttrVal($me, "tempOFF", $attrVal);
|
||||
if ($tempOFF > $attrVal) {
|
||||
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempON must be bigger than tempOFF";
|
||||
|
||||
@ -1044,7 +1073,7 @@ sub weekprofile_Attr($$$)
|
||||
}
|
||||
|
||||
if ($attrName eq 'tempOFF') {
|
||||
my $tempON = AttrVal($me, "tempON", $attrVal);
|
||||
my $tempON = myAttrVal($me, "tempON", $attrVal);
|
||||
if ($tempON < $attrVal) {
|
||||
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempOFF must be smaller than tempON";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user