95_YAAHM.pm: Neue Version mit ein paar Verbesserungen

git-svn-id: https://svn.fhem.de/fhem/trunk@15972 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
phenning 2018-01-23 16:52:22 +00:00
parent a15b24bb36
commit f3dbe5d2ca
2 changed files with 188 additions and 180 deletions

View File

@ -32,7 +32,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
use vars qw(%defs); # FHEM device/button definitions use vars qw(%defs); # FHEM device/button definitions
use vars qw(%intAt); # FHEM at definitions
use vars qw($FW_ME); use vars qw($FW_ME);
use vars qw($FW_inform); use vars qw($FW_inform);
use vars qw($FW_headerlines); use vars qw($FW_headerlines);
@ -48,7 +47,7 @@ my $yaahmname;
my $yaahmlinkname = "Profile"; # link text my $yaahmlinkname = "Profile"; # link text
my $yaahmhiddenroom = "ProfileRoom"; # hidden room my $yaahmhiddenroom = "ProfileRoom"; # hidden room
my $yaahmpublicroom = "Unsorted"; # public room my $yaahmpublicroom = "Unsorted"; # public room
my $yaahmversion = "1.33"; my $yaahmversion = "1.43";
my $firstcall = 1; my $firstcall = 1;
my %yaahm_transtable_EN = ( my %yaahm_transtable_EN = (
@ -61,6 +60,7 @@ my %yaahm_transtable_EN = (
"manual" => "Manual Time", "manual" => "Manual Time",
"exceptly" => "exceptionally", "exceptly" => "exceptionally",
"undecid" => "not decidable", "undecid" => "not decidable",
"off" => "off",
"swoff" => "switched off", "swoff" => "switched off",
"and" => "and", "and" => "and",
"clock" => "", "clock" => "",
@ -152,6 +152,7 @@ my %yaahm_transtable_EN = (
"clock" => "Uhr", "clock" => "Uhr",
"exceptly" => "ausnahmsweise", "exceptly" => "ausnahmsweise",
"undecid" => "nicht bestimmbar", "undecid" => "nicht bestimmbar",
"off" => "Aus",
"swoff" => "ausgeschaltet", "swoff" => "ausgeschaltet",
"and" => "und", "and" => "und",
"active" => "Aktiv", "active" => "Aktiv",
@ -334,7 +335,7 @@ my @csstate1 = ("#53f3c7","#ff9458","#f554e2","#fd5777");
#-- temporary fix for update purpose #-- temporary fix for update purpose
sub YAAHM_restore($$){}; sub YAAHM_restore($$){};
sub YAAHM_sayWeeklyTime($$$){}; sub YAAHM_setWeeklyTime($){};
######################################################################################### #########################################################################################
# #
@ -948,7 +949,8 @@ sub YAAHM_Get($@) {
sub YAAHM_save($) { sub YAAHM_save($) {
my ($hash) = @_; my ($hash) = @_;
$hash->{DATA}{"savedate"} = sprintf("%s",localtime(time)); my $date = localtime(time);
$hash->{DATA}{"savedate"} = $date;
readingsSingleUpdate( $hash, "savedate", $hash->{DATA}{"savedate"}, 1 ); readingsSingleUpdate( $hash, "savedate", $hash->{DATA}{"savedate"}, 1 );
my $json = JSON->new->utf8; my $json = JSON->new->utf8;
my $jhash0 = eval{ $json->encode( $hash->{DATA} ) }; my $jhash0 = eval{ $json->encode( $hash->{DATA} ) };
@ -1235,7 +1237,10 @@ sub YAAHM_nextWeeklyTime {
} }
#-- check value - may be empty #-- check value - may be empty
if( $time ne ""){ if( $time eq "" || $time eq "default" ){
$time = "";
#-- nontrivial
}else{
#-- off=ok, do nothing #-- off=ok, do nothing
if( $time eq "off"){ if( $time eq "off"){
#-- time=ok, check #-- time=ok, check
@ -1253,17 +1258,10 @@ sub YAAHM_nextWeeklyTime {
} }
} }
#-- weekly profile times #-- all logic in setweeklytime
my $sg0; $hash->{DATA}{"WT"}[$i]{"next"} = $time;
if( ReadingsVal($name.".wtimer_".$i.".IF","mode","") ne "disabled" ){
$sg0 = $time;
}else{
$sg0 = "off";
}
$hash->{DATA}{"WT"}[$i]{"next"} = $sg0;
YAAHM_setWeeklyTime($hash); YAAHM_setWeeklyTime($hash);
readingsEndUpdate($hash,1);
} }
######################################################################################### #########################################################################################
@ -1694,128 +1692,138 @@ sub YAAHM_setWeeklyTime($) {
#-- iterate over timers #-- iterate over timers
for( my $i=0;$i<int( @{$hash->{DATA}{"WT"}} );$i++){ for( my $i=0;$i<int( @{$hash->{DATA}{"WT"}} );$i++){
#-- obtain next time spec => will override all
#-- TODO: inconsistency, time is off although only timer disabled $ng = $hash->{DATA}{"WT"}[$i]{ "next" };
#-- lowest priority is the waketable - provided, the timer device is enabled #-- highest priority is a disabled timer - no wakeup at all
if( ReadingsVal($name.".wtimer_".$i.".IF","mode","") ne "disabled" ){ if( ReadingsVal($name.".wtimer_".$i.".IF","mode","") eq "disabled" ){
$sg0 = $hash->{DATA}{"WT"}[$i]{ $weeklytable[$hash->{DATA}{"DD"}[0]{"weekday"}] } ;
$sg1 = $hash->{DATA}{"WT"}[$i]{ $weeklytable[$hash->{DATA}{"DD"}[1]{"weekday"}] };
$ng = $hash->{DATA}{"WT"}[$i]{ "next" };
$sg0en = "enabled";
$sg1en = "enabled";
}else{
$sg0 = "off"; $sg0 = "off";
$sg1 = "off"; $sg1 = "off";
$ng = "off";
$sg0en = "disabled (timer)"; $sg0en = "disabled (timer)";
$sg1en = "disabled (timer)"; $sg1en = "disabled (timer)";
} #-- if the timer is enabled, we'll use its timing values
#-- next higher priority is to check for daytype
my $wupad = $hash->{DATA}{"WT"}[$i]{"acti_d"}.",workday,weekend";
if( ($sg0 !~ /^off/) && (index($wupad, $hash->{DATA}{"DD"}[0]{"daytype"}) == -1) ){
$sg0mod = "off (".substr(ReadingsVal($name,"tr_todayType",""),0,3).")";
$sg0en = "disabled (".ReadingsVal($name,"todayType","").")";
}else{ }else{
$sg0mod = $sg0; $sg0 = $hash->{DATA}{"WT"}[$i]{ $weeklytable[$hash->{DATA}{"DD"}[0]{"weekday"}] } ;
$sg0en = "enabled" $sg1 = $hash->{DATA}{"WT"}[$i]{ $weeklytable[$hash->{DATA}{"DD"}[1]{"weekday"}] };
if( $sg0en !~ /^disabled/); $sg0en = "enabled";
} $sg1en = "enabled";
if( ($sg1 !~ /^off/) && (index($wupad, $hash->{DATA}{"DD"}[1]{"daytype"}) == -1) ){ #-- next higher priority for "off" is daytype
$sg1mod = "off (".substr(ReadingsVal($name,"tr_tomorrowType",""),0,3).")"; my $wupad = $hash->{DATA}{"WT"}[$i]{"acti_d"}.",workday,weekend";
$sg1en = "disabled (".ReadingsVal($name,"todayType","").")"; #-- start with tomorrow
}else{ if( index($wupad, $hash->{DATA}{"DD"}[1]{"daytype"}) == -1 ){
$sg1mod = $sg1; $sg1mod = "off (".substr(ReadingsVal($name,"tr_tomorrowType",""),0,3).")";
$sg1en = "enabled" $sg1en = "disabled (".ReadingsVal($name,"tomorrowType","").")";
if( $sg1en !~ /^disabled/); }elsif( ($hash->{DATA}{"DD"}[1]{"vacflag"} == 1 ) && index($wupad,"vacation") == -1 ){
} $sg1mod = "off (".substr($yaahm_tt->{"vacation"},0,3).")";
$sg1en = "disabled (vacation)";
#-- next higher priority is to check for housemode (only today !)
my $wupam = $hash->{DATA}{"WT"}[$i]{"acti_m"}.",normal";
if( ($sg0mod !~ /^off/) && (index($wupam, ReadingsVal($name,"housemode","")) == -1) ){
$sg0mod = "off (".substr(ReadingsVal($name,"tr_housemode",""),0,3).")";
$sg0en = "disabled (".ReadingsVal($name,"housemode","").")";
}
#-- highest priority is a "next" time specification
#-- current time
my ($sec, $min, $hour, $day, $month, $year, $wday,$yday,$isdst) = localtime(time);
my $lga = sprintf("%02d%02d",$hour,$min);
#-- today's waketime
my $tga = $sg0;
$tga =~ s/://;
#-- tomorrow's waketime
my $tgm = $sg1;
$tgm =~ s/://;
#-- "next" input
my $nga = (defined $ng)?$ng:"";
$nga =~ s/://;
#-- "next" is empty
if( $nga eq "" ){
$ring_0 = $sg0;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" }="";
#-- "next" is the same as today and today not over
}elsif( ($nga eq $tga) && ($tga > $lga)){
$ring_0 = $sg0;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" }="";
#-- "next" is the same as tomorrow and today over
}elsif( ($nga eq $tgm) && ($tga < $lga)){
$ring_0 = $sg0;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" }="";
#-- "next" is off
}elsif( $nga eq "off" ){
#-- today's waketime not over => we mean today
if( $tga ne "off" && ($tga > $lga)){
if( $sg0mod !~ /^off/ ){
$sg0mod = "off (man)";
$ring_0 = "off";
$ring_1 = $sg1;
}
#-- today's waketime over => we mean tomorrow
}else{ }else{
if( $sg1mod !~ /^off/ ){ $sg1mod = $sg1;
$sg1mod = "off (man)";
$ring_0 = $sg0;
$ring_1 = "$sg1 (off)";
}
} }
#-- "next" is nontrivial timespec #-- because today we might also have an influence of housemode
}else{ if( index($wupad, $hash->{DATA}{"DD"}[0]{"daytype"}) == -1 ){
#-- "next" after current time => we mean today $sg0mod = "off (".substr(ReadingsVal($name,"tr_todayType",""),0,3).")";
if( $nga > $lga ){ $sg0en = "disabled (".ReadingsVal($name,"todayType","").")";
#-- only restore standard setting (do we come here at all ?) }elsif( ($hash->{DATA}{"DD"}[0]{"vacflag"} == 1 ) && index($wupad,"vacation") == -1 ){
if( $ng eq $sg0 ){ $sg0mod = "off (".substr($yaahm_tt->{"vacation"},0,3).")";
$sg0en = "disabled (vacation)";
}else{
#-- next higher priority for "off" (only today !) is housemode
my $wupam = $hash->{DATA}{"WT"}[$i]{"acti_m"}.",normal";
if( index($wupam, ReadingsVal($name,"housemode","")) == -1 ){
$sg0mod = "off (".substr(ReadingsVal($name,"tr_housemode",""),0,3).")";
$sg0en = "disabled (".ReadingsVal($name,"housemode","").")";
}else{
$sg0mod = $sg0; $sg0mod = $sg0;
$ring_0 = $sg0;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" } = "";
}else{
$sg0mod = "$ng (man)";
$ring_0 = $ng;
}
$ring_1 = $sg1;
#-- "next" before current time => we mean tomorrow
}else{
#-- only restore standard setting (do we come here at all ?)
if( $ng eq $sg1 ){
$sg0mod = $sg1;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" } = "";
}else{
$sg1mod = "$ng (man)";
$ring_1 = "$sg1 ($ng)";
} }
}
}
#Log 1,"====> AFTER INITIAL CHECK TIMER $i sg0=$sg0 sg0mod=$sg0mod sg1=$sg1 sg1mod=$sg1mod ng=$ng";
#-- no "next" time specification
if( !defined($ng) || $ng eq "" ){
$ring_0 = $sg0;
$ring_1 = $sg1;
#-- highest priority is a "next" time specification
}else{
#-- current time
my ($sec, $min, $hour, $day, $month, $year, $wday,$yday,$isdst) = localtime(time);
my $lga = sprintf("%02d%02d",$hour,$min);
#-- today's waketime
my $tga = $sg0;
$tga =~ s/://;
#-- tomorrow's waketime
my $tgm = $sg1;
$tgm =~ s/://;
#-- "next" input
my $nga = (defined $ng)?$ng:"";
$nga =~ s/://;
#-- "next" is the same as todays waketime and todays waketime not over => restore !
if( ($nga eq $tga) && ($tga > $lga)){
$ring_0 = $sg0; $ring_0 = $sg0;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" }="";
#-- "next" is the same as tomorrows waketime and todays waketime over => restore !
}elsif( ($nga eq $tgm) && ($tga < $lga)){
$ring_0 = $sg0;
$ring_1 = $sg1;
$ng = "";
$hash->{DATA}{"WT"}[$i]{ "next" }="";
#-- "next" is off
}elsif( $nga eq "off" ){
#-- today's waketime not over => we mean today
if( $tga ne "off" && ($tga > $lga)){
if( $sg0mod !~ /^off/ ){
$sg0mod = "off (man)";
$ring_0 = "off";
$ring_1 = $sg1;
}
#-- today's waketime over => we mean tomorrow
}else{
if( $sg1mod !~ /^off/ ){
$sg1mod = "off (man)";
$ring_0 = $sg0;
$ring_1 = "$sg1 (off)";
}
}
#-- "next" is nontrivial timespec
}else{
#-- "next" after current time => we mean today
if( $nga > $lga ){
#-- the same as original waketime => restore ! (do we come here at all ?)
#if( $ng eq $sg0 ){
# $sg0mod = $sg0;
# $ring_0 = $sg0;
# $ng = "";
# $hash->{DATA}{"WT"}[$i]{ "next" } = "";
#-- new manual waketime tomorrow
#}else{
$sg0mod = "$ng (man)";
$ring_0 = $ng;
#}
$ring_1 = $sg1;
#-- "next" before current time => we mean tomorrow
}else{
#-- the same as original waketime => restore ! (do we come here at all ?)
#if( $ng eq $sg1 ){
# $sg0mod = $sg1;
# $ring_1 = $sg1;
# $ng = "";
# $hash->{DATA}{"WT"}[$i]{ "next" } = "";
#}else{
$sg1mod = "$ng (man)";
$ring_1 = "$sg1 ($ng)";
#}
$ring_0 = $sg0;
}
} }
} }
$hash->{DATA}{"WT"}[$i]{"ring_0"} = $ring_0;
$hash->{DATA}{"WT"}[$i]{"ring_1"} = $ring_1;
$hash->{DATA}{"WT"}[$i]{"ring_0x"} = $sg0mod;
$hash->{DATA}{"WT"}[$i]{"ring_1x"} = $sg1mod;
$hash->{DATA}{"WT"}[$i]{"ring_0e"} = $sg0en;
$hash->{DATA}{"WT"}[$i]{"ring_1e"} = $sg1en;
#Log 1,"====> AFTER FINAL CHECK TIMER $i sg0=$sg0 sg0mod=$sg0mod sg1=$sg1 sg1mod=$sg1mod ng=$ng";
#Log 1," ".$hash->{DATA}{"WT"}[$i]{"ring_0x"}." ".$hash->{DATA}{"WT"}[$i]{"ring_1x"};
#-- notation: #-- notation:
# today_i is today's waketime of timer i # today_i is today's waketime of timer i
# tomorrow_i is tomorrow's waketime of timer i # tomorrow_i is tomorrow's waketime of timer i
@ -1834,13 +1842,12 @@ sub YAAHM_setWeeklyTime($) {
readingsBulkUpdate( $hash, "tomorrow_".$i."_e",$sg1en ); readingsBulkUpdate( $hash, "tomorrow_".$i."_e",$sg1en );
readingsBulkUpdate( $hash, "ring_".$i,$ring_0 ); readingsBulkUpdate( $hash, "ring_".$i,$ring_0 );
readingsBulkUpdate( $hash, "ring_".$i."_1",$ring_1 ); readingsBulkUpdate( $hash, "ring_".$i."_1",$ring_1 );
readingsBulkUpdate( $hash, "ring_".$i."x",$sg0mod );
readingsBulkUpdate( $hash, "ring_".$i."_1x",$sg1mod );
readingsBulkUpdate( $hash, "next_".$i,$ng ); readingsBulkUpdate( $hash, "next_".$i,$ng );
$hash->{DATA}{"WT"}[$i]{"ring_0"} = $ring_0;
$hash->{DATA}{"WT"}[$i]{"ring_1"} = $ring_1; readingsEndUpdate($hash,1);
$hash->{DATA}{"WT"}[$i]{"ring_0x"} = $sg0mod; YAAHM_sayWeeklyTime($hash,$i,0);
$hash->{DATA}{"WT"}[$i]{"ring_1x"} = $sg1mod;
readingsEndUpdate($hash,1);
YAAHM_sayWeeklyTime($hash,$i,0);
} }
} }
@ -1856,7 +1863,7 @@ sub YAAHM_sayWeeklyTime($$$) {
my ($hash,$timer,$sp) = @_; my ($hash,$timer,$sp) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my ($tod,$tom,$ton,$hl,$ml,$tl,$ht,$mt,$tt,$tsay,$chg,$msg,$hw,$mw,$pt); my ($tod,$tom,$ton,$hl,$ml,$tl,$ht,$mt,$tt,$tsay,$chg,$msg,$hw,$mw,$pt,$rea);
#--determine which timer (duplicate check when coming from set) #--determine which timer (duplicate check when coming from set)
@ -1865,33 +1872,29 @@ sub YAAHM_sayWeeklyTime($$$) {
Log3 $name,1,"[YAAHM_sayNextTime] ".$msg; Log3 $name,1,"[YAAHM_sayNextTime] ".$msg;
return $msg; return $msg;
} }
$tod = $hash->{DATA}{"WT"}[$timer]{"ring_0"};
$tom = $hash->{DATA}{"WT"}[$timer]{"ring_1"};
$ton = $hash->{DATA}{"WT"}[$timer]{"next"};
$msg = $hash->{DATA}{"WT"}[$timer]{"name"};
($hl,$ml) = split(':',strftime('%H:%M', localtime(time))); #-- init message
$tl = 60*$hl+$ml; $msg = $hash->{DATA}{"WT"}[$timer]{"name"};
#-- today off AND tomorrow any time, off or special time #-- get timer values from readings, because these include vacation settings and special time
if( $tod eq "off" ){ $tod = $hash->{DATA}{"WT"}[$timer]{"ring_0x"};
$tom = $hash->{DATA}{"WT"}[$timer]{"ring_1x"};
#-- current local time
($hl,$ml) = split(':',strftime('%H:%M', localtime(time)));
$tl = 60*$hl+$ml;
#-- today off AND tomorrow any time or off
if( $tod =~ /^off.*/ ){
#-- special time #-- special time
if( ($ton =~ /(\d?\d):(\d\d)(:(\d\d))?/) && ($tom ne $ton) ){ if( $tom =~ /(\d?\d):(\d\d)(:(\d\d))?/ && $tom !~ /.*\(off\)$/ ){
$hw = $1*1;
$mw = $2*1;
$pt = sprintf("%d:%02d",$hw,$mw)." ".lc($yaahm_tt->{"tomorrow"});
$msg .= " ".lc($yaahm_tt->{"tomorrow"})." ".$yaahm_tt->{"exceptly"}." $hw ".$yaahm_tt->{"clock"};
$msg .=" $mw"
if( $mw != 0 );
}elsif( $tom =~ /(\d?\d):(\d\d)(:(\d\d))?/ && $tom !~ /.*\(off\)$/ ){
$hw = $1*1; $hw = $1*1;
$mw = $2*1; $mw = $2*1;
$pt = sprintf("%d:%02d",$hw,$mw)." ".lc($yaahm_tt->{"tomorrow"}); $pt = sprintf("%d:%02d",$hw,$mw)." ".lc($yaahm_tt->{"tomorrow"});
$msg .= " ".lc($yaahm_tt->{"tomorrow"})." $hw ".$yaahm_tt->{"clock"}; $msg .= " ".lc($yaahm_tt->{"tomorrow"})." $hw ".$yaahm_tt->{"clock"};
$msg .=" $mw" $msg .=" $mw"
if( $mw != 0 ); if( $mw != 0 );
}elsif( $tom eq "off" || $tom =~ /.*\(off\)$/ ){ }elsif( $tom =~ /^off/ || $tom =~ /.*\(off\)$/ ){
$pt = "off ".lc($yaahm_tt->{"today"})." ".$yaahm_tt->{"and"}." ".lc($yaahm_tt->{"tomorrow"}); $pt = "off ".lc($yaahm_tt->{"today"})." ".$yaahm_tt->{"and"}." ".lc($yaahm_tt->{"tomorrow"});
$msg .= " ".lc($yaahm_tt->{"today"})." ".$yaahm_tt->{"and"}." ".lc($yaahm_tt->{"tomorrow"})." ".$yaahm_tt->{"swoff"}; $msg .= " ".lc($yaahm_tt->{"today"})." ".$yaahm_tt->{"and"}." ".lc($yaahm_tt->{"tomorrow"})." ".$yaahm_tt->{"swoff"};
}else{ }else{
@ -1901,7 +1904,7 @@ sub YAAHM_sayWeeklyTime($$$) {
#-- today nontrivial => compare this time with current time #-- today nontrivial => compare this time with current time
}elsif( $tod =~ /(\d?\d):(\d\d)(:(\d\d))?/ ){ }elsif( $tod =~ /(\d?\d):(\d\d)(:(\d\d))?/ ){
#Log 1,"===========> |$1|$2|$3|$4"; #Log 1,"===========> |$1|$2|$3|$4";
($ht,$mt) = split(':',$tod); ($ht,$mt) = split('[\s:]',$tod);
$tt=60*$ht+$mt; $tt=60*$ht+$mt;
#-- wakeup later today #-- wakeup later today
if( $tt >= $tl ){ if( $tt >= $tl ){
@ -1928,6 +1931,9 @@ sub YAAHM_sayWeeklyTime($$$) {
$msg .= " ".lc($yaahm_tt->{"tomorrow"})." $hw ".$yaahm_tt->{"clock"}; $msg .= " ".lc($yaahm_tt->{"tomorrow"})." $hw ".$yaahm_tt->{"clock"};
$msg .=" $mw" $msg .=" $mw"
if( $mw != 0 ); if( $mw != 0 );
}elsif( $tom =~ /^off/ || $tom =~ /.*\(off\)$/ ){
$pt = "off ".lc($yaahm_tt->{"tomorrow"});
$msg .= " ".lc($yaahm_tt->{"tomorrow"})." ".$yaahm_tt->{"swoff"};
}else{ }else{
$pt = $yaahm_tt->{"undecid"}; $pt = $yaahm_tt->{"undecid"};
$msg .= " ".$yaahm_tt->{"undecid"}; $msg .= " ".$yaahm_tt->{"undecid"};
@ -2262,12 +2268,14 @@ sub YAAHM_GetDayStatus($) {
$hash->{DATA}{"DD"}[0]{"weekday"} = (strftime('%w', localtime(time))+6)%7; $hash->{DATA}{"DD"}[0]{"weekday"} = (strftime('%w', localtime(time))+6)%7;
$hash->{DATA}{"DD"}[0]{"daytype"} = "workday"; $hash->{DATA}{"DD"}[0]{"daytype"} = "workday";
$hash->{DATA}{"DD"}[0]{"desc"} = $yaahm_tt->{"workday"}; $hash->{DATA}{"DD"}[0]{"desc"} = $yaahm_tt->{"workday"};
$hash->{DATA}{"DD"}[0]{"vacflag"} = 0;
$tomtype = "workday"; $tomtype = "workday";
$hash->{DATA}{"DD"}[1]{"date"} = $stom; $hash->{DATA}{"DD"}[1]{"date"} = $stom;
$hash->{DATA}{"DD"}[1]{"weekday"} = (strftime('%w', localtime(time+86400))+6)%7; $hash->{DATA}{"DD"}[1]{"weekday"} = (strftime('%w', localtime(time+86400))+6)%7;
$hash->{DATA}{"DD"}[1]{"daytype"} = "workday"; $hash->{DATA}{"DD"}[1]{"daytype"} = "workday";
$hash->{DATA}{"DD"}[1]{"desc"} = $yaahm_tt->{"workday"}; $hash->{DATA}{"DD"}[1]{"desc"} = $yaahm_tt->{"workday"};
$hash->{DATA}{"DD"}[1]{"vacflag"} = 0;
#-- vacation = vacdays has higher priority #-- vacation = vacdays has higher priority
my $vacdayDevs = AttrVal( $name, "vacationDevices", "" ); my $vacdayDevs = AttrVal( $name, "vacationDevices", "" );
@ -2280,13 +2288,13 @@ sub YAAHM_GetDayStatus($) {
if ( $tod ne "none" ) { if ( $tod ne "none" ) {
$todaydesc = $tod; $todaydesc = $tod;
$todaytype = "vacday"; $todaytype = "vacday";
Log3 $name, 1,"[YAAHM] found today=vacation \"$todaydesc\" in holiday $vacdayDev"; Log3 $name, 5,"[YAAHM] found today=vacation \"$todaydesc\" in holiday $vacdayDev";
} }
$tod = holiday_refresh( $vacdayDev, $stom ); $tod = holiday_refresh( $vacdayDev, $stom );
if ( $tod ne "none" ) { if ( $tod ne "none" ) {
$tomdesc = $tod; $tomdesc = $tod;
$tomtype = "vacday"; $tomtype = "vacday";
Log3 $name, 1,"[YAAHM] found tomorrow=vacation \"$tomdesc\" in holiday $vacdayDev"; Log3 $name, 5,"[YAAHM] found tomorrow=vacation \"$tomdesc\" in holiday $vacdayDev";
} }
#-- device of type calendar #-- device of type calendar
}elsif( IsDevice($vacdayDev, "Calendar" )){ }elsif( IsDevice($vacdayDev, "Calendar" )){
@ -2310,14 +2318,14 @@ sub YAAHM_GetDayStatus($) {
if( ($rete>=0) && ($rets<=0) ){ if( ($rete>=0) && ($rets<=0) ){
$todaydesc = $chunks[5]; $todaydesc = $chunks[5];
$todaytype = "vacation"; $todaytype = "vacation";
Log3 $name, 1,"[YAAHM] found today=vacation \"$todaydesc\" in calendar $vacdayDev"; Log3 $name, 5,"[YAAHM] found today=vacation \"$todaydesc\" in calendar $vacdayDev";
} }
$rets = ($sday[2]-$tmor[2])*365+($sday[1]-$tmor[1])*31+($sday[0]-$tmor[0]); $rets = ($sday[2]-$tmor[2])*365+($sday[1]-$tmor[1])*31+($sday[0]-$tmor[0]);
$rete = ($eday[2]-$tmor[2])*365+($eday[1]-$tmor[1])*31+($eday[0]-$tmor[0]); $rete = ($eday[2]-$tmor[2])*365+($eday[1]-$tmor[1])*31+($eday[0]-$tmor[0]);
if( ($rete>=0) && ($rets<=0) ){ if( ($rete>=0) && ($rets<=0) ){
$tomdesc = $chunks[5]; $tomdesc = $chunks[5];
$tomtype = "vacation"; $tomtype = "vacation";
Log3 $name, 1,"[YAAHM] found tomorrow=vacation \"$tomdesc\" in calendar $vacdayDev"; Log3 $name, 5,"[YAAHM] found tomorrow=vacation \"$tomdesc\" in calendar $vacdayDev";
} }
} }
} }
@ -2329,15 +2337,15 @@ sub YAAHM_GetDayStatus($) {
if( $todaytype eq "vacation" ){ if( $todaytype eq "vacation" ){
$hash->{DATA}{"DD"}[0]{"daytype"} = "vacation"; $hash->{DATA}{"DD"}[0]{"daytype"} = "vacation";
$hash->{DATA}{"DD"}[0]{"desc"} = $todaydesc; $hash->{DATA}{"DD"}[0]{"desc"} = $todaydesc;
}else{ $hash->{DATA}{"DD"}[0]{"vacflag"} = 1;
} }
if( $tomtype eq "vacation" ){ if( $tomtype eq "vacation" ){
$hash->{DATA}{"DD"}[1]{"daytype"} = "vacation"; $hash->{DATA}{"DD"}[1]{"daytype"} = "vacation";
$hash->{DATA}{"DD"}[1]{"desc"} = $tomdesc; $hash->{DATA}{"DD"}[1]{"desc"} = $tomdesc;
}else{ $hash->{DATA}{"DD"}[1]{"vacflag"} = 1;
} }
#-- weekend has higher priority #-- weekend has higher priority
if( strftime('%u', localtime(time)) > 5){ if( strftime('%u', localtime(time)) > 5){
$todaytype = "weekend"; $todaytype = "weekend";
if( $hash->{DATA}{"DD"}[0]{"daytype"} ne "workday" ){ if( $hash->{DATA}{"DD"}[0]{"daytype"} ne "workday" ){
@ -2355,7 +2363,7 @@ sub YAAHM_GetDayStatus($) {
}else{ }else{
$hash->{DATA}{"DD"}[1]{"desc"} = $yaahm_tt->{"weekend"}; $hash->{DATA}{"DD"}[1]{"desc"} = $yaahm_tt->{"weekend"};
} }
$hash->{DATA}{"DD"}[1]{"daytype"} = "weekend"; $hash->{DATA}{"DD"}[1]{"daytype"} = "weekend";
} }
#-- holidays have the highest priority #-- holidays have the highest priority
@ -3022,7 +3030,7 @@ sub YAAHM_timewidget($){
FW_pO '<path d="M 0 0 '.$x_morning.' '.$y_morning.' A '.$radius.' '.$radius.' 0 0 1 '.$x_evening.' '.$y_evening.' Z" fill="url(#grad1)"/>'; FW_pO '<path d="M 0 0 '.$x_morning.' '.$y_morning.' A '.$radius.' '.$radius.' 0 0 1 '.$x_evening.' '.$y_evening.' Z" fill="url(#grad1)"/>';
#-- evening to sunset sector #-- evening to sunset sector
$dir = ( $ss < $ev ) ? 0 : 1; $dir = ( $ss < $ev ) ? 1 : 0;
FW_pO '<path d="M 0 0 '.$x_evening.' '.$y_evening.' A '.$radius.' '.$radius.' 0 0 '.$dir.' '.$x_sunset.' '.$y_sunset.' Z" fill="url(#grad2)"/>'; FW_pO '<path d="M 0 0 '.$x_evening.' '.$y_evening.' A '.$radius.' '.$radius.' 0 0 '.$dir.' '.$x_sunset.' '.$y_sunset.' Z" fill="url(#grad2)"/>';
#-- midnight line #-- midnight line
@ -3097,7 +3105,6 @@ sub YAAHM_toptable($){
my ($styl,$stym,$styr); my ($styl,$stym,$styr);
my $ret = ""; my $ret = "";
YAAHM_GetDayStatus($hash); YAAHM_GetDayStatus($hash);
#-- #--
my $lockstate = ($hash->{READINGS}{lockstate}{VAL}) ? $hash->{READINGS}{lockstate}{VAL} : "unlocked"; my $lockstate = ($hash->{READINGS}{lockstate}{VAL}) ? $hash->{READINGS}{lockstate}{VAL} : "unlocked";
my $showhelper = ($lockstate eq "unlocked") ? 1 : 0; my $showhelper = ($lockstate eq "unlocked") ? 1 : 0;
@ -3149,7 +3156,7 @@ sub YAAHM_toptable($){
for( my $i=0; $i<$cols; $i++){ for( my $i=0; $i<$cols; $i++){
if( $i < int(@modes)){ if( $i < int(@modes)){
$ret .= "<td width=\"120px\"><input type=\"button\" id=\"b_".$modes[$i]."\" value=\"".$yaahm_tt->{$modes[$i]}. $ret .= "<td width=\"120px\"><input type=\"button\" id=\"b_".$modes[$i]."\" value=\"".$yaahm_tt->{$modes[$i]}.
"\" style=\"height:20px; width:120px;\" onclick=\"javascript:yaahm_mode('$name','".$modes[$i]."')\"/></td>"; "\" style=\"width:120px;\" onclick=\"javascript:yaahm_mode('$name','".$modes[$i]."')\"/></td>";
}else{ }else{
$ret .= "<td width=\"120px\"></td>"; $ret .= "<td width=\"120px\"></td>";
} }
@ -3162,7 +3169,7 @@ sub YAAHM_toptable($){
for( my $i=0; $i<$cols; $i++){ for( my $i=0; $i<$cols; $i++){
if( $i < int(@states)){ if( $i < int(@states)){
$ret .= "<td width=\"120px\"><input type=\"button\" id=\"b_".$states[$i]."\" value=\"".$yaahm_tt->{$states[$i]}. $ret .= "<td width=\"120px\"><input type=\"button\" id=\"b_".$states[$i]."\" value=\"".$yaahm_tt->{$states[$i]}.
"\" style=\"height:20px; width:120px;\" onclick=\"javascript:yaahm_state('$name','".$states[$i]."')\"/></td>"; "\" style=\"width:120px;\" onclick=\"javascript:yaahm_state('$name','".$states[$i]."')\"/></td>";
}else{ }else{
$ret .= "<td width=\"120px\"></td>"; $ret .= "<td width=\"120px\"></td>";
} }
@ -3251,17 +3258,9 @@ sub YAAHM_toptable($){
} }
#-- ring times #-- ring times
my $ring_0 = $hash->{DATA}{"WT"}[$i]{"ring_0x"}; my $ring_0x = $hash->{DATA}{"WT"}[$i]{"ring_0x"};
my $ring_0_e = ReadingsVal($name,"today_".$i."_e",""); my $ring_1x = $hash->{DATA}{"WT"}[$i]{"ring_1x"};
if( $ring_0_e=~ /^disabled \((.*)\)/ ){ my $wake = $hash->{DATA}{"WT"}[$i]{"wake"};
$ring_0 = 'off ('.substr($yaahm_tt->{$1},0,3).')';
}
my $ring_1 = $hash->{DATA}{"WT"}[$i]{"ring_1x"};
my $ring_1_e = ReadingsVal($name,"tomorrow_".$i."_e","");
if( $ring_1_e=~ /^disabled \((.*)\)/ ){
$ring_1 = 'off ('.substr($yaahm_tt->{$1},0,3).')';
}
my $wake = $hash->{DATA}{"WT"}[$i]{"wake"};
#-- border styles #-- border styles
@ -3280,8 +3279,8 @@ sub YAAHM_toptable($){
} }
$ret.="<td style=\"padding:5px;$styl\">".$wupn. $ret.="<td style=\"padding:5px;$styl\">".$wupn.
"</td><td style=\"text-align:center;width:30px;padding:5px;$stym\">$ts</td>". "</td><td style=\"text-align:center;width:30px;padding:5px;$stym\">$ts</td>".
"<td style=\"padding:5px;$stym\"><div class=\"dval\" informId=\"$name-ring_$i\">".$ring_0."</div></td>". "<td style=\"padding:5px;$stym\"><div class=\"dval\" informId=\"$name-ring_".$i."x\">".$ring_0x."</div></td>".
"<td style=\"padding:5px;$stym\"><div class=\"dval\" informId=\"$name-ring_".$i."_1\">".$ring_1."</div></td>". "<td style=\"padding:5px;$stym\"><div class=\"dval\" informId=\"$name-ring_".$i."_1x\">".$ring_1x."</div></td>".
"<td style=\"padding:5px;$styr\"><div class=\"dval\" informId=\"$name-tr_wake_$i\">".$wake."</div></td></tr>\n"; "<td style=\"padding:5px;$styr\"><div class=\"dval\" informId=\"$name-tr_wake_$i\">".$wake."</div></td></tr>\n";
} }
$ret .= "</table></td></tr>\n"; $ret .= "</table></td></tr>\n";
@ -3616,8 +3615,12 @@ sub YAAHM_Longtable($){
<li><a name="yaahm_manualnext"></a> <li><a name="yaahm_manualnext"></a>
<code>set &lt;name&gt; manualnext &lt;timernumber&gt; &lt;time&gt;</code><br/> <code>set &lt;name&gt; manualnext &lt;timernumber&gt; &lt;time&gt;</code><br/>
<code>set &lt;name&gt; manualnext &lt;timername&gt; &lt;time&gt;</code><br/> <code>set &lt;name&gt; manualnext &lt;timername&gt; &lt;time&gt;</code><br/>
For the weekly timer identified by its number (starting at 0) or its name, set the next ring time manually. The time specification &lt;time&gt;must be in the format hh:mm or "off" For the weekly timer identified by its number (starting at 0) or its name, set the next ring time manually. The time specification &lt;time&gt;must be in the format hh:mm, or "off", or "default".
If the time specification &lt;time&gt; is later than the current time, it will be used for today. If it is earlier than the current time, it will be used tomorrow. <ul>
<li>If the time specification &lt;time&gt; is later than the current time, it will be used for today. If it is earlier than the current time, it will be used tomorrow.</li>
<li>If the time specification is "off", the next pending waketime will be ignored.</li>
<li>If the time specification id "default", the manual waketime is removed and the value from the weekly schedule will be used.</li>
</ul>
</li> </li>
<li><a name="yaahm_mode"> <li><a name="yaahm_mode">
<code>set &lt;name&gt; mode normal | party | absence | donotdisturb</code> <code>set &lt;name&gt; mode normal | party | absence | donotdisturb</code>

View File

@ -1,15 +1,20 @@
//######################################################################################## //########################################################################################
// yaahm.js // yaahm.js
// Version 1.30 // Version 1.4
// See 95_YAAHM for licensing // See 95_YAAHM for licensing
//######################################################################################## //########################################################################################
//# Prof. Dr. Peter A. Henning //# Prof. Dr. Peter A. Henning
function encodeParm(oldval) { function encodeParm(oldval) {
var newval; var newval;
newval = oldval.replace(/\+/g, '%2B'); newval = oldval.replace(/"/g, '%27');
newval = newval.replace(/#/g, '%23'); newval = newval.replace(/#/g, '%23');
newval = newval.replace(/"/g, '%27'); newval = newval.replace(/\+/g, '%2B');
newval = newval.replace(/&/g, '%26');
newval = newval.replace(/'/g, '%27');
newval = newval.replace(/=/g, '%3D');
newval = newval.replace(/\?/g, '%3F');
newval = newval.replace(/\|/g, '%7C');
return newval; return newval;
} }