From 81c1b86b5046d98b509cbf5364f51b08c4b4f17c Mon Sep 17 00:00:00 2001
From: mgehre <>
Date: Tue, 12 Feb 2013 04:20:59 +0000
Subject: [PATCH] MAX: parse weekProfile after setting
git-svn-id: https://svn.fhem.de/fhem/trunk@2698 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/10_MAX.pm | 93 ++++++++++++++++++++++++---------------------
1 file changed, 50 insertions(+), 43 deletions(-)
diff --git a/fhem/FHEM/10_MAX.pm b/fhem/FHEM/10_MAX.pm
index 26835b610..63273495b 100755
--- a/fhem/FHEM/10_MAX.pm
+++ b/fhem/FHEM/10_MAX.pm
@@ -175,6 +175,52 @@ MAX_ReadingsVal(@)
return $val;
}
+sub
+MAX_ParseWeekProfile(@) {
+ my ($hash ) = @_;
+ # Format of weekprofile: 16 bit integer (high byte first) for every control point, 13 control points for every day
+ # each 16 bit integer value is parsed as
+ # int time = (value & 0x1FF) * 5;
+ # int hour = (time / 60) % 24;
+ # int minute = time % 60;
+ # int temperature = ((value >> 9) & 0x3F) / 2;
+
+ my $beginUpdate = !exists($hash->{".updateTimestamp"});
+ readingsBeginUpdate($hash) if($beginUpdate);
+
+ my $curWeekProfile = MAX_ReadingsVal($hash, ".weekProfile");
+ #parse weekprofiles for each day
+ for (my $i=0;$i<7;$i++) {
+ my (@time_prof, @temp_prof);
+ for(my $j=0;$j<13;$j++) {
+ $time_prof[$j] = (hex(substr($curWeekProfile,($i*52)+ 4*$j,4))& 0x1FF) * 5;
+ $temp_prof[$j] = (hex(substr($curWeekProfile,($i*52)+ 4*$j,4))>> 9 & 0x3F ) / 2;
+ }
+
+ my @hours;
+ my @minutes;
+ my $j;
+ for($j=0;$j<13;$j++) {
+ $hours[$j] = ($time_prof[$j] / 60 % 24);
+ $minutes[$j] = ($time_prof[$j]%60);
+ #if 00:00 reached, last point in profile was found
+ last if(int($hours[$j])==0 && int($minutes[$j])==0 );
+ }
+ my $time_prof_str = "00:00";
+ my $temp_prof_str;
+ for (my $k=0;$k<=$j;$k++) {
+ $time_prof_str .= sprintf("-%02d:%02d", $hours[$k], $minutes[$k]);
+ $temp_prof_str .= sprintf("%2.1f °C",$temp_prof[$k]);
+ if ($k < $j) {
+ $time_prof_str .= " / " . sprintf("%02d:%02d", $hours[$k], $minutes[$k]);
+ $temp_prof_str .= " / ";
+ }
+ }
+ readingsBulkUpdate($hash, "weekprofile-$i-$decalcDays{$i}-time", $time_prof_str );
+ readingsBulkUpdate($hash, "weekprofile-$i-$decalcDays{$i}-temp", $temp_prof_str );
+ }
+ readingsEndUpdate($hash, 1) if($beginUpdate);
+}
#############################
sub
MAX_Set($@)
@@ -381,6 +427,7 @@ MAX_Set($@)
substr($curWeekProfile, $day*52, length($newWeekprofilePart)) = $newWeekprofilePart;
}
readingsSingleUpdate($hash, ".weekProfile", $curWeekProfile, 0);
+ MAX_ParseWeekProfile($hash);
Log 5, "New weekProfile: " . MAX_ReadingsVal($hash, ".weekProfile");
}else{
@@ -608,47 +655,7 @@ MAX_Parse($$)
readingsBulkUpdate($shash, ".weekProfile", $args[4]);
}
- # Format of weekprofile: 16 bit integer (high byte first) for every control point, 13 control points for every day
- # each 16 bit integer value is parsed as
- # int time = (value & 0x1FF) * 5;
- # int hour = (time / 60) % 24;
- # int minute = time % 60;
- # int temperature = ((value >> 9) & 0x3F) / 2;
-
- my $curWeekProfile = MAX_ReadingsVal($shash, ".weekProfile");
- #parse weekprofiles for each day
- for (my $i=0;$i<7;$i++) {
- my (@time_prof, @temp_prof);
- for(my $j=0;$j<13;$j++) {
- $time_prof[$j] = (hex(substr($curWeekProfile,($i*52)+ 4*$j,4))& 0x1FF) * 5;
- $temp_prof[$j] = (hex(substr($curWeekProfile,($i*52)+ 4*$j,4))>> 9 & 0x3F ) / 2;
- }
-
- my @hours;
- my @minutes;
- my $j;
- for($j=0;$j<13;$j++) {
- $hours[$j] = ($time_prof[$j] / 60 % 24);
- $minutes[$j] = ($time_prof[$j]%60);
- #if 00:00 reached, last point in profile was found
- last if(int($hours[$j])==0 && int($minutes[$j])==0 );
- }
-
- my $time_prof_str = "00:00";
- my $temp_prof_str;
- for (my $k=0;$k<=$j;$k++) {
- $time_prof_str .= sprintf("-%02d:%02d", $hours[$k], $minutes[$k]);
- $temp_prof_str .= sprintf("%2.1f °C",$temp_prof[$k]);
- if ($k < $j) {
- $time_prof_str .= " / " . sprintf("%02d:%02d", $hours[$k], $minutes[$k]);
- $temp_prof_str .= " / ";
- }
- }
-
- readingsBulkUpdate($shash, "weekprofile-$i-$decalcDays{$i}-time", $time_prof_str );
- readingsBulkUpdate($shash, "weekprofile-$i-$decalcDays{$i}-temp", $temp_prof_str );
-
- } # Endparse weekprofiles for each day
+ MAX_ParseWeekProfile($shash);
} elsif($msgtype eq "Error") {
if(@args == 0) {
@@ -798,8 +805,8 @@ MAX_Parse($$)
Allows setting the week profile. For devices of type HeatingThermostat or WallMountedThermostat only. Example:
set MAX_12345 weekprofile Fri 24.5,6:00,12,15:00,5 Sat 7,4:30,19,12:55,6
sets the profile
- Friday: 24.5 C for 0:00 - 6:00, 12 C for 6:00 - 15:00, 5 C for 15:00 - 0:00
- Saturday: 7 C for 0:00 - 4:30, 19 C for 4:30 - 12:55, 6 C for 12:55 - 0:00
+ Friday: 24.5 °C for 0:00 - 6:00, 12 °C for 6:00 - 15:00, 5 °C for 15:00 - 0:00
+ Saturday: 7 °C for 0:00 - 4:30, 19 °C for 4:30 - 12:55, 6 °C for 12:55 - 0:00
while keeping the old profile for all other days.