From 3d4fb48cc3fd8ed597cf9a9ecf751587f5f083ab Mon Sep 17 00:00:00 2001 From: borisneubert Date: Fri, 29 Jun 2012 18:12:42 +0000 Subject: [PATCH] multiple events at the same time trigger only one readings update instead of many added get ... location, alarm, start, end git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1665 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/57_Calendar.pm | 58 +++++++++++++++++++++++++++++++++++++------- docs/commandref.html | 5 ++-- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/FHEM/57_Calendar.pm b/FHEM/57_Calendar.pm index e693f256d..cc6f88f59 100644 --- a/FHEM/57_Calendar.pm +++ b/FHEM/57_Calendar.pm @@ -51,7 +51,7 @@ sub addproperty { my ($self,$line)= @_; # TRIGGER;VALUE=DATE-TIME:20120531T150000Z #main::debug "line= $line"; - my ($property,$parameter)= split(":", $line); # TRIGGER;VALUE=DATE-TIME 20120531T150000Z + my ($property,$parameter)= split(":", $line,2); # TRIGGER;VALUE=DATE-TIME 20120531T150000Z #main::debug "property= $property parameter= $parameter"; my ($key,$parts)= split(";", $property,2); #main::debug "key= $key parts= $parts"; @@ -295,12 +295,14 @@ sub dt { sub ts { my ($tm)= @_; + return "" unless($tm); my ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst)= localtime($tm); return sprintf("%02d.%02d.%4d %02d:%02d:%02d", $day,$month+1,$year+1900,$hour,$minute,$second); } sub ts0 { my ($tm)= @_; + return "" unless($tm); my ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst)= localtime($tm); return sprintf("%02d.%02d.%2d %02d:%02d", $day,$month+1,$year-100,$hour,$minute); } @@ -314,6 +316,7 @@ sub fromVEvent { $self->{end}= tm($vevent->value("DTEND")); $self->{lastModified}= tm($vevent->value("LAST-MODIFIED")); $self->{summary}= $vevent->value("SUMMARY"); + $self->{location}= $vevent->value("LOCATION"); #$self->{summary}=~ s/;/,/g; # @@ -366,6 +369,11 @@ sub summary { return $self->{summary}; } +sub location { + my ($self)= @_; + return $self->{location}; +} + sub asText { my ($self)= @_; @@ -388,6 +396,22 @@ sub asFull { ); } +sub alarmTime { + my ($self)= @_; + return ts($self->{alarm}); +} + +sub startTime { + my ($self)= @_; + return ts($self->{start}); +} + +sub endTime { + my ($self)= @_; + return ts($self->{end}); +} + + # returns 1 if time is before alarm time and before start time, else 0 sub isUpcoming { my ($self,$t) = @_; @@ -554,19 +578,22 @@ sub Calendar_Wakeup($) { my $t= time(); Calendar_GetUpdate($hash) if($t>= $hash->{fhem}{nxtUpdtTs}); + + $hash->{fhem}{lastChkTs}= $t; + $hash->{fhem}{lastCheck}= FmtDateTime($t); Calendar_CheckTimes($hash); - my $nt= $hash->{fhem}{nxtUpdtTs}; - # find next event + my $nt= $hash->{fhem}{nxtUpdtTs}; foreach my $event ($hash->{fhem}{events}->events()) { my $et= $event->nextTime($t); - $nt= $et if(defined($et) && ($et< $nt)); + # we only consider times in the future to avoid multiple + # invocations for calendar events with the event time + $nt= $et if(defined($et) && ($et< $nt) && ($et > $t)); } + $hash->{fhem}{nextChkTs}= $nt; + $hash->{fhem}{nextCheck}= FmtDateTime($nt); - my ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst)= localtime($nt); - $hash->{fhem}{nextUpdate}= sprintf("%02d.%02d.%4d %02d:%02d:%02d", $day,$month+1,$year+1900,$hour,$minute,$second); - InternalTimer($nt, "Calendar_Wakeup", $hash, 0) ; } @@ -605,6 +632,7 @@ sub Calendar_CheckTimes($) { my @changed= sort map { $_->uid() } @changedevents; readingsBeginUpdate($hash); + readingsUpdate($hash, "lastCheck", $hash->{fhem}{lastCheck}); readingsUpdate($hash, "modeUpcoming", join(";", @upcoming)); readingsUpdate($hash, "modeAlarm", join(";", @alarm)); readingsUpdate($hash, "modeAlarmed", join(";", @alarmed)); @@ -624,6 +652,10 @@ sub Calendar_GetUpdate($) { my ($hash) = @_; + my $t= time(); + $hash->{fhem}{lstUpdtTs}= $t; + $hash->{fhem}{lastUpdate}= FmtDateTime($t); + #main::debug "Updating..."; my $url= $hash->{fhem}{url}; @@ -677,6 +709,7 @@ sub Calendar_GetUpdate($) { #$hash->{STATE}= $val; readingsBeginUpdate($hash); readingsUpdate($hash, "calname", $calname); + readingsUpdate($hash, "lastUpdate", $hash->{fhem}{lastUpdate}); readingsUpdate($hash, "all", join(";", @all)); readingsUpdate($hash, "stateNew", join(";", @new)); readingsUpdate($hash, "stateUpdated", join(";", @updated)); @@ -684,7 +717,10 @@ sub Calendar_GetUpdate($) { readingsUpdate($hash, "stateChanged", join(";", @changed)); readingsEndUpdate($hash, 1); # DoTrigger, because sub is called by a timer instead of dispatch - $hash->{fhem}{nxtUpdtTs}= time()+$hash->{fhem}{interval}; + $t+= $hash->{fhem}{interval}; + $hash->{fhem}{nxtUpdtTs}= $t; + $hash->{fhem}{nextUpdate}= FmtDateTime($t); + return 1; } @@ -714,7 +750,7 @@ sub Calendar_Get($@) { my @events; my $cmd= $a[1]; - if($cmd eq "text" || $cmd eq "full" || $cmd eq "summary") { + if(grep(/^$cmd$/, ("text","full","summary","location","alarm","start","end"))) { return "argument is missing" if($#a != 2); my $reading= $a[2]; @@ -735,6 +771,10 @@ sub Calendar_Get($@) { push @texts, $event->asText() if $cmd eq "text"; push @texts, $event->asFull() if $cmd eq "full"; push @texts, $event->summary() if $cmd eq "summary"; + push @texts, $event->location() if $cmd eq "location"; + push @texts, $event->alarmTime() if $cmd eq "alarm"; + push @texts, $event->startTime() if $cmd eq "start"; + push @texts, $event->endTime() if $cmd eq "end"; } } return join("\n", @texts); diff --git a/docs/commandref.html b/docs/commandref.html index edc89df4d..5f965e2f4 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -1419,9 +1419,10 @@ A line ending with \ will be concatenated with the next one, so long lines Get