2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

57_Calendar: new feature get ...events include:... returnType:...

git-svn-id: https://svn.fhem.de/fhem/trunk@19937 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2019-08-02 19:03:44 +00:00
parent 00b036721e
commit 9a0081a2e5
2 changed files with 157 additions and 68 deletions

View File

@ -1,5 +1,6 @@
# 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.
- feature: 57_Calendar: get ...events include:... returnType:...
- feature: 44_TEK603: ser2net support
- feature: 73_AutoShuttersControl: add new Dev TYPE in %posSetCmds,
remove old commandref text

View File

@ -1938,6 +1938,8 @@ sub Calendar_Get($@) {
my @filters= ();
my $next= undef;
my $count= undef;
my $returnFormat= '$text';
my @includes= ();
my ($paramerror, $arrayref)= Calendar_simpleParseWords(join(" ", @a));
return "$name: Parameter parse error: $paramerror" if(defined($paramerror));
@ -1965,7 +1967,7 @@ sub Calendar_Get($@) {
} elsif($p =~ /^timeFormat:['"](.+)['"]$/) {
$timeFormat= $1;
### filter
} elsif($p =~ /^filter:(.+)$/) {
} elsif($p =~ /^filter:(.+)$/) {
my ($filtererror, $filterarrayref)= Calendar_simpleParseWords($1, ",");
return "$name: Filter parse error: $filtererror" if(defined($filtererror));
my @filterspecs= @{$filterarrayref};
@ -2038,13 +2040,41 @@ sub Calendar_Get($@) {
}
}
} else {
} elsif($p =~ /^returnType:(.+)$/) {
$returnFormat= $1;
if( ($returnFormat eq '$text') ||
($returnFormat eq '@events') ||
($returnFormat eq '@texts')) {
# fine
} else {
return "$name: Illegal return format: $returnFormat";
}
} elsif($p =~ /^include:(.+)$/) {
@includes= split(",", $1);
# remove duplicates
@includes= keys %{{ map{ $_ => 1 } @includes }};
#my %seen = ();
#@includes = grep { ! $seen{ $_ }++ } @includes;
} else {
return "$name: Illegal parameter: $p";
}
}
my @texts;
my @events= Calendar_GetEvents($hash, $t, @filters);
if($#includes>= 0) {
foreach my $calname (@includes) {
next if($calname eq $name); # silently ignore inclusion of this calendar
my $dev= $defs{$calname};
if(defined($dev) && $dev->{TYPE} eq "Calendar") {
push @events, Calendar_GetEvents($dev, $t, @filters);
} else {
Log3 $hash, 2, "$name: device $calname does not exist or is not a Calendar";
}
}
@events= sort { $a->start() <=> $b->start() } @events;
}
# special treatment for next
if(defined($next)) {
my %uids; # remember the UIDs
@ -2058,11 +2088,16 @@ sub Calendar_Get($@) {
} @events;
}
return @events if($returnFormat eq '@events');
my $n= 0;
my @texts;
foreach my $event (@events) {
push @texts, $event->formatted($format, $timeFormat);
last if(defined($count) && (++$n>= $count));
}
return @texts if($returnFormat eq '@texts');
return "" if($#texts<0);
return join("\n", @texts);
@ -3300,7 +3335,11 @@ sub CalendarEventsAsHtml($;$) {
Same as <code>set &lt;name&gt; update</code><br><br></li>
<li><code>get &lt;name&gt; events [format:&lt;formatSpec&gt;] [timeFormat:&lt;timeFormatSpec&gt;] [filter:&lt;filterSpecs&gt;] [series:next[=&lt;max&gt;]] [limit:&lt;limitSpecs&gt;]</code><br><br>
<li><code>get &lt;name&gt; events [format:&lt;formatSpec&gt;] [timeFormat:&lt;timeFormatSpec&gt;] [filter:&lt;filterSpecs&gt;]
[series:next[=&lt;max&gt;]] [limit:&lt;limitSpecs&gt;]
[include:&lt;names&gt;]
[returnType:&lt;returnTypeSpec&gt;]
</code><br><br>
The swiss army knife for displaying calendar events.
Returns, line by line, information on the calendar events in the calendar &lt;name&gt;
according to formatting and filtering rules.
@ -3449,6 +3488,28 @@ sub CalendarEventsAsHtml($;$) {
<code>get MyCalendar events limit:count=10,from=0,to=+10d</code><br>
<br><br>
The <u><code>include</code></u> parameter includes events from other calendars. This is useful for
displaying events from several calendars in one combined output. <code>&lt;names&gt;</code> is
a comma-separated list of names of calendar devices. The name of the device itself as well as
any duplicates are silently ignored. Names of non-existant devices or of devices that are not
Calendar devices are ignored and an error is written to the log.<br><br>
Example:<br>
<code>get MyCalendar events include:HolidayCalendar,GarbageCollection</code><br>
<br><br>
The <u><code>returnType</code></u> parameter is used to return the events in a particular type.
This is useful for Perl scripts.<br><br>
<table>
<tr><th align="left"><code>&lt;returnTypeSpec&gt;</code></th><th align="left">description</th></tr>
<tr><td><code>$text</code></td><td>a multiline string in human-readable format (default)</td></tr>
<tr><td><code>@texts</code></td><td>an array of strings in human-readable format</td></tr>
<tr><td><code>@event</code></td><td>an array of Calendar::Event hashes</td></tr>
</table>
<br><br>
</li>
@ -3966,7 +4027,11 @@ sub CalendarEventsAsHtml($;$) {
Entspricht <code>set &lt;name&gt; reload</code><br><br>
<li><code>get &lt;name&gt; events [format:&lt;formatSpec&gt;] [timeFormat:&lt;timeFormatSpec&gt;] [filter:&lt;filterSpecs&gt;] [series:next[=&lt;max&gt;]] [limit:&lt;limitSpecs&gt;]</code><br><br>
<li><code>get &lt;name&gt; events [format:&lt;formatSpec&gt;] [timeFormat:&lt;timeFormatSpec&gt;] [filter:&lt;filterSpecs&gt;]
[series:next[=&lt;max&gt;]] [limit:&lt;limitSpecs&gt;]
[include:&lt;names&gt;]
[returnType:&lt;returnTypeSpec&gt;]
</code><br><br>
Das Schweizer Taschenmesser f&uuml;r die Anzeige von Terminen.
Die Termine des Kalenders &lt;name&gt; werden Zeile f&uuml;r Zeile entsprechend der Format- und Filterangaben ausgegeben.
Keiner, einer oder mehrere der Parameter <code>format</code>,
@ -4114,6 +4179,29 @@ sub CalendarEventsAsHtml($;$) {
<code>get MyCalendar events limit:count=10,from=0,to=+10d</code><br>
<br><br>
Der <u><code>include</code></u> Parameter schlie&szlig;t Termine aus anderen Kalendern ein. Das ist n&uuml;tzlich,
um Termine aus anderen Kalendern in einer kombimierten Ausgabe anzuzeigen.
<code>&lt;names&gt;</code> ist eine mit Kommas getrennte Liste der Namen von Calendar-Ger&auml;ten.
Der Name des Kalenders selbst sowie Duplikate werden stillschweigend ignoriert. Namen von Ger&auml;ten, die
es nicht gibt oder keine Calendar-Ger&auml;te sind, werden ignoriert und es wird eine Fehlermeldung ins Log
geschrieben.<br><br>
Example:<br>
<code>get MyCalendar events include:Feiertage,M&uuml;llabfuhr</code><br>
<br><br>
Der Parameter <u><code>returnType</code></u> wird verwendet, um die Termine als ein bestimmter Typ
zur&uuml;ckzugeben. Das ist n&uuml;tzlich f&uuml;r Perl-Skripte.<br><br>
<table>
<tr><th align="left"><code>&lt;returnTypeSpec&gt;</code></th><th align="left">Beschreibung</th></tr>
<tr><td><code>$text</code></td><td>ein mehrzeiliger String in menschenlesbarer Darstellung (Vorgabe)</td></tr>
<tr><td><code>@texts</code></td><td>ein Array von Strings in menschenlesbarer Darstellung</td></tr>
<tr><td><code>@event</code></td><td>ein Array von Calendar::Event-Hashs</td></tr>
</table>
<br><br>
</li>