From 40c0d835701a6f260127645d1bb91325d2bd33ed Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sat, 16 Jun 2012 08:33:44 +0000 Subject: [PATCH] Multi-Holiday allowed git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1622 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 1 + FHEM/95_holiday.pm | 22 +++++++++++----------- docs/commandref.html | 14 +++++++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGED b/CHANGED index 3858ac38e..531f633d6 100644 --- a/CHANGED +++ b/CHANGED @@ -43,6 +43,7 @@ - feature: new parameter for updatefhem added (M. Fischer) new global attribute added (M. Fischer) - feature: optional telnet password added / telnet port is optional + - feature: holiday returns all matches, not only the first. - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/FHEM/95_holiday.pm b/FHEM/95_holiday.pm index 20b08fbb1..2eb0b902c 100755 --- a/FHEM/95_holiday.pm +++ b/FHEM/95_holiday.pm @@ -62,17 +62,18 @@ holiday_refresh($$) my $fname = $attr{global}{modpath} . "/FHEM/" . $hash->{NAME} . ".holiday"; return "Can't open $fname: $!" if(!open(FH, $fname)); - my $found = "none"; + my @foundList; + while(my $l = ) { next if($l =~ m/^\s*#/); next if($l =~ m/^\s*$/); chomp($l); + my $found; if($l =~ m/^1/) { # Exact date: 1 MM-DD Holiday my @args = split(" +", $l, 3); if($args[1] eq $fordate) { $found = $args[2]; - last; } } elsif($l =~ m/^2/) { # Easter date: 2 +1 Ostermontag @@ -98,7 +99,6 @@ holiday_refresh($$) next if($mday != $fd[3] || $mmonth != $fd[4]+1); $found = $a[2]; Log 4, "$name: Match day: $a[2]\n"; - last; } elsif($l =~ m/^3/) { # Relative date: 3 -1 Mon 03 Holiday my @a = split(" +", $l, 5); @@ -123,13 +123,11 @@ holiday_refresh($$) } $found = $a[4]; - last; } elsif($l =~ m/^4/) { # Interval: 4 MM-DD MM-DD Holiday my @args = split(" +", $l, 4); if($args[1] le $fordate && $args[2] ge $fordate) { $found = $args[3]; - last; } } elsif($l =~ m/^5/) { # nth weekday since MM-DD / before MM-DD @@ -155,27 +153,29 @@ holiday_refresh($$) $tgtmin -= $1*$weeksecs; # Minimum: target date minus $1 weeks $tgtmax = $tgtmin+$weeksecs; # Maximum: one week after minimum # needs to be lower than max and greater than or equal to min - if ( ($cd ge $tgtmin) && ( $cd lt $tgtmax) ) { - $found=$a[5]; - last; + if( ($cd ge $tgtmin) && ( $cd lt $tgtmax) ) { + $found=$a[5]; } } elsif ( $a[1] =~ /^\+?([0-9])*$/ ) { $tgtmin += ($1-1)*$weeksecs; # Minimum: target date plus $1-1 weeks $tgtmax = $tgtmin+$weeksecs; # Maximum: one week after minimum # needs to be lower than or equal to max and greater min - if ( ($cd gt $tgtmin) && ( $cd le $tgtmax) ) { - $found=$a[5]; - last; + if( ($cd gt $tgtmin) && ( $cd le $tgtmax) ) { + $found=$a[5]; } } else { Log 1, "Wrong distance spec: $l"; next; } } + push @foundList, $found if($found); } close(FH); + push @foundList, "none" if(!int(@foundList)); + my $found = join(", ", @foundList); + RemoveInternalTimer($name); $nt -= ($lt[2]*3600+$lt[1]*60+$lt[0]); # Midnight $nt += 86400 + 2; # Tomorrow diff --git a/docs/commandref.html b/docs/commandref.html index 2537db11f..0204d3b31 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -9165,14 +9165,14 @@ KlikAanKlikUit, NEXA, CHACON, HomeEasy UK.
You need to define an RFXtrx433

Define a set of holidays. The module will try to open the file <name>.holiday in the modpath/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 list command - will be set to the holiday, else the state is set to the text none. Most - probably you'll want to query this value in some perl script: see Value() in - the perl section or the global attribute holiday2we.
- The file will be reread once every night, to compute the value for the - current day, and by each get command (see below).
+ will be set to the corresponding values, else the state is set to the text + none. Most probably you'll want to query this value in some perl script: + see Value() in the perl section or the global attribute + holiday2we.
The file will be reread once + every night, to compute the value for the current day, and by each get + command (see below).

Holiday file definition: