Multi-Holiday allowed

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1622 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2012-06-16 08:33:44 +00:00
parent 40bf2e3407
commit 40c0d83570
3 changed files with 19 additions and 18 deletions

View File

@@ -43,6 +43,7 @@
- feature: new parameter <changed> for updatefhem added (M. Fischer) - feature: new parameter <changed> for updatefhem added (M. Fischer)
new global attribute <exclude_from_update> added (M. Fischer) new global attribute <exclude_from_update> added (M. Fischer)
- feature: optional telnet password added / telnet port is optional - feature: optional telnet password added / telnet port is optional
- feature: holiday returns all matches, not only the first.
- 2011-12-31 (5.2) - 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera - bugfix: applying smallscreen attributes to firefox/opera

View File

@@ -62,17 +62,18 @@ holiday_refresh($$)
my $fname = $attr{global}{modpath} . "/FHEM/" . $hash->{NAME} . ".holiday"; my $fname = $attr{global}{modpath} . "/FHEM/" . $hash->{NAME} . ".holiday";
return "Can't open $fname: $!" if(!open(FH, $fname)); return "Can't open $fname: $!" if(!open(FH, $fname));
my $found = "none"; my @foundList;
while(my $l = <FH>) { while(my $l = <FH>) {
next if($l =~ m/^\s*#/); next if($l =~ m/^\s*#/);
next if($l =~ m/^\s*$/); next if($l =~ m/^\s*$/);
chomp($l); chomp($l);
my $found;
if($l =~ m/^1/) { # Exact date: 1 MM-DD Holiday if($l =~ m/^1/) { # Exact date: 1 MM-DD Holiday
my @args = split(" +", $l, 3); my @args = split(" +", $l, 3);
if($args[1] eq $fordate) { if($args[1] eq $fordate) {
$found = $args[2]; $found = $args[2];
last;
} }
} elsif($l =~ m/^2/) { # Easter date: 2 +1 Ostermontag } elsif($l =~ m/^2/) { # Easter date: 2 +1 Ostermontag
@@ -98,7 +99,6 @@ holiday_refresh($$)
next if($mday != $fd[3] || $mmonth != $fd[4]+1); next if($mday != $fd[3] || $mmonth != $fd[4]+1);
$found = $a[2]; $found = $a[2];
Log 4, "$name: Match day: $a[2]\n"; Log 4, "$name: Match day: $a[2]\n";
last;
} elsif($l =~ m/^3/) { # Relative date: 3 -1 Mon 03 Holiday } elsif($l =~ m/^3/) { # Relative date: 3 -1 Mon 03 Holiday
my @a = split(" +", $l, 5); my @a = split(" +", $l, 5);
@@ -123,13 +123,11 @@ holiday_refresh($$)
} }
$found = $a[4]; $found = $a[4];
last;
} elsif($l =~ m/^4/) { # Interval: 4 MM-DD MM-DD Holiday } elsif($l =~ m/^4/) { # Interval: 4 MM-DD MM-DD Holiday
my @args = split(" +", $l, 4); my @args = split(" +", $l, 4);
if($args[1] le $fordate && $args[2] ge $fordate) { if($args[1] le $fordate && $args[2] ge $fordate) {
$found = $args[3]; $found = $args[3];
last;
} }
} elsif($l =~ m/^5/) { # nth weekday since MM-DD / before MM-DD } elsif($l =~ m/^5/) { # nth weekday since MM-DD / before MM-DD
@@ -157,7 +155,6 @@ holiday_refresh($$)
# needs to be lower than max and greater than or equal to min # needs to be lower than max and greater than or equal to min
if( ($cd ge $tgtmin) && ( $cd lt $tgtmax) ) { if( ($cd ge $tgtmin) && ( $cd lt $tgtmax) ) {
$found=$a[5]; $found=$a[5];
last;
} }
} elsif ( $a[1] =~ /^\+?([0-9])*$/ ) { } elsif ( $a[1] =~ /^\+?([0-9])*$/ ) {
$tgtmin += ($1-1)*$weeksecs; # Minimum: target date plus $1-1 weeks $tgtmin += ($1-1)*$weeksecs; # Minimum: target date plus $1-1 weeks
@@ -165,17 +162,20 @@ holiday_refresh($$)
# needs to be lower than or equal to max and greater min # needs to be lower than or equal to max and greater min
if( ($cd gt $tgtmin) && ( $cd le $tgtmax) ) { if( ($cd gt $tgtmin) && ( $cd le $tgtmax) ) {
$found=$a[5]; $found=$a[5];
last;
} }
} else { } else {
Log 1, "Wrong distance spec: $l"; Log 1, "Wrong distance spec: $l";
next; next;
} }
} }
push @foundList, $found if($found);
} }
close(FH); close(FH);
push @foundList, "none" if(!int(@foundList));
my $found = join(", ", @foundList);
RemoveInternalTimer($name); RemoveInternalTimer($name);
$nt -= ($lt[2]*3600+$lt[1]*60+$lt[0]); # Midnight $nt -= ($lt[2]*3600+$lt[1]*60+$lt[0]); # Midnight
$nt += 86400 + 2; # Tomorrow $nt += 86400 + 2; # Tomorrow

View File

@@ -9165,14 +9165,14 @@ KlikAanKlikUit, NEXA, CHACON, HomeEasy UK. <br> You need to define an RFXtrx433
<br><br> <br><br>
Define a set of holidays. The module will try to open the file Define a set of holidays. The module will try to open the file
&lt;name&gt;.holiday in the <a href="#modpath">modpath</a>/FHEM directory. &lt;name&gt;.holiday in the <a href="#modpath">modpath</a>/FHEM directory.
If an entry in the holiday file matches the current day, then the STATE of If entries in the holiday file match the current day, then the STATE of
this holiday instance displayed in the <a href="#list">list</a> command this holiday instance displayed in the <a href="#list">list</a> command
will be set to the holiday, else the state is set to the text none. Most will be set to the corresponding values, else the state is set to the text
probably you'll want to query this value in some perl script: see Value() in none. Most probably you'll want to query this value in some perl script:
the <a href="#perl">perl</a> section or the global attribute <a see Value() in the <a href="#perl">perl</a> section or the global attribute
href="#holiday2we"> holiday2we</a>.<br> <a href="#holiday2we"> holiday2we</a>.<br> The file will be reread once
The file will be reread once every night, to compute the value for the every night, to compute the value for the current day, and by each get
current day, and by each get command (see below).<br> command (see below).<br>
<br> <br>
Holiday file definition:<br> Holiday file definition:<br>