2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +00:00

holiday.pm: move holiday directory from contrib to FHEM

git-svn-id: https://svn.fhem.de/fhem/trunk@15042 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-09-10 13:59:16 +00:00
parent 4dade819c2
commit 8d807ee02e
4 changed files with 86 additions and 19 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: 95_holiday: move holiday files from contrib to FHEM
- feature: 31_Nello: updated to new api specifications - feature: 31_Nello: updated to new api specifications
- feature: 49_SSCam: V2.8.0, switch Surveillance Station HomeMode available - feature: 49_SSCam: V2.8.0, switch Surveillance Station HomeMode available
- bugfix: 73_GardenaSmartBridge: code clean, update german tranlation - bugfix: 73_GardenaSmartBridge: code clean, update german tranlation

View File

@ -2166,7 +2166,7 @@ FW_style($$)
my $efl = AttrVal($FW_wname, 'editFileList', my $efl = AttrVal($FW_wname, 'editFileList',
"Own modules and helper files:\$MW_dir:^(.*sh|[0-9][0-9].*Util.*pm|". "Own modules and helper files:\$MW_dir:^(.*sh|[0-9][0-9].*Util.*pm|".
".*cfg|.*holiday|myUtilsTemplate.pm|.*layout)\$\n". ".*cfg|.*\.holiday|myUtilsTemplate.pm|.*layout)\$\n".
"Gplot files:\$FW_gplotdir:^.*gplot\$\n". "Gplot files:\$FW_gplotdir:^.*gplot\$\n".
"Styles:\$FW_cssdir:^.*(css|svg)\$"); "Styles:\$FW_cssdir:^.*(css|svg)\$");
foreach my $l (split(/[\r\n]/, $efl)) { foreach my $l (split(/[\r\n]/, $efl)) {

View File

@ -6,7 +6,7 @@ use strict;
use warnings; use warnings;
use POSIX; use POSIX;
sub holiday_refresh($;$); sub holiday_refresh($;$$);
##################################### #####################################
sub sub
@ -16,6 +16,7 @@ holiday_Initialize($)
$hash->{DefFn} = "holiday_Define"; $hash->{DefFn} = "holiday_Define";
$hash->{GetFn} = "holiday_Get"; $hash->{GetFn} = "holiday_Get";
$hash->{SetFn} = "holiday_Set";
$hash->{UndefFn} = "holiday_Undef"; $hash->{UndefFn} = "holiday_Undef";
$hash->{AttrList} = $readingFnAttributes; $hash->{AttrList} = $readingFnAttributes;
} }
@ -27,7 +28,7 @@ holiday_Define($$)
{ {
my ($hash, $def) = @_; my ($hash, $def) = @_;
return holiday_refresh($hash->{NAME}) if($init_done); return holiday_refresh($hash->{NAME}, undef, 1) if($init_done);
InternalTimer(gettimeofday()+1, "holiday_refresh", $hash->{NAME}, 0); InternalTimer(gettimeofday()+1, "holiday_refresh", $hash->{NAME}, 0);
return undef; return undef;
} }
@ -41,9 +42,9 @@ holiday_Undef($$)
} }
sub sub
holiday_refresh($;$) holiday_refresh($;$$)
{ {
my ($name, $fordate) = (@_); my ($name, $fordate, $showAvailable) = (@_);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $fromTimer=0; my $fromTimer=0;
@ -63,9 +64,36 @@ holiday_refresh($;$)
Log3 $name, 5, "holiday_refresh $name called for $fordate ($fromTimer)"; Log3 $name, 5, "holiday_refresh $name called for $fordate ($fromTimer)";
my $fname = $attr{global}{modpath} . "/FHEM/" . $hash->{NAME} . ".holiday"; my $dir = $attr{global}{modpath} . "/FHEM";
my ($err, @holidayfile) = FileRead($fname); my ($err, @holidayfile) = FileRead("$dir/$name.holiday");
return $err if($err); if($err) {
$dir = $attr{global}{modpath}."/FHEM/holiday";
($err, @holidayfile) = FileRead("$dir/$name.holiday");
$hash->{READONLY} = 1;
} else {
$hash->{READONLY} = 0;
}
if($err) {
if($showAvailable) {
my @ret;
if(configDBUsed()) {
@ret = cfgDB_FW_fileList($dir,".*.holiday",@ret);
map { s/\.configDB$//;$_ } @ret;
} else {
if(opendir(DH, $dir)) {
@ret = grep { m/\.holiday$/ } readdir(DH);
closedir(DH);
}
}
$err .= "\nAvailable holiday files: ".
join(" ", map { s/.holiday//;$_ } @ret);
} else {
Log 1, "$name: $err";
}
return $err;
}
$hash->{HOLIDAYFILE} = "$dir/$name.holiday";
my @foundList; my @foundList;
foreach my $l (@holidayfile) { foreach my $l (@holidayfile) {
@ -196,6 +224,23 @@ holiday_refresh($;$)
} }
} }
sub
holiday_Set($@)
{
my ($hash, @a) = @_;
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;
}
sub sub
holiday_Get($@) holiday_Get($@)
{ {
@ -282,7 +327,11 @@ western_easter($)
<code>define &lt;name&gt; holiday</code> <code>define &lt;name&gt; holiday</code>
<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
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>
If entries in the holiday file match 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 corresponding values, else the state is set to the text will be set to the corresponding values, else the state is set to the text
@ -347,13 +396,20 @@ western_easter($)
</ul> </ul>
</li> </li>
</ul> </ul>
See also he.holiday in the contrib directory for official holidays in the
german country of Hessen, and by.holiday for the Bavarian definition.
</ul> </ul>
<br> <br>
<a name="holidayset"></a> <a name="holidayset"></a>
<b>Set</b> <ul>N/A</ul><br> <b>Set</b>
<ul>
<li>createPrivateCopy<br>
<ul>
if the holiday file is opened from the FHEM/holiday directory (which is
refreshed by FHEM-update), then it is readonly, and should not be
modified. With createPrivateCopy the file will be copied to the FHEM
directory, where it can be modified.
</ul></li>
</ul><br>
<a name="holidayget"></a> <a name="holidayget"></a>
<b>Get</b> <b>Get</b>
@ -386,9 +442,12 @@ western_easter($)
<ul> <ul>
<code>define &lt;name&gt; holiday</code> <code>define &lt;name&gt; holiday</code>
<br><br> <br><br>
Definiert einen Satz mit Urlaubsinformationen. Das Modul versucht die Datei Definiert einen Satz mit Urlaubsinformationen. Das Modul versucht die
&lt;name&gt;.holiday im Pfad <a href="#modpath">modpath</a>/FHEM zu Datei &lt;name&gt;.holiday erst in <a href="#modpath">modpath</a>/FHEM zu
&ouml;ffnen. &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.
Wenn Eintr&auml;ge im der Datei auf den aktuellen Tag passen wird der STATE 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 der Holiday-Instanz die im <a href="#list">list</a> Befehl angezeigt wird
auf die entsprechenden Werte gesetzt. Andernfalls ist der STATE auf den auf die entsprechenden Werte gesetzt. Andernfalls ist der STATE auf den
@ -458,13 +517,20 @@ western_easter($)
</ul> </ul>
</li> </li>
</ul> </ul>
Siehe auch he.holiday im contrib Verzeichnis f&uuml;r offizielle Feiertage
in den deutschen Bundesl&auml;ndern Hessen und by.holiday f&uuml;r Bayern.
</ul> </ul>
<br> <br>
<a name="holidayset"></a> <a name="holidayset"></a>
<b>Set</b> <ul>N/A</ul><br> <b>Set</b>
<ul>
<li>createPrivateCopy<br>
<ul>
Falls die Datei in der FHEM/holiday Verzeichnis ge&ouml;ffnet wurde,
dann ist sie nicht beschreibbar, da dieses Verzeichnis mit FHEM
update aktualisiert wird. Mit createPrivateCopy kann eine private Kopie
im FHEM Verzeichnis erstellt werden.
</ul></li>
</ul><br>
<a name="holidayget"></a> <a name="holidayget"></a>
<b>Get</b> <b>Get</b>

View File

@ -2559,7 +2559,7 @@ GlobalAttr($$$$)
my %noDel = ( modpath=>1, verbose=>1, logfile=>1 ); my %noDel = ( modpath=>1, verbose=>1, logfile=>1 );
return "The global attribute $name cannot be deleted" if($noDel{$name}); return "The global attribute $name cannot be deleted" if($noDel{$name});
$featurelevel = 5.8 if($name eq "featurelevel"); $featurelevel = 5.8 if($name eq "featurelevel");
$haveInet6 = 0 if($name eq "useInet6"); $haveInet6 = 0 if($name eq "useInet6"); # IPv6
return undef; return undef;
} }