mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
feature: Calendar can read from file and limit number of calendar events retrieved in get command
git-svn-id: https://svn.fhem.de/fhem/trunk@3955 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e4cf2bd9c3
commit
41b1d1f709
@ -1,4 +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.
|
||||||
|
- feature: Calendar can read from file and limit number of calendar events
|
||||||
|
retrieved in get command
|
||||||
- feature: new module 70_ENIGMA2.pm added (by loredo)
|
- feature: new module 70_ENIGMA2.pm added (by loredo)
|
||||||
- change: CustomGetFileFromURL() in HttpUtils.pm now reacts to
|
- change: CustomGetFileFromURL() in HttpUtils.pm now reacts to
|
||||||
"301 Moved Permanently" return code
|
"301 Moved Permanently" return code
|
||||||
|
@ -792,10 +792,29 @@ sub Calendar_GetUpdate($) {
|
|||||||
$hash->{fhem}{lastUpdate}= FmtDateTime($t);
|
$hash->{fhem}{lastUpdate}= FmtDateTime($t);
|
||||||
|
|
||||||
Log3 $hash, 4, "Calendar " . $hash->{NAME} . ": Updating...";
|
Log3 $hash, 4, "Calendar " . $hash->{NAME} . ": Updating...";
|
||||||
|
my $type = $hash->{fhem}{type};
|
||||||
my $url= $hash->{fhem}{url};
|
my $url= $hash->{fhem}{url};
|
||||||
|
|
||||||
my $ics= GetFileFromURLQuiet($url);
|
my $ics;
|
||||||
#my $ics= CustomGetFileFromURL(0, $url, undef, undef, 1);
|
|
||||||
|
if($type eq "url"){
|
||||||
|
$ics= GetFileFromURLQuiet($url) if($type eq "url");
|
||||||
|
} elsif($type eq "file") {
|
||||||
|
if(open(ICSFILE, $url)) {
|
||||||
|
while(<ICSFILE>) {
|
||||||
|
$ics .= $_;
|
||||||
|
}
|
||||||
|
close(ICSFILE);
|
||||||
|
} else {
|
||||||
|
Log3 $hash, 1, "Calendar " . $hash->{NAME} . ": Could not open file $url";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# this case never happens by virtue of _Define, so just
|
||||||
|
die "Software Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!defined($ics)) {
|
if(!defined($ics)) {
|
||||||
Log3 $hash, 1, "Calendar " . $hash->{NAME} . ": Could not retrieve file at URL";
|
Log3 $hash, 1, "Calendar " . $hash->{NAME} . ": Could not retrieve file at URL";
|
||||||
return 0;
|
return 0;
|
||||||
@ -888,7 +907,7 @@ sub Calendar_Get($@) {
|
|||||||
my $cmd= $a[1];
|
my $cmd= $a[1];
|
||||||
if(grep(/^$cmd$/, ("text","full","summary","location","alarm","start","end"))) {
|
if(grep(/^$cmd$/, ("text","full","summary","location","alarm","start","end"))) {
|
||||||
|
|
||||||
return "argument is missing" if($#a != 2);
|
return "argument is missing" if($#a < 2);
|
||||||
my $reading= $a[2];
|
my $reading= $a[2];
|
||||||
|
|
||||||
# $reading is alarmed, all, changed, deleted, new, started, updated
|
# $reading is alarmed, all, changed, deleted, new, started, updated
|
||||||
@ -913,6 +932,11 @@ sub Calendar_Get($@) {
|
|||||||
push @texts, $event->endTime() if $cmd eq "end";
|
push @texts, $event->endTime() if $cmd eq "end";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(defined($a[3])) {
|
||||||
|
my $keep= $a[3];
|
||||||
|
return "Argument $keep is not a number." unless($keep =~ /\d+/);
|
||||||
|
splice @texts, $keep if($#texts>= 0);
|
||||||
|
}
|
||||||
return join("\n", @texts);
|
return join("\n", @texts);
|
||||||
|
|
||||||
} elsif($cmd eq "find") {
|
} elsif($cmd eq "find") {
|
||||||
@ -940,17 +964,20 @@ sub Calendar_Define($$) {
|
|||||||
|
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
return "syntax: define <name> Calendar ical url <URL> [interval]"
|
return "syntax: define <name> Calendar ical url <URL> [interval]\n".\
|
||||||
if(($#a < 4 && $#a > 5) || ($a[2] ne 'ical') || ($a[3] ne 'url'));
|
" define <name> Calendar ical file <FILENAME> [interval]"
|
||||||
|
if(($#a < 4 && $#a > 5) || ($a[2] ne 'ical') || (($a[3] ne 'url') && ($a[3] ne 'file')));
|
||||||
|
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
|
|
||||||
my $name = $a[0];
|
my $name = $a[0];
|
||||||
|
my $type = $a[3];
|
||||||
my $url = $a[4];
|
my $url = $a[4];
|
||||||
my $interval = 3600;
|
my $interval = 3600;
|
||||||
|
|
||||||
$interval= $a[5] if($#a==5);
|
$interval= $a[5] if($#a==5);
|
||||||
|
|
||||||
|
$hash->{fhem}{type}= $type;
|
||||||
$hash->{fhem}{url}= $url;
|
$hash->{fhem}{url}= $url;
|
||||||
$hash->{fhem}{interval}= $interval;
|
$hash->{fhem}{interval}= $interval;
|
||||||
$hash->{fhem}{events}= Calendar::Events->new();
|
$hash->{fhem}{events}= Calendar::Events->new();
|
||||||
@ -991,21 +1018,24 @@ sub Calendar_Undef($$) {
|
|||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>define <name> Calendar ical url <URL> [<interval>]</code><br>
|
<code>define <name> Calendar ical url <URL> [<interval>]</code><br>
|
||||||
|
<code>define <name> Calendar ical file <FILENAME> [<interval>]</code><br>
|
||||||
<br>
|
<br>
|
||||||
Defines a calendar device.<br><br>
|
Defines a calendar device.<br><br>
|
||||||
|
|
||||||
A calendar device periodically gathers calendar events from the source calendar at the given URL. The file at the given URL
|
A calendar device periodically gathers calendar events from the source calendar at the given URL or from a file.
|
||||||
must be in ICal format.<br><br>
|
The file must be in ICal format.<br><br>
|
||||||
|
|
||||||
If the URL
|
If the URL
|
||||||
starts with <code>https://</code>, the perl module IO::Socket::SSL must be installed
|
starts with <code>https://</code>, the perl module IO::Socket::SSL must be installed
|
||||||
(use <code>cpan -i IO::Socket::SSL</code>).<br><br>
|
(use <code>cpan -i IO::Socket::SSL</code>).<br><br>
|
||||||
|
|
||||||
Note for users of Google Calendar: You can literally use the private ICal URL from your Google Calendar.
|
Note for users of Google Calendar: You can literally use the private ICal URL from your Google Calendar.
|
||||||
Google App accounts do not work since requests to the URL
|
<!--Google App accounts do not work since requests to the URL
|
||||||
get redirected first and the fhem mechanism for retrieving data via http/https cannot handle this. If your Google Calendar
|
get redirected first and the fhem mechanism for retrieving data via http/https cannot handle this. -->
|
||||||
|
If your Google Calendar
|
||||||
URL starts with <code>https://</code> and the perl module IO::Socket::SSL is not installed on your system, you can
|
URL starts with <code>https://</code> and the perl module IO::Socket::SSL is not installed on your system, you can
|
||||||
replace it by <code>http://</code>.<br><br>
|
replace it by <code>http://</code> if and only if there is no redirection to the <code>https://</code> URL.
|
||||||
|
Check with your browser first if unsure.<br><br>
|
||||||
|
|
||||||
The optional parameter <code>interval</code> is the time between subsequent updates
|
The optional parameter <code>interval</code> is the time between subsequent updates
|
||||||
in seconds. It defaults to 3600 (1 hour).<br><br>
|
in seconds. It defaults to 3600 (1 hour).<br><br>
|
||||||
@ -1014,6 +1044,7 @@ sub Calendar_Undef($$) {
|
|||||||
<pre>
|
<pre>
|
||||||
define MyCalendar Calendar ical url https://www.google.com­/calendar/ical/john.doe%40example.com­/private-foo4711/basic.ics
|
define MyCalendar Calendar ical url https://www.google.com­/calendar/ical/john.doe%40example.com­/private-foo4711/basic.ics
|
||||||
define YourCalendar Calendar ical url http://www.google.com­/calendar/ical/jane.doe%40example.com­/private-bar0815/basic.ics 86400
|
define YourCalendar Calendar ical url http://www.google.com­/calendar/ical/jane.doe%40example.com­/private-bar0815/basic.ics 86400
|
||||||
|
define SomeCalendar Calendar ical file /home/johndoe/calendar.ics
|
||||||
</pre>
|
</pre>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
@ -1032,12 +1063,13 @@ sub Calendar_Undef($$) {
|
|||||||
<a name="Calendarget"></a>
|
<a name="Calendarget"></a>
|
||||||
<b>Get</b>
|
<b>Get</b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>get <name> full|text|summary|location|alarm|start|end <reading>|<uid></code><br><br>
|
<code>get <name> full|text|summary|location|alarm|start|end <reading>|<uid> [max]</code><br><br>
|
||||||
|
|
||||||
Returns, line by line, the full state or a textual representation or the summary (subject, title) or the
|
Returns, line by line, the full state or a textual representation or the summary (subject, title) or the
|
||||||
location or the alarm time or the start time or the end time
|
location or the alarm time or the start time or the end time
|
||||||
of the calendar event(s) listed in the
|
of the calendar event(s) listed in the
|
||||||
reading <reading> or identified by the UID <uid>.<br><br>
|
reading <reading> or identified by the UID <uid>. The optional parameter <code>max</code> limits
|
||||||
|
the number of returned lines.<br><br>
|
||||||
|
|
||||||
<code>get <name> find <regexp></code><br><br>
|
<code>get <name> find <regexp></code><br><br>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user