From 8a665abd5761fc1d3faf8e75c46ee18ee37a7cfc Mon Sep 17 00:00:00 2001 From: betateilchen Date: Sat, 23 Feb 2019 13:05:53 +0000 Subject: [PATCH] 57_Calendar.pm: new features and attributes, Forum #97769 git-svn-id: https://svn.fhem.de/fhem/trunk@18697 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/57_Calendar.pm | 517 +++++---------------------------------- 1 file changed, 68 insertions(+), 449 deletions(-) diff --git a/fhem/FHEM/57_Calendar.pm b/fhem/FHEM/57_Calendar.pm index 9aa6f4640..c8ab767e9 100644 --- a/fhem/FHEM/57_Calendar.pm +++ b/fhem/FHEM/57_Calendar.pm @@ -1683,11 +1683,15 @@ sub Calendar_Initialize($) { $hash->{SetFn} = "Calendar_Set"; $hash->{AttrFn} = "Calendar_Attr"; $hash->{NotifyFn}= "Calendar_Notify"; - $hash->{AttrList}= "update:sync,async,none removevcalendar:0,1 " . - "cutoffOlderThan hideOlderThan hideLaterThan onCreateEvent " . - "ignoreCancelled:0,1 quirks " . - "SSLVerify:0,1 defaultFormat defaultTimeFormat " . - $readingFnAttributes; + $hash->{AttrList}= "update:none,onUrlChanged ". + "synchronousUpdate:0,1 ". + "removevcalendar:0,1 " . + "ignoreCancelled:0,1 ". + "SSLVerify:0,1 ". + "cutoffOlderThan hideOlderThan hideLaterThan ". + "onCreateEvent quirks ". + "defaultFormat defaultTimeFormat ". + $readingFnAttributes; } @@ -1711,11 +1715,14 @@ sub Calendar_Define($$) { my $type = $a[3]; my $url = $a[4]; my $interval = 3600; - - $interval= $a[5] if($#a==5); + if($#a==5) { + $interval= $a[5] if ($a[5] > 0); + Log3 $hash,2,"Calendar $name: interval $a[5] not allowed. Using 3600 as default." if ($a[5] <= 0); + } $hash->{".fhem"}{type}= $type; $hash->{".fhem"}{url}= $url; + $hash->{".fhem"}{lasturl}= $url; $hash->{".fhem"}{interval}= $interval; $hash->{".fhem"}{lastid}= 0; $hash->{".fhem"}{vevents}= {}; @@ -1768,9 +1775,17 @@ sub Calendar_Attr(@) { return "$arg must be a perl command in curly brackets but you supplied $arg."; } } elsif($a[0] eq "update") { - my @args= qw/none sync async/; - return "Argument for update must be one of " . join(" ", @args) . - " instead of $arg." unless($arg ~~ @args); + my @args= qw/sync async/; + if ($arg ~~ @args) { # inform about new attribute synchronousUpdate + Log3 $hash,2,"Calendar $name: Value '$arg' for attribute 'update' is deprecated."; + Log3 $hash,2,"Calendar $name: Please use new attribute 'synchronousUpdate' if really needed."; + Log3 $hash,2,"Calendar $name: Attribute 'update' deleted. Please use 'save config' to update your configuration."; + CommandDefine(undef,"delattr_$name at +00:00:01 deleteattr $name update"); + return undef; + } + @args= qw/none onUrlChanged/; + return "Calendar $name: Argument for update must be one of " . join(" ", @args) . + " instead of $arg." unless($arg ~~ @args); } return undef; @@ -2469,9 +2484,20 @@ sub Calendar_GetUpdate($$$;$) { return; } + my @ti = localtime; + my $url= ResolveDateWildcards($hash->{".fhem"}{url}, @ti); + + if($url ne $hash->{".fhem"}{lasturl}) { + $hash->{".fhem"}{lasturl} = $url; + } elsif (!$force && (AttrVal($hash->{NAME},"update","") eq "onUrlChanged")) { + Log3 $hash,4,"Calendar $name: unchanged url and update set to unUrlChanged = nothing to do."; + Calendar_CheckTimes($hash, $t); + Calendar_RearmTimer($hash, $t); + return; + } + Log3 $hash, 4, "Calendar $name: Updating..."; my $type = $hash->{".fhem"}{type}; - my $url= $hash->{".fhem"}{url}; my $errmsg= ""; my $ics; @@ -2590,10 +2616,10 @@ sub Calendar_ProcessUpdate($$$) { } else { $hash->{".fhem"}{iCalendar}= $ics; # the plain text iCalendar $hash->{".fhem"}{removeall}= $removeall; - if(AttrVal($name, "update", "sync") eq "async") { - Calendar_AsynchronousUpdateCalendar($hash); - } else { + if(AttrVal($name, "synchronousUpdate", 0) == 1) { Calendar_SynchronousUpdateCalendar($hash); + } else { + Calendar_AsynchronousUpdateCalendar($hash); } } @@ -3202,8 +3228,23 @@ sub CalendarEventsAsHtml($;$) { If the URL starts with https://, the perl module IO::Socket::SSL must be installed - (use cpan -i IO::Socket::SSL).

- + (use cpan -i IO::Socket::SSL).
+
+ <URL> may contain %-wildcards of the + POSIX strftime function of the underlying OS (see your strftime manual). + Common used wildcards are: + +
+ Wildcards in url will be evaluated on every calendar update.
+
Note for users of Google Calendar: You can literally use the private ICal URL from your Google Calendar. If your Google Calendar URL starts with https:// and the perl module IO::Socket::SSL is not installed on your system, you can @@ -3494,12 +3535,17 @@ sub CalendarEventsAsHtml($;$) { command. The specification is explained there. Do not enclose the <timeFormatSpec> in quotes.

-
  • update sync|async|none
    - If this attribute is not set or if it is set to sync, the processing of - the calendar is done in the foreground. Large calendars will block FHEM on slow - systems. If this attribute is set to async, the processing is done in the - background and FHEM will not block during updates. If this attribute is set to - none, the calendar will not be updated at all. +
  • synchronousUpdate 0|1
    + If this attribute is not set or if it is set to 0, the processing is done + in the background and FHEM will not block during updates.
    + If this attribute is set to 1, the processing of the calendar is done + in the foreground. Large calendars will block FHEM on slow systems.
    +
  • + +

  • update onUrlChanged|none
    + If this attribute is set to onUrlChanged, the processing is done only + if url to calendar has changed since last calendar update.
    + If this attribute is set to none, the calendar will not be updated at all.
  • removevcalendar 0|1
    @@ -3822,432 +3868,5 @@ sub CalendarEventsAsHtml($;$) { =end html -=begin html_DE - -

    Calendar

    - - -=end html_DE =cut