2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

multiple events at the same time trigger only one readings update instead of many

added get ... location, alarm, start, end 

git-svn-id: https://svn.fhem.de/fhem/trunk@1665 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2012-06-29 18:12:42 +00:00
parent 6068d8593f
commit 6df120d410
2 changed files with 52 additions and 11 deletions

View File

@ -51,7 +51,7 @@ sub addproperty {
my ($self,$line)= @_; my ($self,$line)= @_;
# TRIGGER;VALUE=DATE-TIME:20120531T150000Z # TRIGGER;VALUE=DATE-TIME:20120531T150000Z
#main::debug "line= $line"; #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"; #main::debug "property= $property parameter= $parameter";
my ($key,$parts)= split(";", $property,2); my ($key,$parts)= split(";", $property,2);
#main::debug "key= $key parts= $parts"; #main::debug "key= $key parts= $parts";
@ -295,12 +295,14 @@ sub dt {
sub ts { sub ts {
my ($tm)= @_; my ($tm)= @_;
return "" unless($tm);
my ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst)= localtime($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); return sprintf("%02d.%02d.%4d %02d:%02d:%02d", $day,$month+1,$year+1900,$hour,$minute,$second);
} }
sub ts0 { sub ts0 {
my ($tm)= @_; my ($tm)= @_;
return "" unless($tm);
my ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst)= localtime($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); 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->{end}= tm($vevent->value("DTEND"));
$self->{lastModified}= tm($vevent->value("LAST-MODIFIED")); $self->{lastModified}= tm($vevent->value("LAST-MODIFIED"));
$self->{summary}= $vevent->value("SUMMARY"); $self->{summary}= $vevent->value("SUMMARY");
$self->{location}= $vevent->value("LOCATION");
#$self->{summary}=~ s/;/,/g; #$self->{summary}=~ s/;/,/g;
# #
@ -366,6 +369,11 @@ sub summary {
return $self->{summary}; return $self->{summary};
} }
sub location {
my ($self)= @_;
return $self->{location};
}
sub asText { sub asText {
my ($self)= @_; 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 # returns 1 if time is before alarm time and before start time, else 0
sub isUpcoming { sub isUpcoming {
my ($self,$t) = @_; my ($self,$t) = @_;
@ -554,19 +578,22 @@ sub Calendar_Wakeup($) {
my $t= time(); my $t= time();
Calendar_GetUpdate($hash) if($t>= $hash->{fhem}{nxtUpdtTs}); Calendar_GetUpdate($hash) if($t>= $hash->{fhem}{nxtUpdtTs});
$hash->{fhem}{lastChkTs}= $t;
$hash->{fhem}{lastCheck}= FmtDateTime($t);
Calendar_CheckTimes($hash); Calendar_CheckTimes($hash);
my $nt= $hash->{fhem}{nxtUpdtTs};
# find next event # find next event
my $nt= $hash->{fhem}{nxtUpdtTs};
foreach my $event ($hash->{fhem}{events}->events()) { foreach my $event ($hash->{fhem}{events}->events()) {
my $et= $event->nextTime($t); 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) ; InternalTimer($nt, "Calendar_Wakeup", $hash, 0) ;
} }
@ -605,6 +632,7 @@ sub Calendar_CheckTimes($) {
my @changed= sort map { $_->uid() } @changedevents; my @changed= sort map { $_->uid() } @changedevents;
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUpdate($hash, "lastCheck", $hash->{fhem}{lastCheck});
readingsUpdate($hash, "modeUpcoming", join(";", @upcoming)); readingsUpdate($hash, "modeUpcoming", join(";", @upcoming));
readingsUpdate($hash, "modeAlarm", join(";", @alarm)); readingsUpdate($hash, "modeAlarm", join(";", @alarm));
readingsUpdate($hash, "modeAlarmed", join(";", @alarmed)); readingsUpdate($hash, "modeAlarmed", join(";", @alarmed));
@ -624,6 +652,10 @@ sub Calendar_GetUpdate($) {
my ($hash) = @_; my ($hash) = @_;
my $t= time();
$hash->{fhem}{lstUpdtTs}= $t;
$hash->{fhem}{lastUpdate}= FmtDateTime($t);
#main::debug "Updating..."; #main::debug "Updating...";
my $url= $hash->{fhem}{url}; my $url= $hash->{fhem}{url};
@ -677,6 +709,7 @@ sub Calendar_GetUpdate($) {
#$hash->{STATE}= $val; #$hash->{STATE}= $val;
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUpdate($hash, "calname", $calname); readingsUpdate($hash, "calname", $calname);
readingsUpdate($hash, "lastUpdate", $hash->{fhem}{lastUpdate});
readingsUpdate($hash, "all", join(";", @all)); readingsUpdate($hash, "all", join(";", @all));
readingsUpdate($hash, "stateNew", join(";", @new)); readingsUpdate($hash, "stateNew", join(";", @new));
readingsUpdate($hash, "stateUpdated", join(";", @updated)); readingsUpdate($hash, "stateUpdated", join(";", @updated));
@ -684,7 +717,10 @@ sub Calendar_GetUpdate($) {
readingsUpdate($hash, "stateChanged", join(";", @changed)); readingsUpdate($hash, "stateChanged", join(";", @changed));
readingsEndUpdate($hash, 1); # DoTrigger, because sub is called by a timer instead of dispatch 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; return 1;
} }
@ -714,7 +750,7 @@ sub Calendar_Get($@) {
my @events; my @events;
my $cmd= $a[1]; 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); return "argument is missing" if($#a != 2);
my $reading= $a[2]; my $reading= $a[2];
@ -735,6 +771,10 @@ sub Calendar_Get($@) {
push @texts, $event->asText() if $cmd eq "text"; push @texts, $event->asText() if $cmd eq "text";
push @texts, $event->asFull() if $cmd eq "full"; push @texts, $event->asFull() if $cmd eq "full";
push @texts, $event->summary() if $cmd eq "summary"; 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); return join("\n", @texts);

View File

@ -1419,9 +1419,10 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="Calendarget"></a> <a name="Calendarget"></a>
<b>Get</b> <b>Get</b>
<ul> <ul>
<code>get &lt;name&gt; full|text|summary &lt;reading&gt|&lt;uid&gt;</code><br><br> <code>get &lt;name&gt; full|text|summary|location|alarm|start|end &lt;reading&gt|&lt;uid&gt;</code><br><br>
Returns, line by line, the full state or a textual representation or the summary (subject, title) 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
of the calendar event(s) listed in the of the calendar event(s) listed in the
reading &lt;reading&gt or identified by the UID &lt;uid&gt.<br><br> reading &lt;reading&gt or identified by the UID &lt;uid&gt.<br><br>