10_MAX.pm: fix save reading serialnum

git-svn-id: https://svn.fhem.de/fhem/trunk@21992 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Wzut
2020-05-21 15:07:33 +00:00
parent e1a7592792
commit ff264d88ce

View File

@@ -1306,123 +1306,96 @@ sub MAX_Save
return; return;
} }
sub MAX_saveConfig sub MAX_saveConfig {
{
my $name = shift; my $name = shift;
my $fname = shift; my $fname = shift;
$fname //= $name;
my $hash = $defs{$name}; my $hash = $defs{$name};
my $devtype = int($hash->{devtype}); my $devtype = int($hash->{devtype});
$fname = $name if (!$fname);
my $dir = AttrVal('global', 'logdir', './log/'); my $dir = AttrVal('global', 'logdir', './log/');
$dir .='/' if ($dir !~ m/\/$/); $dir .='/' if ($dir !~ m/\/$/);
my @lines; my @lines;
my %h; my %h;
if (($devtype < 4) || ($devtype == 8)) # HT , HT+ , WT if (($devtype < 4) || ($devtype == 8)) { # HT , HT+ , WT
{
$h{'21comfortTemperature'} = MAX_ReadingsVal($hash,"comfortTemperature"); $h{'21comfortTemperature'} = MAX_ReadingsVal($hash, 'comfortTemperature');
$h{'22.comfortTemperature'} = $h{'21comfortTemperature'}; $h{'22.comfortTemperature'} = $h{'21comfortTemperature'};
$h{'23.ecoTemperature'} = MAX_ReadingsVal($hash, 'ecoTemperature');
$h{'23.ecoTemperature'} = MAX_ReadingsVal($hash,"ecoTemperature"); $h{'25.maximumTemperature'} = MAX_ReadingsVal($hash, 'maximumTemperature');
#$h{'24.ecoTemperature'} = $h{'23ecoTemperature'}; $h{'27.minimumTemperature'} = MAX_ReadingsVal($hash, 'minimumTemperature');
$h{'29.measurementOffset'} = MAX_ReadingsVal($hash, 'measurementOffset');
$h{'25.maximumTemperature'} = MAX_ReadingsVal($hash,"maximumTemperature"); $h{'31.windowOpenTemperature'} = MAX_ReadingsVal($hash, 'windowOpenTemperature');
#$h{'26.maximumTemperature'} = $h{'25maximumTemperature'}; $h{'00groupid'} = MAX_ReadingsVal($hash, 'groupid');
$h{'27.minimumTemperature'} = MAX_ReadingsVal($hash,"minimumTemperature");
#$h{'28.minimumTemperature'} = $h{'27minimumTemperature'};
$h{'29.measurementOffset'} = MAX_ReadingsVal($hash,"measurementOffset");
#$h{'30.measurementOffset'} = $h{'29measurementOffset'};
$h{'31.windowOpenTemperature'} = MAX_ReadingsVal($hash,"windowOpenTemperature");
#$h{'32.windowOpenTemperature'} = $h{'31windowOpenTemperature'};
$h{'00groupid'} = MAX_ReadingsVal($hash, "groupid");
$h{'01.groupid'} = $h{'00groupid'}; $h{'01.groupid'} = $h{'00groupid'};
$h{'02.SerialNr'} = ReadingsVal($name, 'SerialNr', '???');
$h{'09'} = '#'; $h{'09'} = '#';
$h{'50..weekProfile'} = MAX_ReadingsVal($hash, ".weekProfile"); $h{'50..weekProfile'} = MAX_ReadingsVal($hash, '.weekProfile');
$h{'98.peers'} = ReadingsVal($name,'peers',undef); $h{'98.peers'} = ReadingsVal($name, 'peers', '???');
$h{'99.PairedTo'} = ReadingsVal($name,'PairedTo',undef); $h{'99.PairedTo'} = ReadingsVal($name, 'PairedTo', '???');
$h{'35displayActualTemperature'} = ReadingsVal($name,'displayActualTemperature',undef) if ($devtype == 3); $h{'35displayActualTemperature'} = ReadingsVal($name, 'displayActualTemperature', '???') if ($devtype == 3);
$h{'36.displayActualTemperature'}= $h{'35displayActualTemperature'}; $h{'36.displayActualTemperature'}= $h{'35displayActualTemperature'} if ($devtype == 3);
$h{'59'} = '#'; $h{'59'} = '#';
$h{'61.temperature'} = MAX_ReadingsVal($hash,"temperature"); $h{'61.temperature'} = MAX_ReadingsVal($hash, 'temperature');
$h{'62.msgcnt'} = 0; $h{'62.msgcnt'} = 0;
$h{'69'} = '#'; $h{'69'} = '#';
} }
if (($devtype == 1) || ($devtype == 2) || ($devtype == 8)) # HT , HT+ if (($devtype == 1) || ($devtype == 2) || ($devtype == 8)) { # HT , HT+
{
$h{'10decalcification'} = MAX_ReadingsVal($hash,"decalcification");
$h{'11.decalcification'} = $h{'10decalcification'};
$h{'12.boostDuration'} = MAX_ReadingsVal($hash,"boostDuration");
$h{'13.boostValveposition'} = MAX_ReadingsVal($hash,"boostValveposition");
$h{'14.maxValveSetting'} = MAX_ReadingsVal($hash,"maxValveSetting");
$h{'15.valveOffset'} = MAX_ReadingsVal($hash,"valveOffset");
$h{'10decalcification'} = MAX_ReadingsVal($hash, 'decalcification');
$h{'11.decalcification'} = $h{'10decalcification'};
$h{'12.boostDuration'} = MAX_ReadingsVal($hash, 'boostDuration');
$h{'13.boostValveposition'} = MAX_ReadingsVal($hash, 'boostValveposition');
$h{'14.maxValveSetting'} = MAX_ReadingsVal($hash, 'maxValveSetting');
$h{'15.valveOffset'} = MAX_ReadingsVal($hash, 'valveOffset');
$h{'20'} = '#'; $h{'20'} = '#';
$h{'33.windowOpenDuration'} = MAX_ReadingsVal($hash,"windowOpenDuration"); $h{'33.windowOpenDuration'} = MAX_ReadingsVal($hash,'windowOpenDuration');
#$h{'34.windowOpenDuration'} = $h{'33windowOpenDuration'};
$h{'39'} = '#'; $h{'39'} = '#';
} }
foreach (sort keys %h) foreach my $val (sort keys %h) {
{ next if (!defined($h{$val}) || (defined($h{$val}) && ($h{$val} eq '???')));
if (defined($h{$_}))
{ if ($h{$val} eq '#') {
if ($h{$_} eq '#')
{
push @lines,'##############################################'; push @lines,'##############################################';
next; next;
} }
my $r = substr($_,2,length($_)); # die Sortierung abschneiden my $r = substr($val,2,length($val)); # die Sortierung abschneiden
if (substr($r,0,1) ne '.') if (substr($r,0,1) ne '.') {
{ push @lines,'set '.$fname.' '.$r.' '.$h{$val};
push @lines,'set '.$fname.' '.$r.' '.$h{$_};
}
else
{
push @lines,'setreading '.$fname.' '.substr($r,1,length($r)).' '.$h{$_};
} }
else {
push @lines,'setreading '.$fname.' '.substr($r,1,length($r)).' '.$h{$val};
} }
} }
$hash->{saveConfig} = 1; $hash->{saveConfig} = 1;
my @ar = MAX_ParseWeekProfile($hash); my @ar = MAX_ParseWeekProfile($hash);
delete $hash->{saveConfig}; delete $hash->{saveConfig};
my @json; my @j_arr;
foreach (@ar) foreach my $line (@ar) {
{ push @lines, $line if ($line && (substr($line,0,1) ne '"'));
push @lines , $_ if ($_ && (substr($_,0,1) ne '"')); push @j_arr, $line if ($line && (substr($line,0,1) eq '"'));
push @json , $_ if ($_ && (substr($_,0,1) eq '"'));
} }
my $json = '{'; $json .= join(',',@json); $json .= '}'; push @lines , "setreading $name .wp_json ".'{'.join(',', @j_arr).'}';
push @lines , "setreading $name .wp_json ".$json;
my $error = FileWrite($dir.$fname.'.max', @lines); my $error = FileWrite($dir.$fname.'.max', @lines);
if ($error) if ($error) {
{ Log3 $hash,2,"$name, configSave : $error"; } Log3($name, 2, "$name, configSave : $error");
else
{
if(exists($hash->{".updateTimestamp"})) # readingsBulkUpdate ist aktiv, wird von fhem.pl gesetzt/gelöscht
{
readingsBulkUpdate($hash,'lastConfigSave',$dir.$fname.'.max');
readingsBulkUpdate($hash,'.wp_json',$json);
}
else
{ readingsBeginUpdate($hash);
readingsBulkUpdate($hash,'lastConfigSave',$dir.$fname.'.max');
readingsBulkUpdate($hash,'.wp_json',$json);
readingsEndUpdate($hash,1);
}
}
return $error; return $error;
} }
my $bulk = (exists($hash->{'.updateTimestamp'})) ? 1 : 0; # readingsBulkUpdate ist aktiv, wird von fhem.pl gesetzt/gelöscht
readingsBeginUpdate($hash) if(!$bulk);
readingsBulkUpdate($hash, 'lastConfigSave', $dir.$fname.'.max');
readingsBulkUpdate($hash, '.wp_json', '{'.join(',', @j_arr).'}');
readingsEndUpdate($hash, 1) if(!$bulk);
return;
}
sub MAXX_Restore sub MAXX_Restore
{ {
my $name = shift; my $name = shift;