From 46de1dcc106dd50a5b9a47448ade0f55326056a1 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Wed, 27 Dec 2017 19:35:48 +0000
Subject: [PATCH] 95_holiday.pm: add Link for editing the .holiday file (Forum
#81527) fhem.pl: holiday2we may contain a comma separated list of holiday
files
git-svn-id: https://svn.fhem.de/fhem/trunk@15710 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/01_FHEMWEB.pm | 3 +-
fhem/FHEM/95_holiday.pm | 78 +++++++++++++++++++++++++-----
fhem/docs/commandref_frame.html | 4 +-
fhem/docs/commandref_frame_DE.html | 2 +
fhem/fhem.pl | 7 ++-
5 files changed, 74 insertions(+), 20 deletions(-)
diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm
index d0b689e1a..058ea2ae5 100644
--- a/fhem/FHEM/01_FHEMWEB.pm
+++ b/fhem/FHEM/01_FHEMWEB.pm
@@ -2255,8 +2255,7 @@ FW_style($$)
$ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,);
$ret = FW_Set("","","rereadicons") if($isImg);
DoTrigger("global", "FILEWRITE $filePath", 1) if(!$ret); # Forum #32592
- $ret = ($ret ? "
ERROR:
$ret" :
- "Saved the file $fileName to $forceType");
+ $ret = ($ret ? "ERROR:
$ret" : "Saved $fileName");
FW_style("style list", $ret);
$ret = "";
diff --git a/fhem/FHEM/95_holiday.pm b/fhem/FHEM/95_holiday.pm
index 504f839bc..a504e28da 100644
--- a/fhem/FHEM/95_holiday.pm
+++ b/fhem/FHEM/95_holiday.pm
@@ -19,6 +19,7 @@ holiday_Initialize($)
$hash->{SetFn} = "holiday_Set";
$hash->{UndefFn} = "holiday_Undef";
$hash->{AttrList} = $readingFnAttributes;
+ $hash->{FW_detailFn} = "holiday_FW_detailFn";
}
@@ -228,17 +229,38 @@ sub
holiday_Set($@)
{
my ($hash, @a) = @_;
+ my %sets = (
+ createPrivateCopy => $hash->{READONLY},
+ deletePrivateCopy => !$hash->{READONLY},
+ reload => 1
+ );
+
+ return "unknown argument $a[1], choose one of ".
+ join(" ", map { "$_:noArg" }
+ grep { $sets{$_} } keys %sets) if(!$sets{$a[1]});
- return "unknown argument $a[1], choose one of createPrivateCopy:noArg"
- if($a[1] ne "createPrivateCopy");
- return "Already a private version" if(!$hash->{READONLY});
- my $fname = $attr{global}{modpath}."/FHEM/holiday/$hash->{NAME}.holiday";
- my ($err, @holidayfile) = FileRead($fname);
- return $err if($err);
- $fname = $attr{global}{modpath}."/FHEM/$hash->{NAME}.holiday";
- $err = FileWrite($fname, @holidayfile);
- holiday_refresh($hash->{NAME});
- return $err;
+ if($a[1] eq "createPrivateCopy") {
+ return "Already a private version" if(!$hash->{READONLY});
+ my $fname = $attr{global}{modpath}."/FHEM/holiday/$hash->{NAME}.holiday";
+ my ($err, @holidayfile) = FileRead($fname);
+ return $err if($err);
+ $fname = $attr{global}{modpath}."/FHEM/$hash->{NAME}.holiday";
+ $err = FileWrite($fname, @holidayfile);
+ return $err if($err);
+ holiday_refresh($hash->{NAME});
+
+ } elsif($a[1] eq "deletePrivateCopy") {
+
+ return "Not a private version" if($hash->{READONLY});
+ my $err = FileDelete($attr{global}{modpath}."/FHEM/$hash->{NAME}.holiday");
+ return $err if($err);
+ holiday_refresh($hash->{NAME});
+
+ } elsif($a[1] eq "reload") {
+ holiday_refresh($hash->{NAME});
+
+ }
+ return undef;
}
sub
@@ -311,6 +333,17 @@ western_easter($)
return $month, $day;
}
+
+sub
+holiday_FW_detailFn($$$$)
+{
+ my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
+
+ return "" if($defs{$d}{READONLY});
+ return FW_pH("cmd=style edit $d.holiday",
+ "Edit $d.holiday
", 0, "dval", 1);
+}
+
1;
=pod
@@ -329,8 +362,9 @@ western_easter($)
Define a set of holidays. The module will try to open the file
<name>.holiday in the modpath/FHEM directory
first, then in the modpath/FHEM/holiday directory, the latter containing a
- set of predefined files. The set will be shown if an error occures at the
- time of the definietion.
+ set of predefined files. This list of available holiday files will be shown
+ if an error occurs at the time of the definition, e.g. if you type "define
+ help holiday"
If entries in the holiday file match the current day, then the STATE of
this holiday instance displayed in the list command
@@ -409,6 +443,15 @@ western_easter($)
modified. With createPrivateCopy the file will be copied to the FHEM
directory, where it can be modified.
+ deletePrivateCopy
+
+ delete the private copy, see createPrivateCopy above
+
+ reload
+
+ set the state, tomorrow and yesterday readings. Useful after manually
+ editing the file.
+
@@ -446,7 +489,7 @@ western_easter($)
Datei <name>.holiday erst in modpath/FHEM zu
öffnen, und dann in modpath/FHEM/holiday, Letzteres enthält eine
Liste von per FHEM-update verteilten Dateien für diverse
- (Bundes-)Länder. Diese Liste wird bei einer Feherlmeldung angezeigt.
+ (Bundes-)Länder. Diese Liste wird bei einer Fehlermeldung angezeigt.
Wenn Einträge im der Datei auf den aktuellen Tag passen wird der STATE
der Holiday-Instanz die im list Befehl angezeigt wird
@@ -530,6 +573,15 @@ western_easter($)
update aktualisiert wird. Mit createPrivateCopy kann eine private Kopie
im FHEM Verzeichnis erstellt werden.
+ deletePrivateCopy
+
+ Entfernt die private Kopie, siehe auch createPrivateCopy
+
+ reload
+
+ setzt die state, tomorrow und yesterday Readings. Wird nach einem
+ manuellen Bearbeiten der .holiday Datei benötigt.
+
diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html
index ca3b5d078..359f7dc38 100644
--- a/fhem/docs/commandref_frame.html
+++ b/fhem/docs/commandref_frame.html
@@ -1459,9 +1459,11 @@ The following local attributes are used by a wider range of devices:
If this attribute is set, then the $we variable
will be true, if the value of the holiday
variable referenced by this attribute is not none.
+ If it is a comma separated list, then it is true, if one of the
+ referenced entities is not none.
Example:
- attr global holiday2we hessen
+ attr global holiday2we he
diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html
index ab8df97aa..471e70661 100644
--- a/fhem/docs/commandref_frame_DE.html
+++ b/fhem/docs/commandref_frame_DE.html
@@ -1557,6 +1557,8 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
href="#perl">$we Variable als "true" betrachtet, wenn der
Wert der holiday Variable zu diesem Attribut
nicht "none" ist.
+ Falls es eine Komma getrennte Liste ist, dann ist es wahr, falls einer
+ der referenzierten Instanzen nicht "none" ist.
Beispiel:
attr global holiday2we hessen
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index 79c75e6bf..a6b6eb473 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -1049,10 +1049,9 @@ AnalyzePerlCommand($$;$)
my $hms = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
my $we = (($wday==0 || $wday==6) ? 1 : 0);
if(!$we) {
- my $h2we = $attr{global}{holiday2we};
- if($h2we && Value($h2we)) {
+ foreach my $h2we (split(",", AttrVal("global", "holiday2we", ""))) {
my ($a, $b) = ReplaceEventMap($h2we, [$h2we, Value($h2we)], 0);
- $we = 1 if($b ne "none");
+ $we = 1 if($b && $b ne "none");
}
}
$month++;
@@ -3884,7 +3883,7 @@ sub
ReplaceEventMap($$$)
{
my ($dev, $str, $dir) = @_;
- my $em = $attr{$dev}{eventMap};
+ my $em = AttrVal($dev, "eventMap", undef);
return $str if($dir && !$em);
return @{$str} if(!$dir && (!$em || int(@{$str}) < 2 ||