From 466d8cec52b4ca9be977a121d3a5e0f02fbc91ff Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 23 May 2009 07:32:08 +0000 Subject: [PATCH] Holiday bugfixes git-svn-id: https://svn.fhem.de/fhem/trunk@376 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 +++- fhem/FHEM/95_holiday.pm | 40 +++++++++++++++++++++++++++++++++++++++ fhem/HISTORY | 2 -- fhem/Makefile | 1 - fhem/TODO | 1 + fhem/contrib/by.holiday | 19 +++++++++++++++++++ fhem/contrib/checkmsg.pl | 1 + fhem/docs/HOWTO.html | 12 ++++++++++++ fhem/docs/commandref.html | 13 ++++++++++++- fhem/docs/faq.html | 8 ++++---- fhem/docs/fhem.html | 13 +++++++++---- fhem/examples/sample_pgm2 | 2 +- fhem/fhem.pl | 13 +++++++++---- 13 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 fhem/contrib/by.holiday diff --git a/fhem/CHANGED b/fhem/CHANGED index 7c42be4f0..9333500c2 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -489,10 +489,12 @@ - feature: Common Module calling for CUL/FHZ/CM11 - feature: Store CUL sensitivity info - feature: avoid the "unknown/help me" message for unloaded devices - - feature: structure module for big installations + - feature: structure module for large installations - feature: Cost Control in 15_CUL_EM (CostPerUnit, BasisFeePerMonth) - feature: add counter differential per time in 81_M232Counter.pm - feature: added USB compendium to documentation - feature: pgm3: Documentation for pgm3 updated, HMS100CO added (and bugfixes) - bugfix: Defining a repeated at job in a sunrise/sunset at job fails - bugfix: FHT "summer" fix (avoiding a lot of syncnow) + - feature: FHEMWEB modules added + - feature: holiday module + doc + example + holiday2we attribute diff --git a/fhem/FHEM/95_holiday.pm b/fhem/FHEM/95_holiday.pm index 2e7a0f335..38e6eba71 100755 --- a/fhem/FHEM/95_holiday.pm +++ b/fhem/FHEM/95_holiday.pm @@ -120,6 +120,46 @@ holiday_refresh($$) $found = $args[3]; last; } + + } elsif($l =~ m/^5/) { # nth weekday since MM-DD / before MM-DD + my @a = split(" +", $l, 6); + # arguments: 5 + my %wd = ("Sun"=>0, "Mon"=>1, "Tue"=>2, "Wed"=>3, + "Thu"=>4, "Fri"=>5, "Sat"=>6); + my $wd = $wd{$a[2]}; + if(!defined($wd)) { + Log 1, "Wrong weekday spec: $l"; + next; + } + next if $wd != $fd[6]; # check wether weekday matches today + my $yday=$fd[7]; + # create time object of target date - mktime counts months and their + # days from 0 instead of 1, so subtract 1 from each + my $tgt=mktime(0,0,1,$a[3]-1,$a[4]-1,$fd[5],0,0,-1); + my $tgtmin=$tgt; + my $tgtmax=$tgt; + my $weeksecs=7*24*60*60; # 7 days, 24 hours, 60 minutes, 60seconds each + my $cd=mktime(0,0,1,$fd[3],$fd[4],$fd[5],0,0,-1); + if ( $a[1] =~ /^-([0-9])*$/ ) { + $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; + } + } 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; + } + } else { + Log 1, "Wrong distance spec: $l"; + next; + } } } diff --git a/fhem/HISTORY b/fhem/HISTORY index 744b1f573..2309ea1a3 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -396,5 +396,3 @@ - pgm3: bugfix, format table for userdef - pgm3: feature X10_support, taillogorder optional with date - pgm3: HMS100CO added, fhem.html relating pgm3 updated - - diff --git a/fhem/Makefile b/fhem/Makefile index 9e1947154..aa24f854e 100644 --- a/fhem/Makefile +++ b/fhem/Makefile @@ -33,7 +33,6 @@ install-base: mkdir -p $(BINDIR) $(MODDIR) $(VARDIR) cp fhem.pl $(BINDIR) cp -r FHEM $(MODDIR) - mkdir -p $(VARDIR) perl -pi -e 's,modpath \.,modpath $(MODDIR),' examples/[a-z]* perl -pi -e 's,/tmp,$(VARDIR),' examples/[a-z]* diff --git a/fhem/TODO b/fhem/TODO index bd0367cd0..512e9876c 100644 --- a/fhem/TODO +++ b/fhem/TODO @@ -4,6 +4,7 @@ FHEM: - holiday database - fhem-to-fhem module - CUR built-in MENU creation support +- Remove or reimplement repeater attribute (cul/fhz/doc) Webpgm2 - plot data from multiple files in a single picture diff --git a/fhem/contrib/by.holiday b/fhem/contrib/by.holiday new file mode 100644 index 000000000..e2303f2e3 --- /dev/null +++ b/fhem/contrib/by.holiday @@ -0,0 +1,19 @@ +# Siehe auch +# http://de.wikipedia.org/wiki/Feiertage_in_Deutschland + +1 01-01 Neujahr +1 01-06 Heilige Drei Koenige +1 05-01 Tag der Arbeit +1 08-15 Mariae Himmelfahrt (nur bei ueberwiegend katholischer Bevoelkerung) +1 10-03 Tag der deutschen Einheit +1 11-01 Allerheiligen +1 12-25 1. Weihnachtstag +1 12-26 2. Weihnachtstag + +2 -2 Karfreitag +2 1 Ostermontag +2 39 Christi Himmelfahrt +2 50 Pfingsten +2 60 Fronleichnam +#5 -1 Wed 11 23 Buss und Bettag (first Wednesday before Nov, 23rd)
+ diff --git a/fhem/contrib/checkmsg.pl b/fhem/contrib/checkmsg.pl index abb0a2b6d..a46847ff0 100755 --- a/fhem/contrib/checkmsg.pl +++ b/fhem/contrib/checkmsg.pl @@ -1,3 +1,4 @@ +#!/usr/bin/perl die("Usage: checkmsg HEX-FHZ-MESSAGE\n") if(int(@ARGV) != 1); my $msg = $ARGV[0]; diff --git a/fhem/docs/HOWTO.html b/fhem/docs/HOWTO.html index 05173c164..3dd1e8830 100644 --- a/fhem/docs/HOWTO.html +++ b/fhem/docs/HOWTO.html @@ -19,6 +19,7 @@ Logging data
Plotting logs
FHEMWEB tips
+ Complex structures
@@ -233,7 +234,18 @@ define messages FileLog /var/log/messages fakelog

+ +
+

Complex structures

+
diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index cdb1a7d5c..e5ecd09e6 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -2964,9 +2964,20 @@ A line ending with \ will be concatenated with the next one, so long lines 4 01-06 31-06 Summer holiday
+
  • 5
    + Date relative, weekday fixed holiday. Arguments: <nth> + <weekday> <month> <day> < holiday-name>
    + Note that while +0 or -0 as offsets are not forbidden, their behaviour + is undefined in the sense that it might change without notice.
    + Examples:
    +
      + 5 -1 Wed 11 23 Buss und Bettag (first Wednesday before Nov, 23rd)
      + 5 1 Mon 01 31 First Monday after Jan, 31st (1st Monday in February)
      +
    +
  • See also he.holiday in the contrib directory for official holidays in the - german country of Hessen. + german country of Hessen, and by.holiday for the Bavarian definition.
    diff --git a/fhem/docs/faq.html b/fhem/docs/faq.html index 69555391e..20bec7869 100644 --- a/fhem/docs/faq.html +++ b/fhem/docs/faq.html @@ -214,9 +214,8 @@ that 255 should be the default? 8. The time specification of the builtin at command is not very flexible. Please add day/month/weekday to it.
      - I think the command is complex and flexible enough. Use a perl expression - for this functionality like (described in the commandref.html): -
      at *07:00:00 { fhz "set lamp on" if($we) }
      + Please take a look at the holiday device, and the perl helper variables (both + described in the commandref.html).
    @@ -234,7 +233,8 @@ it. by fhem.pl?
      - Convert the first 2 digits first from decimal to hex, then the next two. Example:
      + Convert the first 2 digits first from decimal to hex, then the next two. + Example:
                % bc
       	 obase=16
      diff --git a/fhem/docs/fhem.html b/fhem/docs/fhem.html
      index 4fd39a6fb..e3894cf4c 100644
      --- a/fhem/docs/fhem.html
      +++ b/fhem/docs/fhem.html
      @@ -52,8 +52,13 @@ Currently implemented features:
  • Via the CUL module (see www.busware.de - ) access to the FS20/EM1000/FHT/S300 protocols. Note:due to - the incomplete firmware the access is read-only at the moment. + ) access to the following protocols:
    +
      +
    • FS20 (Receive/Send, all devices) +
    • EM (EM1000EM/EM1000GZ/EM1000WZ) +
    • FHT (Only snoop functionality, no send!) +
    • S300 (KS300, S300TH, S555TH, etc) + /ul>
    • reading WS300 data, and up to 9 attached devices
    • reading EM1000WZ/EM1000EM/EM1000GZ data via an attached EM1010PC
    • @@ -83,8 +88,8 @@ commandref.html and faq.html for more documentation, http://www.koeniglich.de/fhem/fhem-=VERS=.tar.gz
      FAQ: http://www.koeniglich.de/fhem/faq.html
      - Google-Group: - http://groups.google.com/group/FHZ1000-users-on-unix
      + Google-Group: + http://groups.google.com/group/fhem-users
      Martins Web frontend (webpgm3): http://www.martin-haas.de/fhz
      Another Martins Web frontend (myHCE): diff --git a/fhem/examples/sample_pgm2 b/fhem/examples/sample_pgm2 index e23b92245..a7dddbb5b 100644 --- a/fhem/examples/sample_pgm2 +++ b/fhem/examples/sample_pgm2 @@ -8,7 +8,7 @@ attr global verbose 3 # "normal" verbosity (min 1, max 5) attr global port 7072 # our TCP/IP port (localhost only) attr global modpath /tmp/fhem/fhem # where our FHEM directory is -define WEB FHEMWEB 8083 +define WEB FHEMWEB 8083 global attr WEB plotmode SVG # Fake logfile, to access the global log diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 18d1d61a4..a5eb1af03 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -151,7 +151,7 @@ my %defaultattr; # Default attributes my %intAt; # Internal at timer hash. my $nextat; # Time when next timer will be triggered. my $intAtCnt=0; -my $cvsid = '$Id: fhem.pl,v 1.70 2009-04-11 08:20:13 rudolfkoenig Exp $'; +my $cvsid = '$Id: fhem.pl,v 1.71 2009-05-23 07:32:08 rudolfkoenig Exp $'; my $namedef = "where is either:\n" . "- a single device name\n" . @@ -167,7 +167,7 @@ $modules{_internal_}{LOADED} = 1; $modules{_internal_}{AttrList} = "archivecmd allowfrom archivedir configfile lastinclude logfile " . "modpath nrarchive pidfilename port statefile title userattr " . - "verbose:1,2,3,4,5 mseclog version nofork logdir"; + "verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we"; $modules{_internal_}{AttrFn} = "GlobalAttr"; @@ -294,7 +294,8 @@ while (1) { } my $timeout = HandleTimeout(); - $timeout = $readytimeout if(!defined($timeout) && keys %readyfnlist); + $timeout = $readytimeout if(keys(%readyfnlist) && + (!defined($timeout) || $timeout > $readytimeout)); my $nfound = select($rout=$rin, undef, undef, $timeout); CommandShutdown(undef, undef) if($sig_term); @@ -526,6 +527,10 @@ AnalyzeCommand($$) } my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime; my $we = (($wday==0 || $wday==6) ? 1 : 0); + if(!$we) { + my $h2we = $attr{global}{holiday2we}; + $we = 1 if($h2we && $value{$h2we} ne "none"); + } $month++; $year+=1900; @@ -839,7 +844,7 @@ CommandSave($$) print SFH "\n"; # then the "important" ones (FHZ, WS300Device) - foreach my $d (sort keys %savefirst) { + foreach my $d (sort { $defs{$a}{NR} <=> $defs{$b}{NR} } keys %savefirst) { my $r = $savefirst{$d}; delete $rooms{$r}{$d}; delete $rooms{$r} if(! %{$rooms{$r}});