mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-28 11:01:59 +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:
parent
8a5b9a65a2
commit
349eb2f187
@ -2,6 +2,7 @@
|
|||||||
###########################
|
###########################
|
||||||
# CALVIEW
|
# CALVIEW
|
||||||
# needs a defined Device 57_Calendar
|
# needs a defined Device 57_Calendar
|
||||||
|
# needs perl-modul Date::Parse
|
||||||
###########################
|
###########################
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
@ -17,10 +18,12 @@ sub CALVIEW_Initialize($)
|
|||||||
$hash->{DefFn} = "CALVIEW_Define";
|
$hash->{DefFn} = "CALVIEW_Define";
|
||||||
$hash->{UndefFn} = "CALVIEW_Undef";
|
$hash->{UndefFn} = "CALVIEW_Undef";
|
||||||
$hash->{SetFn} = "CALVIEW_Set";
|
$hash->{SetFn} = "CALVIEW_Set";
|
||||||
$hash->{AttrList} = "do_not_notify:1,0 " .
|
$hash->{NotifyFn} = "CALVIEW_Notify";
|
||||||
|
$hash->{AttrList} = "disable:0,1 " .
|
||||||
|
"do_not_notify:1,0 " .
|
||||||
"maxreadings " .
|
"maxreadings " .
|
||||||
"oldStyledReadings:1,0 " .
|
|
||||||
"modes:next ".
|
"modes:next ".
|
||||||
|
"oldStyledReadings:1,0 " .
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
sub CALVIEW_Define($$){
|
sub CALVIEW_Define($$){
|
||||||
@ -41,11 +44,13 @@ sub CALVIEW_Define($$){
|
|||||||
$hash->{KALENDER} = $a[2];
|
$hash->{KALENDER} = $a[2];
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
$hash->{INTERVAL} = $inter;
|
$hash->{INTERVAL} = $inter;
|
||||||
$modes = 1 if (!defined($modes));
|
$modes = "next" if (!defined($modes));
|
||||||
if($modes == 1) {$attr{$name}{modes} = "next";}
|
if($modes == 1) {$attr{$name}{modes} = "next";}
|
||||||
elsif($modes == 0){$attr{$name}{modes} = "next";}
|
elsif($modes == 0){$attr{$name}{modes} = "next";}
|
||||||
elsif($modes == 2){$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);
|
InternalTimer(gettimeofday()+2, "CALVIEW_GetUpdate", $hash, 0);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -92,8 +97,8 @@ sub CALVIEW_GetUpdate($){
|
|||||||
my ($D,$M,$Y)=split(/\./,$tempstart[0]);
|
my ($D,$M,$Y)=split(/\./,$tempstart[0]);
|
||||||
my @bts=str2time($M."/".$D."/".$Y." ".$tempstart[1]);
|
my @bts=str2time($M."/".$D."/".$Y." ".$tempstart[1]);
|
||||||
#replace the "\," with ","
|
#replace the "\," with ","
|
||||||
$item->[1] =~ s/\\,/,/g;
|
if(length($item->[1]) > 0){ $item->[1] =~ s/\\,/,/g; }
|
||||||
$item->[4] =~ s/\\,/,/g;
|
if(length($item->[4]) > 0){ $item->[4] =~ s/\\,/,/g; }
|
||||||
push @termineNew,{
|
push @termineNew,{
|
||||||
bdate => $tempstart[0],
|
bdate => $tempstart[0],
|
||||||
btime => $tempstart[1],
|
btime => $tempstart[1],
|
||||||
@ -106,7 +111,7 @@ sub CALVIEW_GetUpdate($){
|
|||||||
mode => $item->[5]}; }
|
mode => $item->[5]}; }
|
||||||
my $todaycounter = 1;
|
my $todaycounter = 1;
|
||||||
my $tomorrowcounter = 1;
|
my $tomorrowcounter = 1;
|
||||||
my $runningcounter = 1;
|
#my $runningcounter = 1;
|
||||||
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
|
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
|
||||||
# sort the array by btimestamp
|
# sort the array by btimestamp
|
||||||
my @sdata = map $_->[0],
|
my @sdata = map $_->[0],
|
||||||
@ -126,7 +131,8 @@ sub CALVIEW_GetUpdate($){
|
|||||||
last if ($counter++ == $max);
|
last if ($counter++ == $max);
|
||||||
};
|
};
|
||||||
for my $termin (@sdata){ #check ob temin heute
|
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)."_bdate", "heute");
|
||||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime});
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime});
|
||||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary});
|
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)."_etime", $termin->{etime});
|
||||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
|
||||||
$todaycounter ++;}
|
$todaycounter ++;}
|
||||||
elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){
|
#elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute");
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute");
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_btime", $termin->{btime});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_btime", $termin->{btime});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_summary", $termin->{summary});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_summary", $termin->{summary});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_source", $termin->{source});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_source", $termin->{source});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_location", $termin->{location});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_location", $termin->{location});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_edate", $termin->{edate});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_edate", $termin->{edate});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_etime", $termin->{etime});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_etime", $termin->{etime});
|
||||||
readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_mode", $termin->{mode});
|
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_mode", $termin->{mode});
|
||||||
$runningcounter ++;}
|
# $runningcounter ++;}
|
||||||
#check ob termin morgen
|
#check ob termin morgen
|
||||||
elsif ($datenext eq $termin->{bdate}){
|
elsif ($datenext eq $termin->{bdate}){
|
||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen");
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen");
|
||||||
@ -158,11 +164,12 @@ sub CALVIEW_GetUpdate($){
|
|||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
|
||||||
$tomorrowcounter++;}
|
$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-term", $counter-1);
|
||||||
readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
|
readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
|
||||||
readingsBulkUpdate($hash, "c-today", $todaycounter-1);
|
readingsBulkUpdate($hash, "c-today", $todaycounter-1);
|
||||||
readingsBulkUpdate($hash, "c-started", $runningcounter-1);
|
#readingsBulkUpdate($hash, "c-started", $runningcounter-1);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
my $lastreadingname = "";
|
my $lastreadingname = "";
|
||||||
@ -200,7 +207,6 @@ sub getsummery($)
|
|||||||
|
|
||||||
foreach my $termin (@termine){
|
foreach my $termin (@termine){
|
||||||
my @uid=split(/\s+/,$termin);
|
my @uid=split(/\s+/,$termin);
|
||||||
|
|
||||||
#für jedes event die einzelnen infos holen
|
#für jedes event die einzelnen infos holen
|
||||||
my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid[0]));
|
my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid[0]));
|
||||||
my @starts = split(/\n/,$tmpstarts);
|
my @starts = split(/\n/,$tmpstarts);
|
||||||
@ -226,6 +232,27 @@ sub getsummery($)
|
|||||||
};
|
};
|
||||||
return @terminliste;
|
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;
|
1;
|
||||||
=pod
|
=pod
|
||||||
=begin html
|
=begin html
|
||||||
@ -233,16 +260,21 @@ sub getsummery($)
|
|||||||
<a name="CALVIEW"></a>
|
<a name="CALVIEW"></a>
|
||||||
<h3>CALVIEW</h3>
|
<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>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>
|
<b>Define</b>
|
||||||
<ul><code>define <Name> CALVIEW <calendarname(s) separate with ','> <0 for modeAlarm;modeStart;modeStarted; 1 for modeAlarm;modeStart;modeStarted;modeUpcoming; 2 for all (reading all); 3 for modeAlarmOrStart;modeUpcoming > <updateintervall in sec (default 43200)></code></ul><br>
|
<ul><code>define <Name> CALVIEW <calendarname(s) separate with ','> <0 next; 1 next 2 for next ; 3 for next ; next > <updateintervall in sec (default 43200)></code></ul>
|
||||||
<ul><code>define myView CALVIEW Googlecalendar 1</code></ul><br>
|
<ul><code>define myView CALVIEW Googlecalendar next</code></ul>
|
||||||
<ul><code>define myView CALVIEW Googlecalendar,holiday 1 900</code></ul><br>
|
<ul><code>define myView CALVIEW Googlecalendar,holiday next 900</code></ul>
|
||||||
<a name="CALVIEW set"></a>
|
<a name="CALVIEW set"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>update readings:</ul>
|
|
||||||
<ul><code>set <Name> update</code></ul>
|
<ul><code>set <Name> 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>
|
<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>
|
<li>maxreadings<br>
|
||||||
defines the number of max term as readings
|
defines the number of max term as readings
|
||||||
</li><br>
|
</li><br>
|
||||||
@ -260,16 +292,21 @@ sub getsummery($)
|
|||||||
<a name="CALVIEW"></a>
|
<a name="CALVIEW"></a>
|
||||||
<h3>CALVIEW</h3>
|
<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>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>
|
<b>Define</b>
|
||||||
<ul><code>define <Name> CALVIEW <Kalendername(n) getrennt durch ','> <0 für modeAlarm;modeStart;modeStarted; 1 für modeAlarm;modeStart;modeStarted;modeUpcoming; 2 für alle (reading all); 3 für modeAlarmOrStart;modeUpcoming > <updateintervall in sek (default 43200)></code></ul><br>
|
<ul><code>define <Name> CALVIEW <Kalendername(n) getrennt durch ','> <0 next; 1 next 2 for next ; 3 for next ; next > <updateintervall in sek (default 43200)></code></ul>
|
||||||
<ul><code>define myView CALVIEW Googlekalender 1</code></ul><br>
|
<ul><code>define myView CALVIEW Googlekalender 1</code></ul>
|
||||||
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul><br>
|
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul>
|
||||||
<a name="CALVIEW set"></a>
|
<a name="CALVIEW set"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>update readings:</ul>
|
<ul>update readings:</ul>
|
||||||
<ul><code>set <Name> update</code></ul>
|
<ul><code>set <Name> update</code></ul>
|
||||||
<ul><code>set myView update</code></ul><br>
|
<ul><code>set myView update</code></ul><br>
|
||||||
<b>Attributes</b>
|
<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>
|
<li>maxreadings<br>
|
||||||
bestimmt die Anzahl der Termine als Readings
|
bestimmt die Anzahl der Termine als Readings
|
||||||
</li><br>
|
</li><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user