2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

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
This commit is contained in:
rudolfkoenig 2017-12-27 19:35:48 +00:00
parent 6c7115e66e
commit 46de1dcc10
5 changed files with 74 additions and 20 deletions

View File

@ -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 ? "<h3>ERROR:</h3><b>$ret</b>" :
"Saved the file $fileName to $forceType");
$ret = ($ret ? "<h3>ERROR:</h3><b>$ret</b>" : "Saved $fileName");
FW_style("style list", $ret);
$ret = "";

View File

@ -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 createPrivateCopy:noArg"
if($a[1] ne "createPrivateCopy");
return "unknown argument $a[1], choose one of ".
join(" ", map { "$_:noArg" }
grep { $sets{$_} } keys %sets) if(!$sets{$a[1]});
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});
return $err;
} 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",
"<div class=\"dval\">Edit $d.holiday</div>", 0, "dval", 1);
}
1;
=pod
@ -329,8 +362,9 @@ western_easter($)
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
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.<br>
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"<br>
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
@ -409,6 +443,15 @@ western_easter($)
modified. With createPrivateCopy the file will be copied to the FHEM
directory, where it can be modified.
</ul></li>
<li>deletePrivateCopy<br>
<ul>
delete the private copy, see createPrivateCopy above
</ul></li>
<li>reload<br>
<ul>
set the state, tomorrow and yesterday readings. Useful after manually
editing the file.
</ul></li>
</ul><br>
<a name="holidayget"></a>
@ -446,7 +489,7 @@ western_easter($)
Datei &lt;name&gt;.holiday erst in <a href="#modpath">modpath</a>/FHEM zu
&ouml;ffnen, und dann in modpath/FHEM/holiday, Letzteres enth&auml;lt eine
Liste von per FHEM-update verteilten Dateien f&uuml;r diverse
(Bundes-)L&auml;nder. Diese Liste wird bei einer Feherlmeldung angezeigt.
(Bundes-)L&auml;nder. Diese Liste wird bei einer Fehlermeldung angezeigt.
Wenn Eintr&auml;ge im der Datei auf den aktuellen Tag passen wird der STATE
der Holiday-Instanz die im <a href="#list">list</a> Befehl angezeigt wird
@ -530,6 +573,15 @@ western_easter($)
update aktualisiert wird. Mit createPrivateCopy kann eine private Kopie
im FHEM Verzeichnis erstellt werden.
</ul></li>
<li>deletePrivateCopy<br>
<ul>
Entfernt die private Kopie, siehe auch createPrivateCopy
</ul></li>
<li>reload<br>
<ul>
setzt die state, tomorrow und yesterday Readings. Wird nach einem
manuellen Bearbeiten der .holiday Datei ben&ouml;tigt.
</ul></li>
</ul><br>
<a name="holidayget"></a>

View File

@ -1459,9 +1459,11 @@ The following local attributes are used by a wider range of devices:
If this attribute is set, then the <a href="#perl">$we</a> variable
will be true, if the value of the <a href="#holiday">holiday</a>
variable referenced by this attribute is not none.<br>
If it is a comma separated list, then it is true, if one of the
referenced entities is not none.<br>
Example:<br>
<ul>
attr global holiday2we hessen
attr global holiday2we he
</ul>
</li><br>

View File

@ -1557,6 +1557,8 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
href="#perl">$we</a> Variable als &quot;true&quot; betrachtet, wenn der
Wert der <a href="#holiday">holiday</a> Variable zu diesem Attribut
nicht &quot;none&quot; ist.<br>
Falls es eine Komma getrennte Liste ist, dann ist es wahr, falls einer
der referenzierten Instanzen nicht &quot;none&quot; ist.<br>
Beispiel:<br>
<ul>
attr global holiday2we hessen

View File

@ -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 ||