2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

57_CALVIEW.pm: -added internal notify-fn for calendar-devices

-added attr disable for internal notify-fn
               -removed ts state and started_* reading
               -removed old mode-attributes /def modes
               -changed commandref

git-svn-id: https://svn.fhem.de/fhem/trunk@10902 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
chris1284 2016-02-21 14:50:22 +00:00
parent 8a5b9a65a2
commit 349eb2f187

View File

@ -2,6 +2,7 @@
###########################
# CALVIEW
# needs a defined Device 57_Calendar
# needs perl-modul Date::Parse
###########################
package main;
@ -16,11 +17,13 @@ sub CALVIEW_Initialize($)
$hash->{DefFn} = "CALVIEW_Define";
$hash->{UndefFn} = "CALVIEW_Undef";
$hash->{SetFn} = "CALVIEW_Set";
$hash->{AttrList} = "do_not_notify:1,0 " .
$hash->{SetFn} = "CALVIEW_Set";
$hash->{NotifyFn} = "CALVIEW_Notify";
$hash->{AttrList} = "disable:0,1 " .
"do_not_notify:1,0 " .
"maxreadings " .
"oldStyledReadings:1,0 " .
"modes:next ".
"oldStyledReadings:1,0 " .
$readingFnAttributes;
}
sub CALVIEW_Define($$){
@ -41,11 +44,13 @@ sub CALVIEW_Define($$){
$hash->{KALENDER} = $a[2];
$hash->{STATE} = "Initialized";
$hash->{INTERVAL} = $inter;
$modes = 1 if (!defined($modes));
$modes = "next" if (!defined($modes));
if($modes == 1) {$attr{$name}{modes} = "next";}
elsif($modes == 0){$attr{$name}{modes} = "next";}
elsif($modes == 2){$attr{$name}{modes} = "next";}
else {return "invalid mode \"$modes\", use 0,1 or 2!"}
elsif($modes == 3){$attr{$name}{modes} = "next";}
elsif($modes eq "next"){$attr{$name}{modes} = "next";}
else {return "invalid mode \"$modes\", use 0,1,2 or next!"}
InternalTimer(gettimeofday()+2, "CALVIEW_GetUpdate", $hash, 0);
return undef;
}
@ -92,8 +97,8 @@ sub CALVIEW_GetUpdate($){
my ($D,$M,$Y)=split(/\./,$tempstart[0]);
my @bts=str2time($M."/".$D."/".$Y." ".$tempstart[1]);
#replace the "\," with ","
$item->[1] =~ s/\\,/,/g;
$item->[4] =~ s/\\,/,/g;
if(length($item->[1]) > 0){ $item->[1] =~ s/\\,/,/g; }
if(length($item->[4]) > 0){ $item->[4] =~ s/\\,/,/g; }
push @termineNew,{
bdate => $tempstart[0],
btime => $tempstart[1],
@ -106,7 +111,7 @@ sub CALVIEW_GetUpdate($){
mode => $item->[5]}; }
my $todaycounter = 1;
my $tomorrowcounter = 1;
my $runningcounter = 1;
#my $runningcounter = 1;
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
# sort the array by btimestamp
my @sdata = map $_->[0],
@ -126,7 +131,8 @@ sub CALVIEW_GetUpdate($){
last if ($counter++ == $max);
};
for my $termin (@sdata){ #check ob temin heute
if ($date eq $termin->{bdate} && $termin->{mode} ne "modeStart"){
#if ($date eq $termin->{bdate} && $termin->{mode} ne "modeStart"){
if ($date eq $termin->{bdate} ){
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_bdate", "heute");
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary});
@ -136,16 +142,16 @@ sub CALVIEW_GetUpdate($){
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
$todaycounter ++;}
elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute");
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_btime", $termin->{btime});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_summary", $termin->{summary});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_source", $termin->{source});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_location", $termin->{location});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_edate", $termin->{edate});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_etime", $termin->{etime});
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_mode", $termin->{mode});
$runningcounter ++;}
#elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute");
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_btime", $termin->{btime});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_summary", $termin->{summary});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_source", $termin->{source});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_location", $termin->{location});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_edate", $termin->{edate});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_etime", $termin->{etime});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_mode", $termin->{mode});
# $runningcounter ++;}
#check ob termin morgen
elsif ($datenext eq $termin->{bdate}){
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen");
@ -158,11 +164,12 @@ sub CALVIEW_GetUpdate($){
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
$tomorrowcounter++;}
};
readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1)." ts: ".($runningcounter-1));
#readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1)." ts: ".($runningcounter-1));
readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1));
readingsBulkUpdate($hash, "c-term", $counter-1);
readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
readingsBulkUpdate($hash, "c-today", $todaycounter-1);
readingsBulkUpdate($hash, "c-started", $runningcounter-1);
#readingsBulkUpdate($hash, "c-started", $runningcounter-1);
}
else{
my $lastreadingname = "";
@ -200,7 +207,6 @@ sub getsummery($)
foreach my $termin (@termine){
my @uid=split(/\s+/,$termin);
#für jedes event die einzelnen infos holen
my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid[0]));
my @starts = split(/\n/,$tmpstarts);
@ -226,6 +232,27 @@ sub getsummery($)
};
return @terminliste;
}
sub CALVIEW_Notify($$)
{
my ($hash, $extDevHash) = @_;
my $name = $hash->{NAME}; # name calview device
my $extDevName = $extDevHash->{NAME}; # name externes device
my @calendernams = split( ",", $hash->{KALENDER});
my $event;
return "" if(IsDisabled($name)); # wenn attr disabled keine reaktion
foreach my $calendar (@calendernams){
if ($extDevName eq $calendar) {
foreach $event (@{$extDevHash->{CHANGED}}) {
if ($event eq "triggered") {
Log3 $name , 3, "CALVIEW $name - CALENDAR:$extDevName triggered, updating CALVIEW $name ...";
CALVIEW_GetUpdate($hash);
}
}
}
}
}
1;
=pod
=begin html
@ -233,16 +260,21 @@ sub getsummery($)
<a name="CALVIEW"></a>
<h3>CALVIEW</h3>
<ul>This module creates a device with deadlines based on calendar-devices of the 57_Calendar.pm module. You need to install the perl-modul Date::Parse!</ul>
<ul>Actually the module supports only the "get <> next" function of the CALENDAR-Modul.</ul>
<b>Define</b>
<ul><code>define &lt;Name&gt; CALVIEW &lt;calendarname(s) separate with ','&gt; &lt;0 for modeAlarm;modeStart;modeStarted; 1 for modeAlarm;modeStart;modeStarted;modeUpcoming; 2 for all (reading all); 3 for modeAlarmOrStart;modeUpcoming &gt; &lt;updateintervall in sec (default 43200)&gt;</code></ul><br>
<ul><code>define myView CALVIEW Googlecalendar 1</code></ul><br>
<ul><code>define myView CALVIEW Googlecalendar,holiday 1 900</code></ul><br>
<ul><code>define &lt;Name&gt; CALVIEW &lt;calendarname(s) separate with ','&gt; &lt;0 next; 1 next 2 for next ; 3 for next ; next &gt; &lt;updateintervall in sec (default 43200)&gt;</code></ul>
<ul><code>define myView CALVIEW Googlecalendar next</code></ul>
<ul><code>define myView CALVIEW Googlecalendar,holiday next 900</code></ul>
<a name="CALVIEW set"></a>
<b>Set</b>
<ul>update readings:</ul>
<ul><code>set &lt;Name&gt; update</code></ul>
<ul><code>set myView update</code></ul><br>
<ul><code>set myView update</code></ul>
<ul>this will manually update all readings from the given CALENDAR Devices</ul>
<b>Attribute</b>
<li>disable<br>
0 - disable the internal notify-function of CALVIEW wich is triggered when one of the given CALENDAR devices has updated
1 / not set - internal notify function enabled (default)
</li><br>
<li>maxreadings<br>
defines the number of max term as readings
</li><br>
@ -260,16 +292,21 @@ sub getsummery($)
<a name="CALVIEW"></a>
<h3>CALVIEW</h3>
<ul>Dieses Modul erstellt ein Device welches als Readings Termine eines oder mehrere Kalender(s), basierend auf dem 57_Calendar.pm Modul, besitzt. Ihr müsst das Perl-Modul Date::Parse installieren!</ul>
<ul>Aktuell wird nur die "get <> next" Funktion vom CALENDAR untertstützt.</ul>
<b>Define</b>
<ul><code>define &lt;Name&gt; CALVIEW &lt;Kalendername(n) getrennt durch ','&gt; &lt;0 für modeAlarm;modeStart;modeStarted; 1 für modeAlarm;modeStart;modeStarted;modeUpcoming; 2 für alle (reading all); 3 für modeAlarmOrStart;modeUpcoming &gt &lt;updateintervall in sek (default 43200)&gt;</code></ul><br>
<ul><code>define myView CALVIEW Googlekalender 1</code></ul><br>
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul><br>
<ul><code>define &lt;Name&gt; CALVIEW &lt;Kalendername(n) getrennt durch ','&gt; &lt;0 next; 1 next 2 for next ; 3 for next ; next &gt; &lt;updateintervall in sek (default 43200)&gt;</code></ul>
<ul><code>define myView CALVIEW Googlekalender 1</code></ul>
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul>
<a name="CALVIEW set"></a>
<b>Set</b>
<ul>update readings:</ul>
<ul><code>set &lt;Name&gt; update</code></ul>
<ul><code>set myView update</code></ul><br>
<b>Attributes</b>
<li>disable<br>
0 - deaktiviert die interne Notify-Funktion welche ausgelöst wird wenn sich einer der Kalender aktualisiert hat
1 / nicht gesetzt - aktiviert die interne Notify-Funktion (Standard)
</li><br>
<li>maxreadings<br>
bestimmt die Anzahl der Termine als Readings
</li><br>