mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
57_CALVIEW: added multiple CALENDAR support, reading source and location for terms
git-svn-id: https://svn.fhem.de/fhem/trunk@8107 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0b2515d611
commit
263d961906
@ -1,4 +1,4 @@
|
|||||||
# $Id: 57_CALVIEW.pm 7006 2015-01-13 20:15:00Z chris1284 $
|
# $Id: 57_CALVIEW.pm 7007 2015-01-13 20:15:00Z chris1284 $
|
||||||
###########################
|
###########################
|
||||||
# CALVIEW
|
# CALVIEW
|
||||||
#
|
#
|
||||||
@ -9,6 +9,7 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
use Date::Parse;
|
||||||
|
|
||||||
sub CALVIEW_Initialize($)
|
sub CALVIEW_Initialize($)
|
||||||
{
|
{
|
||||||
@ -27,16 +28,21 @@ sub CALVIEW_Define($$){
|
|||||||
my @a = split( "[ \t][ \t]*", $def );
|
my @a = split( "[ \t][ \t]*", $def );
|
||||||
return "\"set CALVIEW\" needs at least an argument" if ( @a < 2 );
|
return "\"set CALVIEW\" needs at least an argument" if ( @a < 2 );
|
||||||
my $name = $a[0];
|
my $name = $a[0];
|
||||||
my $calender = $a[2];
|
#my $calender = $a[2];
|
||||||
my $inter = 43200;
|
my $inter = 43200;
|
||||||
my $modes = $a[3];
|
my $modes = $a[3];
|
||||||
return "invalid Calendername \"$calender\", define it first" if((devspec2array("NAME=$calender")) != 1 );
|
my @calendars = split( ",", $a[2] );
|
||||||
$hash->{NAME} = $name;
|
$hash->{NAME} = $name;
|
||||||
$hash->{KALENDER} = $calender;
|
my $calcounter = 1;
|
||||||
|
foreach my $calender (@calendars)
|
||||||
|
{
|
||||||
|
return "invalid Calendername \"$calender\", define it first" if((devspec2array("NAME=$calender")) != 1 );
|
||||||
|
}
|
||||||
|
$hash->{KALENDER} = $a[2];
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
$hash->{INTERVAL} = $inter;
|
$hash->{INTERVAL} = $inter;
|
||||||
if($modes == 1) {$hash->{MODES} = "modeStarted;modeUpcoming"; }
|
if($modes == 1) {$hash->{MODES} = "modeAlarm;modeStart;modeStarted;modeUpcoming"; }
|
||||||
elsif($modes == 0){$hash->{MODES} = "modeStarted";}
|
elsif($modes == 0){$hash->{MODES} = "modeAlarm;modeStart;modeStarted";}
|
||||||
elsif($modes == 2){$hash->{MODES} = "all"; }
|
elsif($modes == 2){$hash->{MODES} = "all"; }
|
||||||
InternalTimer(gettimeofday()+2, "CALVIEW_GetUpdate", $hash, 0);
|
InternalTimer(gettimeofday()+2, "CALVIEW_GetUpdate", $hash, 0);
|
||||||
return undef;
|
return undef;
|
||||||
@ -62,7 +68,7 @@ sub CALVIEW_Set($@){
|
|||||||
}
|
}
|
||||||
sub CALVIEW_GetUpdate($){
|
sub CALVIEW_GetUpdate($){
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $calendername = $hash->{KALENDER};
|
#my $calendername = $hash->{KALENDER};
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
#cleanup readings
|
#cleanup readings
|
||||||
delete ($hash->{READINGS});
|
delete ($hash->{READINGS});
|
||||||
@ -84,30 +90,51 @@ sub CALVIEW_GetUpdate($){
|
|||||||
my $date = "$mday.$mon.$year";
|
my $date = "$mday.$mon.$year";
|
||||||
my $datenext = "$nextday.$mon.$year";
|
my $datenext = "$nextday.$mon.$year";
|
||||||
my @termineNew;
|
my @termineNew;
|
||||||
|
# foreach my $item (@termine ){
|
||||||
|
# my @tempstart=split(/\s+/,$item->[0]);
|
||||||
|
# my @tempend=split(/\s+/,$item->[2]);
|
||||||
|
# push @termineNew,{
|
||||||
|
# bdate => $tempstart[0],
|
||||||
|
# btime => $tempstart[1],
|
||||||
|
# summary => $item->[1],
|
||||||
|
# edate => $tempend[0],
|
||||||
|
# etime => $tempend[1]};}
|
||||||
foreach my $item (@termine ){
|
foreach my $item (@termine ){
|
||||||
my @tempstart=split(/\s+/,$item->[0]);
|
my @tempstart=split(/\s+/,$item->[0]);
|
||||||
my @tempend=split(/\s+/,$item->[2]);
|
my @tempend=split(/\s+/,$item->[2]);
|
||||||
|
my ($D,$M,$Y)=split(/\./,$tempstart[0]);
|
||||||
|
my @bts=str2time($M."/".$D."/".$Y." ".$tempstart[1]);
|
||||||
push @termineNew,{
|
push @termineNew,{
|
||||||
bdate => $tempstart[0],
|
bdate => $tempstart[0],
|
||||||
btime => $tempstart[1],
|
btime => $tempstart[1],
|
||||||
summary => $item->[1],
|
summary => $item->[1],
|
||||||
|
source => $item->[3],
|
||||||
|
location => $item->[4],
|
||||||
edate => $tempend[0],
|
edate => $tempend[0],
|
||||||
etime => $tempend[1]};}
|
etime => $tempend[1],
|
||||||
|
btimestamp => $bts[0]}; }
|
||||||
#my $termin= \@termineNew;
|
#my $termin= \@termineNew;
|
||||||
my $todaycounter = 1;
|
my $todaycounter = 1;
|
||||||
my $tomorrowcounter = 1;
|
my $tomorrowcounter = 1;
|
||||||
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
|
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
|
||||||
# sort the data in the array by bdate
|
# sort the data in the array by bdate
|
||||||
|
# my @sdata = map $_->[0],
|
||||||
|
# sort { $a->[1][2] <=> $b->[1][2] or # year
|
||||||
|
# $a->[1][1] <=> $b->[1][1] or # month
|
||||||
|
# $a->[1][0] <=> $b->[1][0] } # day
|
||||||
|
# map [$_, [split /\./, $_->{bdate}]], @termineNew;
|
||||||
|
# sort the array by btimestamp
|
||||||
my @sdata = map $_->[0],
|
my @sdata = map $_->[0],
|
||||||
sort { $a->[1][2] <=> $b->[1][2] or # year
|
sort { $a->[1][0] <=> $b->[1][0] }
|
||||||
$a->[1][1] <=> $b->[1][1] or # month
|
map [$_, [$_->{btimestamp}]], @termineNew;
|
||||||
$a->[1][0] <=> $b->[1][0] } # day
|
|
||||||
map [$_, [split /\./, $_->{bdate}]], @termineNew;
|
|
||||||
if($readingstyle == 0){
|
if($readingstyle == 0){
|
||||||
for my $termin (@sdata){ #termin als reading term_[3steliger counter]
|
for my $termin (@sdata){ #termin als reading term_[3steliger counter]
|
||||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdate", $termin->{bdate});
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdate", $termin->{bdate});
|
||||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_btime", $termin->{btime});
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_btime", $termin->{btime});
|
||||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary});
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary});
|
||||||
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_source", $termin->{source});
|
||||||
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_location", $termin->{location});
|
||||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edate", $termin->{edate});
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edate", $termin->{edate});
|
||||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_etime", $termin->{etime});
|
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_etime", $termin->{etime});
|
||||||
last if ($counter++ == $max);
|
last if ($counter++ == $max);
|
||||||
@ -117,6 +144,8 @@ sub CALVIEW_GetUpdate($){
|
|||||||
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});
|
||||||
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_source", $termin->{source});
|
||||||
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_location", $termin->{location});
|
||||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edate", $termin->{edate});
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edate", $termin->{edate});
|
||||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime});
|
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime});
|
||||||
$todaycounter ++;}
|
$todaycounter ++;}
|
||||||
@ -125,6 +154,8 @@ sub CALVIEW_GetUpdate($){
|
|||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", "morgen");
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", "morgen");
|
||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", $termin->{btime});
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", $termin->{btime});
|
||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary});
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary});
|
||||||
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_source", $termin->{source});
|
||||||
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_location", $termin->{location});
|
||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edate", $termin->{edate});
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edate", $termin->{edate});
|
||||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_etime", $termin->{etime});
|
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_etime", $termin->{etime});
|
||||||
$tomorrowcounter++;}
|
$tomorrowcounter++;}
|
||||||
@ -159,17 +190,21 @@ sub getsummery($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my @terminliste ;
|
my @terminliste ;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $calendername = $hash->{KALENDER};
|
# my $calendername = $hash->{KALENDER};
|
||||||
|
my @calendernamen = split( ",", $hash->{KALENDER});
|
||||||
my $modi = $hash->{MODES};
|
my $modi = $hash->{MODES};
|
||||||
my @modes = split(/;/,$modi);
|
my @modes = split(/;/,$modi);
|
||||||
foreach my $mode (@modes){
|
foreach my $calendername (@calendernamen){
|
||||||
my $all = ReadingsVal($calendername, $mode, "");
|
foreach my $mode (@modes){
|
||||||
my @uids=split(/;/,$all);
|
my $all = ReadingsVal($calendername, $mode, "");
|
||||||
foreach my $uid (@uids){
|
my @uids=split(/;/,$all);
|
||||||
my $terminstart = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid));
|
foreach my $uid (@uids){
|
||||||
my $termintext = CallFn($calendername, "GetFn", $defs{$calendername}, (" ","summary", $uid));
|
my $terminstart = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid));
|
||||||
my $terminend = CallFn($calendername, "GetFn", $defs{$calendername}, (" ","end", $uid));
|
my $termintext = CallFn($calendername, "GetFn", $defs{$calendername}, (" ","summary", $uid));
|
||||||
push(@terminliste, [$terminstart, $termintext, $terminend]);
|
my $terminend = CallFn($calendername, "GetFn", $defs{$calendername}, (" ","end", $uid));
|
||||||
|
my $terminort = CallFn($calendername, "GetFn", $defs{$calendername}, (" ","location", $uid));
|
||||||
|
push(@terminliste, [$terminstart, $termintext, $terminend, $calendername, $terminort]);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return @terminliste;
|
return @terminliste;
|
||||||
@ -180,9 +215,9 @@ 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 a calendar-device of the 57_Calendar.pm module.</ul>
|
<ul>This module creates a device with deadlines based on calendar-devices of the 57_Calendar.pm module.</ul>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul><code>define <Name> CALVIEW <calendarname> <0 for modeStarted Termine; 1 for modeStarted;modeUpcoming Termine></code></ul><br>
|
<ul><code>define <Name> CALVIEW <calendarname(s) separate with ','> <0 for modeStarted Termine; 1 for modeStarted;modeUpcoming Termine></code></ul><br>
|
||||||
<ul><code>define myView CALVIEW Googlecalendar 1</code></ul><br>
|
<ul><code>define myView CALVIEW Googlecalendar 1</code></ul><br>
|
||||||
<a name="CALVIEW set"></a>
|
<a name="CALVIEW set"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
@ -206,9 +241,9 @@ 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 Kalenders, basierend auf dem 57_Calendar.pm Modul, besitzt.</ul>
|
<ul>Dieses Modul erstellt ein Device welches als Readings Termine eines oder mehrere Kalender(s), basierend auf dem 57_Calendar.pm Modul, besitzt.</ul>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul><code>define <Name> CALVIEW <Kalendername> <0 für modeStarted Termine; 1 für modeStarted;modeUpcoming Termine></code></ul><br>
|
<ul><code>define <Name> CALVIEW <Kalendername(n) getrennt durch ','> <0 für modeStarted Termine; 1 für modeStarted;modeUpcoming Termine></code></ul><br>
|
||||||
<ul><code>define myView CALVIEW Googlekalender 1</code></ul><br>
|
<ul><code>define myView CALVIEW Googlekalender 1</code></ul><br>
|
||||||
<a name="CALVIEW set"></a>
|
<a name="CALVIEW set"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user