2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

98_weekprofile: create default profile if master device has no week profile

git-svn-id: https://svn.fhem.de/fhem/trunk@10400 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
risiko79 2016-01-07 19:00:48 +00:00
parent e592eb1ca1
commit fb82405e68
2 changed files with 21 additions and 8 deletions

View File

@ -1,5 +1,7 @@
# 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.
- change: 98_weekprofile: create default profile if master device
has no week profile
- bugfix: allowed without a validFor is invalid. - bugfix: allowed without a validFor is invalid.
- feature: 98_weekprofile: detect profile changes in master device - feature: 98_weekprofile: detect profile changes in master device
- feature: 49_SSCam: Function "Get" for retrieval Camera-Readings added, - feature: 49_SSCam: Function "Get" for retrieval Camera-Readings added,

View File

@ -100,7 +100,7 @@ sub weekprofile_readDayProfile($@)
if($type eq "MAX") { if($type eq "MAX") {
@temps = split('/',ReadingsVal($device,"$reading-temp","")); @temps = split('/',ReadingsVal($device,"$reading-temp",""));
@times = split('/',ReadingsVal($device,"$reading-time","")); @times = split('/',ReadingsVal($device,"$reading-time",""));
# only use to to interval 'from-to' # only use to from interval 'from-to'
for(my $i = 0; $i < scalar(@times); $i+=1){ for(my $i = 0; $i < scalar(@times); $i+=1){
my $interval = $times[$i]; my $interval = $times[$i];
my @parts = split('-',$interval); my @parts = split('-',$interval);
@ -139,13 +139,18 @@ sub weekprofile_readDevProfile(@)
my $prf = {}; my $prf = {};
foreach my $day (@shortDays){ foreach my $day (@shortDays){
my ($dayTimes, $dayTemps) = weekprofile_readDayProfile($device,$day,$type,$me); my ($dayTimes, $dayTemps) = weekprofile_readDayProfile($device,$day,$type,$me);
if (scalar(@{$dayTemps})==0) {
push(@{$dayTimes}, "24:00");
push(@{$dayTemps}, "18.0");
Log3 $me, 3, "WARNING master device $device has no day profile for $day - create default";
}
$prf->{$day}->{"temp"} = $dayTemps; $prf->{$day}->{"temp"} = $dayTemps;
$prf->{$day}->{"time"} = $dayTimes; $prf->{$day}->{"time"} = $dayTimes;
} }
return $prf; return $prf;
} }
############################################## ##############################################
sub weekprofile_createDefaultPofile(@) sub weekprofile_createDefaultProfile(@)
{ {
my ($hash) = @_; my ($hash) = @_;
my $prf = {}; my $prf = {};
@ -256,14 +261,18 @@ sub weekprofile_assignDev($)
my $prfDev = weekprofile_readDevProfile($hash->{MASTERDEV}->{NAME},$type, $me); my $prfDev = weekprofile_readDevProfile($hash->{MASTERDEV}->{NAME},$type, $me);
$prf = {};
$prf->{NAME} = 'master';
if(defined($prfDev)) { if(defined($prfDev)) {
$prf = {};
$prf->{DATA} = $prfDev; $prf->{DATA} = $prfDev;
$prf->{NAME} = 'master'; } else {
Log3 $me, 3, "WARNING master device $hash->{MASTERDEV}->{NAME} has no week profile - create default profile";
$prf->{DATA} = weekprofile_createDefaultProfile($hash);
} }
$hash->{STATE} = "assigned"; $hash->{STATE} = "assigned";
} else { } else {
my $prfDev = weekprofile_createDefaultPofile($hash); my $prfDev = weekprofile_createDefaultProfile($hash);
if(defined($prfDev)) { if(defined($prfDev)) {
$prf = {}; $prf = {};
$prf->{DATA} = $prfDev; $prf->{DATA} = $prfDev;
@ -340,8 +349,10 @@ sub weekprofile_Define($$)
#$attr{$me}{verbose} = 5; #$attr{$me}{verbose} = 5;
weekprofile_assignDev($hash); if ($init_done) {
weekprofile_updateReadings($hash); weekprofile_assignDev($hash);
weekprofile_updateReadings($hash);
}
return undef; return undef;
} }