57_CALVIEW.pm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. # $Id: 57_CALVIEW.pm 16023 2018-01-28 16:28:47Z chris1284 $
  2. ############################
  3. # CALVIEW
  4. # needs a defined Device 57_Calendar
  5. # needs perl-modul Date::Parse
  6. ############################
  7. package main;
  8. use strict;
  9. use warnings;
  10. use POSIX;
  11. use Date::Parse;
  12. #use Date::Calc qw(Day_of_Week);
  13. sub CALVIEW_Initialize($)
  14. {
  15. my ($hash) = @_;
  16. $hash->{DefFn} = "CALVIEW_Define";
  17. $hash->{UndefFn} = "CALVIEW_Undef";
  18. $hash->{SetFn} = "CALVIEW_Set";
  19. $hash->{NotifyFn} = "CALVIEW_Notify";
  20. $hash->{AttrList} = "datestyle:ISO8601 " .
  21. "disable:0,1 " .
  22. "do_not_notify:1,0 " .
  23. "filterSummary:textField-long " .
  24. "fulldaytext " .
  25. "isbirthday:1,0 " .
  26. "maxreadings " .
  27. "modes:next ".
  28. "oldStyledReadings:1,0 " .
  29. "sourcecolor:textField-long " .
  30. "timeshort:1,0 " .
  31. "yobfield:_location,_description,_summary " .
  32. "weekdayformat:de-long,de-short,en-long,en-short " .
  33. $readingFnAttributes;
  34. }
  35. sub CALVIEW_Define($$){
  36. my ( $hash, $def ) = @_;
  37. my @a = split( "[ \t][ \t]*", $def );
  38. return "\"set CALVIEW\" needs at least an argument" if ( @a < 2 );
  39. my $name = $a[0];
  40. my $inter = 43200;
  41. $inter= $a[4] if($#a==4);
  42. my $modes = $a[3];
  43. my @calendars = split( ",", $a[2] );
  44. $hash->{NAME} = $name;
  45. my $calcounter = 1;
  46. foreach my $calender (@calendars)
  47. {
  48. return "invalid Calendername \"$calender\", define it first" if((devspec2array("NAME=$calender")) != 1 );
  49. }
  50. $hash->{KALENDER} = $a[2];
  51. $hash->{STATE} = "Initialized";
  52. $hash->{INTERVAL} = $inter;
  53. $modes = "next" if (!defined($modes));
  54. if ( $modes =~ /^\d+$/) {
  55. if($modes == 1) {$attr{$name}{modes} = "next";}
  56. elsif($modes == 0){$attr{$name}{modes} = "next";}
  57. elsif($modes == 2){$attr{$name}{modes} = "next";}
  58. elsif($modes == 3){$attr{$name}{modes} = "next";}
  59. }
  60. elsif($modes eq "next"){$attr{$name}{modes} = "next";}
  61. else {return "invalid mode \"$modes\", use 0,1,2 or next!"}
  62. InternalTimer(gettimeofday()+2, "CALVIEW_GetUpdate", $hash, 0);
  63. return undef;
  64. }
  65. sub CALVIEW_Undef($$){
  66. my ( $hash, $arg ) = @_;
  67. #DevIo_CloseDev($hash);
  68. RemoveInternalTimer($hash);
  69. return undef;
  70. }
  71. sub CALVIEW_Set($@){
  72. my ( $hash, @a ) = @_;
  73. return "\"set CALVIEW\" needs at least an argument" if ( @a < 2 );
  74. return "\"set CALVIEW\" Unknown argument $a[1], choose one of update" if($a[1] eq '?');
  75. my $name = shift @a;
  76. my $opt = shift @a;
  77. my $arg = join("", @a);
  78. if($opt eq "update"){CALVIEW_GetUpdate($hash);}
  79. }
  80. sub CALVIEW_GetUpdate($){
  81. my ($hash) = @_;
  82. my $name = $hash->{NAME};
  83. #cleanup readings
  84. delete ($hash->{READINGS});
  85. # new timer
  86. RemoveInternalTimer($hash);
  87. InternalTimer(gettimeofday()+$hash->{INTERVAL}, "CALVIEW_GetUpdate", $hash, 1);
  88. readingsBeginUpdate($hash); #start update
  89. my @termine = getsummery($hash);
  90. my $max = AttrVal($name,"maxreadings",0);
  91. if(defined $max && $max =~ /^[+-]?\d+$/){if($max > 190){$max = 190;}}
  92. else{my $max = 190;}
  93. my $counter = 1;
  94. my $samedatecounter = 2;
  95. my $lastterm;
  96. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  97. $year += 1900; $mon += 1;
  98. my $date = sprintf('%02d.%02d.%04d', $mday, $mon, $year);
  99. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time + 86400);
  100. $year += 1900; $mon += 1;
  101. my $datenext = sprintf('%02d.%02d.%04d', $mday, $mon, $year);
  102. my @termineNew;
  103. my @tempstart;
  104. my @bts;
  105. my @tempend;
  106. my $isostarttime;
  107. my $isoendtime;
  108. my ($D,$M,$Y);
  109. my ($eD,$eM,$eY);
  110. my @arrWeekdayDe = ("Sonntag","Montag", "Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
  111. my @arrWeekdayDeShrt = ("So","Mo", "Di","Mi","Do","Fr","Sa");
  112. my @arrWeekdayEn = ("Sunday","Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday");
  113. my @arrWeekdayEnShrt = ("Sun","Mon", "Tue","Wed","Thu","Fri","Sat");
  114. foreach my $item (@termine ){
  115. #start datum und zeit behandeln
  116. if( defined($item->[0])&& length($item->[0]) > 0) {
  117. @tempstart=split(/\s+/,$item->[0]);
  118. ($D,$M,$Y)=split(/\./,$tempstart[0]);
  119. @bts=str2time($M."/".$D."/".$Y." ".$tempstart[1]);
  120. $isostarttime = $Y."-".$M."-".$D."T".$tempstart[1];
  121. }
  122. else {$item->[0] = "no startdate"}
  123. #end datum und zeit behandeln
  124. if( defined($item->[2])&& length($item->[2]) > 0) {
  125. @tempend=split(/\s+/,$item->[2]);
  126. ($eD,$eM,$eY)=split(/\./,$tempend[0]);
  127. $isoendtime = $eY."-".$eM."-".$eD."T".$tempend[1];
  128. }
  129. else {$item->[2] = "no enddate"}
  130. #replace the "\," with ","
  131. if(length($item->[1]) > 0){ $item->[1] =~ s/\\,/,/g; }
  132. if( defined($item->[4]) && length($item->[4]) > 0){ $item->[4] =~ s/\\,/,/g; } elsif( !defined($item->[4])){$item->[4] = " ";}
  133. if( defined($item->[5]) && length($item->[5]) > 0){ $item->[5] =~ s/\\,/,/g; } elsif( !defined($item->[5])){$item->[5] = " ";}
  134. #berechnen verbleibender tage bis zum termin
  135. my $eventDate = fhemTimeLocal(0,0,0,$D,$M-1,$Y-1900);
  136. my $daysleft = floor(($eventDate - time) / 60 / 60 / 24 + 1);
  137. my $daysleft_long;
  138. #my $weekday = Day_of_Week($Y, $M, $D);
  139. my ($tsec,$tmin,$thour,$tmday,$tmon,$year,$weekday,$tyday,$tisdst) = localtime(time + (86400 * $daysleft));
  140. #"weekdayname:de-long,de-short,en-long,en-short " .
  141. my $weekdayname;
  142. if ( AttrVal($name,"weekdayformat","de-long") eq "de-short") {$weekdayname = $arrWeekdayDeShrt[$weekday]}
  143. elsif (AttrVal($name,"weekdayformat","de-long") eq "en-long") {$weekdayname = $arrWeekdayEn[$weekday]}
  144. elsif (AttrVal($name,"weekdayformat","de-long") eq "en-short") {$weekdayname = $arrWeekdayEnShrt[$weekday]}
  145. else {$weekdayname = $arrWeekdayDe[$weekday]}
  146. if( !defined($item->[6])){$item->[6] = " ";}
  147. if( $daysleft == 0){$daysleft_long = "heute";}
  148. elsif( $daysleft == 1){$daysleft_long = "morgen";}
  149. else{$daysleft_long = "in ".$daysleft." Tagen";}
  150. push @termineNew,{
  151. bdate => $tempstart[0],
  152. btime => $tempstart[1],
  153. bdatetimeiso => $isostarttime,
  154. daysleft => $daysleft,
  155. daysleftLong => $daysleft_long,
  156. summary => $item->[1],
  157. source => $item->[3],
  158. location => $item->[4],
  159. description => $item->[5],
  160. categories => $item->[6],
  161. edate => $tempend[0],
  162. etime => $tempend[1],
  163. edatetimeiso => $isoendtime,
  164. btimestamp => $bts[0],
  165. mode => $item->[7],
  166. weekday => $weekday,
  167. weekdayname => $weekdayname};
  168. }
  169. my $todaycounter = 1;
  170. my $tomorrowcounter = 1;
  171. my $readingstyle = AttrVal($name,"oldStyledReadings",0);
  172. my $isbday = AttrVal($name,"isbirthday",0);
  173. my $yobfield = AttrVal($name,"yobfield","_description");
  174. my $filterSummary = AttrVal($name,"filterSummary",".*:.*");
  175. my @arrFilters = split(',' , $filterSummary );
  176. my $sourceColor = AttrVal($name,"sourcecolor","");
  177. my @arrSourceColors = split(',' , $sourceColor );
  178. # sort the array by btimestamp
  179. my @sdata = map $_->[0],
  180. sort { $a->[1][0] <=> $b->[1][0] }
  181. map [$_, [$_->{btimestamp}]], @termineNew;
  182. if($readingstyle == 0){
  183. my $age = 0;
  184. my @termyear;
  185. my $validterm = 0;
  186. for my $termin (@sdata){
  187. my $termcolor="white";
  188. #if($termin->{summary} =~ /$filterSummary/ ){
  189. foreach my $filter (@arrFilters){
  190. my @arrFilter= split(':' , $filter);
  191. my $sourceFilter = $arrFilter[0];
  192. my $summaryFilter = $arrFilter[1];
  193. if( $termin->{source} =~ /$sourceFilter/i && $termin->{summary} =~ /$summaryFilter/i ){ $validterm =1;}
  194. };
  195. foreach my $color (@arrSourceColors){
  196. my @arrSourceColor = split(':' , $color);
  197. my $sourceName = $arrSourceColor[0];
  198. my $sourceColor = $arrSourceColor[1];
  199. if( $termin->{source} =~ /$sourceName/i ){ $termcolor = $sourceColor;}
  200. };
  201. if ($validterm ==1){
  202. #alter berechnen wenn attribut gesetzt ist. alter wird aus "jahr des termins" - "geburtsjahr aus location oder description" errechnet
  203. if($isbday == 1 ){
  204. @termyear = split(/\./,$termin->{bdate});
  205. if($yobfield eq "_location" && defined($termin->{location}) && length($termin->{location}) > 0 && $termin->{location} =~ /(\d{4})/) { my ($byear) = $termin->{location} =~ /(\d{4})/ ; $age = $termyear[2] - $byear;}
  206. elsif($yobfield eq "_description" && defined($termin->{description})&& length($termin->{description}) > 0 && $termin->{description} =~ /(\d{4})/) { my ($byear) = $termin->{description} =~ /(\d{4})/ ; $age = $termyear[2] - $byear;}
  207. elsif($yobfield eq "_summary" && defined($termin->{summary}) && length($termin->{summary}) > 0 && $termin->{summary} =~ /(\d{4})/ ) { my ($byear) = $termin->{summary} =~ /(\d{4})/ ; $age = $termyear[2] - $byear;}
  208. else {$age = " "}
  209. }
  210. my $timeshort = "";
  211. my($startday,$startmonth,$startyear)=split(/\./,$termin->{bdate});
  212. my($endday,$endmonth,$endyear)=split(/\./,$termin->{edate});
  213. my $nextday = $startday + 1;
  214. $nextday = sprintf ('%02d', $nextday);
  215. Log3 $name , 5, "CALVIEW $name - nextday = $nextday , endday = $endday , startday = $startday , btime ".$termin->{btime}." , etime ".$termin->{etime}."";
  216. if( $endday eq $nextday && $termin->{btime} eq $termin->{etime} ){ $timeshort = AttrVal($name,"fulldaytext","ganztägig"); }
  217. else {
  218. if(AttrVal($name,"timeshort","0") eq 0) {$timeshort = $termin->{btime}." - ".$termin->{etime}; }
  219. elsif(AttrVal($name,"timeshort","0") eq 1) {
  220. my $tmps = substr $termin->{btime},0,5 ;
  221. my $tmpe = substr $termin->{etime},0,5 ;
  222. $timeshort = $tmps." - ".$tmpe ;
  223. }
  224. }
  225. #standard reading t_[3steliger counter] anlegen
  226. if($isbday == 1 ){ readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_age", $age);}
  227. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdate", $termin->{bdate});
  228. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_btime", $termin->{btime});
  229. if(AttrVal($name,"datestyle","_description") eq "ISO8601"){readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdatetimeiso", $termin->{bdatetimeiso});readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edatetimeiso", $termin->{edatetimeiso});}
  230. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_daysleft", $termin->{daysleft});
  231. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_daysleftLong", $termin->{daysleftLong});
  232. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary});
  233. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_source", $termin->{source});
  234. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_sourcecolor", $termcolor);
  235. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_location", $termin->{location});
  236. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_description", $termin->{description});
  237. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_categories", $termin->{categories});
  238. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edate", $termin->{edate});
  239. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_etime", $termin->{etime});
  240. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_mode", $termin->{mode});
  241. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_timeshort", $timeshort );
  242. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_weekday", $termin->{weekday} );
  243. readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_weekdayname", $termin->{weekdayname} );
  244. #wenn termin heute today readings anlegen
  245. if ($date eq $termin->{bdate} ){
  246. if($isbday == 1 ){ readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_age", $age);}
  247. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_bdate", "heute");
  248. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime});
  249. if(AttrVal($name,"datestyle","_description") eq "ISO8601"){readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_bdatetimeiso", $termin->{bdatetimeiso});readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edatetimiso", $termin->{edatetimeiso});}
  250. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $counter)."_daysleft", $termin->{daysleft});
  251. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $counter)."_daysleftLong", $termin->{daysleftLong});
  252. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary});
  253. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_source", $termin->{source});
  254. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_sourcecolor", $termcolor);
  255. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_location", $termin->{location});
  256. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_description", $termin->{description});
  257. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_categories", $termin->{categories});
  258. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edate", $termin->{edate});
  259. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime});
  260. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
  261. readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_timeshort", $timeshort );
  262. $todaycounter ++;
  263. }
  264. #wenn termin morgen tomorrow readings anlegen
  265. elsif ($datenext eq $termin->{bdate}){
  266. if($isbday == 1 ){readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_age", $age);}
  267. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen");
  268. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", $termin->{btime});
  269. if(AttrVal($name,"datestyle","_description") eq "ISO8601"){readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdatetimeiso", $termin->{bdatetimeiso});readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edatetimeiso", $termin->{edatetimeiso});}
  270. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_daysleft", $termin->{daysleft});
  271. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_daysleftLong", $termin->{daysleftLong});
  272. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary});
  273. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_source", $termin->{source});
  274. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_sourcecolor", $termcolor);
  275. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_location", $termin->{location});
  276. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_description", $termin->{description});
  277. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_categories", $termin->{categories});
  278. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edate", $termin->{edate});
  279. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_etime", $termin->{etime});
  280. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
  281. readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_timeshort", $timeshort );
  282. $tomorrowcounter++;
  283. }
  284. $endday = '';
  285. $nextday ='';
  286. last if ($counter++ == $max);
  287. }
  288. $validterm = 0;
  289. $age = " ";
  290. };
  291. readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1));
  292. readingsBulkUpdate($hash, "c-term", $counter-1);
  293. readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
  294. readingsBulkUpdate($hash, "c-today", $todaycounter-1);
  295. }
  296. else{
  297. my $lastreadingname = "";
  298. my $doppelcounter = 2;
  299. my $inverteddate;
  300. for my $termin (@sdata){ #termin als reading term_[3steliger counter]
  301. my @tempvar = split /\./, $termin->{bdate};
  302. $inverteddate = "$tempvar[2].$tempvar[1].$tempvar[0]";
  303. if($lastreadingname eq $termin->{bdate}."-".$termin->{btime}){ readingsBulkUpdate($hash, $inverteddate."-".$termin->{btime}."-$doppelcounter" , $termin->{summary}); $doppelcounter ++;}
  304. else{readingsBulkUpdate($hash, $inverteddate."-".$termin->{btime} , $termin->{summary}); $doppelcounter = 2;}
  305. $lastreadingname = $termin->{bdate}."-".$termin->{btime};
  306. last if ($counter++ == $max);
  307. };
  308. for my $termin (@sdata){ #check ob temin heute
  309. if ($date eq $termin->{bdate}){readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter).$termin->{btime}, $termin->{summary});$todaycounter ++;}
  310. #check ob termin morgen
  311. elsif ($datenext eq $termin->{bdate}){readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter).$termin->{btime}, $termin->{summary});$tomorrowcounter++;}
  312. };
  313. }
  314. readingsEndUpdate($hash,1); #end update
  315. }
  316. sub getsummery($)
  317. {
  318. my ($hash) = @_;
  319. my @terminliste ;
  320. my $name = $hash->{NAME};
  321. my @calendernamen = split( ",", $hash->{KALENDER});
  322. my $modi = $attr{$name}{modes};
  323. my @modes = split(/,/,$modi);
  324. foreach my $calendername (@calendernamen){
  325. my $all = CallFn($calendername, "GetFn", $defs{$calendername},(" ","uid", "next"));
  326. my @termine=split(/\n/,$all);
  327. foreach my $uid (@termine){
  328. #für jedes event die einzelnen infos holen
  329. my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid));
  330. my @starts = split(/\n/,$tmpstarts);
  331. my $tmpends = CallFn($calendername, "GetFn", $defs{$calendername},(" ","end", $uid));
  332. my @ends = split(/\n/,$tmpends);
  333. my $tmpsummarys = CallFn($calendername, "GetFn", $defs{$calendername},(" ","summary", $uid));
  334. my @summarys = split(/\n/,$tmpsummarys);
  335. my $tmplocations = CallFn($calendername, "GetFn", $defs{$calendername},(" ","location", $uid));
  336. my @locations = split(/\n/,$tmplocations);
  337. my $tmpdescriptions = CallFn($calendername, "GetFn", $defs{$calendername},(" ","description", $uid));
  338. my @description = split(/\n/,$tmpdescriptions);
  339. my $tmpcategories = CallFn($calendername, "GetFn", $defs{$calendername},(" ","categories", $uid));
  340. my @categories = split(/\n/,$tmpcategories);
  341. for(my $i = 1; $i <= (scalar(@starts)); $i++) {
  342. my $internali = $i-1;
  343. my $terminstart = $starts[$internali];
  344. my $termintext = $summarys[$internali];
  345. my $terminend = $ends[$internali];
  346. my $terminort = $locations[$internali];
  347. my $termindescription = $description[$internali];
  348. my $termincategories = $categories[$internali];
  349. push(@terminliste, [$terminstart, $termintext, $terminend, $calendername, $terminort, $termindescription, $termincategories, "next"]);
  350. }
  351. };
  352. };
  353. return @terminliste;
  354. }
  355. sub CALVIEW_Notify($$)
  356. {
  357. my ($hash, $extDevHash) = @_;
  358. my $name = $hash->{NAME}; # name calview device
  359. my $extDevName = $extDevHash->{NAME}; # name externes device
  360. my @calendernams = split( ",", $hash->{KALENDER});
  361. my $event;
  362. return "" if(IsDisabled($name)); # wenn attr disabled keine reaktion
  363. foreach my $calendar (@calendernams){
  364. if ($extDevName eq $calendar) {
  365. foreach $event (@{$extDevHash->{CHANGED}}) {
  366. if ($event eq "triggered") {
  367. Log3 $name , 3, "CALVIEW $name - CALENDAR:$extDevName triggered, updating CALVIEW $name ...";
  368. CALVIEW_GetUpdate($hash);
  369. }
  370. }
  371. }
  372. }
  373. }
  374. 1;
  375. =pod
  376. =item device
  377. =item summary provides calendar events in a readable form
  378. =begin html
  379. <a name="CALVIEW"></a>
  380. <h3>CALVIEW</h3>
  381. <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>
  382. <ul>Actually the module supports only the "get <> next" function of the CALENDAR-Modul.</ul>
  383. <b>Define</b>
  384. <ul><code>define &lt;Name&gt; CALVIEW &lt;calendarname(s) separate with ','&gt; &lt;next&gt; &lt;updateintervall in sec (default 43200)&gt;</code></ul>
  385. <ul><code>define myView CALVIEW Googlecalendar next</code></ul>
  386. <ul><code>define myView CALVIEW Googlecalendar,holiday next 900</code></ul>
  387. <ul>- setting the update interval is not needed normally because every calendar update triggers a caview update</ul>
  388. <a name="CALVIEW set"></a>
  389. <b>Set</b>
  390. <ul><code>set &lt;Name&gt; update</code></ul>
  391. <ul><code>set myView update</code></ul>
  392. <ul>this will manually update all readings from the given CALENDAR Devices</ul>
  393. <b>Attribute</b>
  394. <li>datestyle<br>
  395. not set - the default, disables displaying readings bdatetimeiso / edatetimeiso<br>
  396. ISO8601 - enables readings bdatetimeiso / edatetimeiso (start and end time of term ISO8601 formated like 2017-02-27T00:00:00)
  397. </li><br>
  398. <li>disable<br>
  399. 0 / not set - internal notify function enabled (default) <br>
  400. 1 - disable the internal notify-function of CALVIEW wich is triggered when one of the given CALENDAR devices has updated
  401. </li><br>filterSummary
  402. <li>filterSummary &lt;filtersouce&gt;:&lt;filtersummary&gt;[,&lt;filtersouce&gt;:&lt;filtersummary&gt;]<br>
  403. not set - displays all terms (default .*:.*) <br>
  404. &lt;filtersouce&gt;:&lt;filtersummary&gt;[,&lt;filtersouce&gt;:&lt;filtersummary&gt;] - CALVIEW will display term where summary matches the &lt;filtersouce&gt;:&lt;filtersummary&gt;, several filters must be separated by comma (,)
  405. e.g.: filterSummary Kalender_Abfall:Leichtverpackungen,Kalender_Abfall:Bioabfall
  406. filterSummary Kalender_Abfall:Leichtverpackungen,Kalender_Feiertage:.*,Kalender_Christian:.*,Kalender_Geburtstage:.*
  407. </li><br>
  408. <li>fulldaytext [text]<br>
  409. this text will be displayed in _timeshort reading for fullday terms (default ganztägig)
  410. </li><br>
  411. <li>isbirthday<br>
  412. 0 / not set - no age calculation (default) <br>
  413. 1 - age calculation active. The module calculates the age with year given in description or location (see att yobfield).
  414. </li><br>
  415. <li>maxreadings<br>
  416. defines the number of max term as readings
  417. </li><br>
  418. <li>modes<br>
  419. here the CALENDAR modes can be selected , to be displayed in the view
  420. </li><br>
  421. <li>oldStyledReadings<br>
  422. 0 the default style of readings <br>
  423. 1 readings look like "2015.06.21-00:00" with value "Start of Summer"
  424. </li><br>
  425. <li>sourcecolor &lt;calendername&gt;:&lt;colorcode&gt;[,&lt;calendername&gt;:&lt;colorcode&gt;]<br>
  426. here you can define the termcolor for terms from your calendars for the calview tabletui widget, several calendar:color pairs must be separated by comma
  427. </li><br>
  428. <li>timeshort<br>
  429. 0 time in _timeshort readings formated 00:00:00 <br>
  430. 1 time in _timeshort readings formated 00:00
  431. </li><br>
  432. <li>yobfield<br>
  433. _description - (default) year of birth will be read from term description <br>
  434. _location - year of birth will be read from term location <br>
  435. _summary - year of birth will be read from summary (uses the first sequence of 4 digits in the string)
  436. </li><br>
  437. <li>weekdayformat<br>
  438. formats the name of the reading weekdayname <br>
  439. - de-long - (default) german, long name like Dienstag <br>
  440. - de-short - german, short name like Di <br>
  441. - en-long - english, long name like Tuesday <br>
  442. - en-short - english, short name like Tue <br>
  443. </li><br>
  444. =end html
  445. =begin html_DE
  446. <a name="CALVIEW"></a>
  447. <h3>CALVIEW</h3>
  448. <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>
  449. <ul>Aktuell wird nur die "get <> next" Funktion vom CALENDAR untertstützt.</ul>
  450. <b>Define</b>
  451. <ul><code>define &lt;Name&gt; CALVIEW &lt;Kalendername(n) getrennt durch ','&gt; &lt;next&gt; &lt;updateintervall in sek (default 43200)&gt;</code></ul>
  452. <ul><code>define myView CALVIEW Googlekalender next</code></ul>
  453. <ul><code>define myView CALVIEW Googlekalender,holiday next 900</code></ul>
  454. <ul>- die Einstellung des Aktualisierungsintervalls wird normalerweise nicht benötigt, da jede Kalenderaktualisierung ein Caview-Update auslöst</ul>
  455. <a name="CALVIEW set"></a>
  456. <b>Set</b>
  457. <ul>update readings:</ul>
  458. <ul><code>set &lt;Name&gt; update</code></ul>
  459. <ul><code>set myView update</code></ul><br>
  460. <b>Attributes</b>
  461. <li>datestyle<br>
  462. nicht gesetzt - Standard, Readings bdatetimeiso / edatetimeiso werden nicht gezeigt<br>
  463. ISO8601 - aktiviert die readings bdatetimeiso / edatetimeiso (zeigen Terminstart und Ende im ISO8601 Format zB. 2017-02-27T00:00:00)
  464. </li><br>
  465. <li>disable<br>
  466. 0 / nicht gesetzt - aktiviert die interne Notify-Funktion (Standard) <br>
  467. 1 - deaktiviert die interne Notify-Funktion welche ausgelöst wird wenn sich einer der Kalender aktualisiert hat
  468. </li><br>
  469. <li>filterSummary &lt;filtersouce&gt;:&lt;filtersummary&gt;[,&lt;filtersouce&gt;:&lt;filtersummary&gt;]<br>
  470. not set - zeigt alle Termine (Standard) <br>
  471. &lt;filtersouce&gt;:&lt;filtersummary&gt;[,&lt;filtersouce&gt;:&lt;filtersummary&gt;] - CALVIEW filtert Termine die &lt;filtersquelle&gt;:&lt;filtertitel&gt; entsprechen, mehrere Filter sind durch Komma (,) zu trennen.
  472. zb.: filterSummary Kalender_Abfall:Leichtverpackungen,Kalender_Abfall:Bioabfall
  473. filterSummary Kalender_Abfall:Leichtverpackungen,Kalender_Feiertage:.*,Kalender_Christian:.*,Kalender_Geburtstage:.*
  474. </li><br>
  475. <li>fulldaytext [text]<br>
  476. Dieser Text wird bei ganztägigen Terminen in _timeshort Readings genutzt (default ganztägig)
  477. </li><br>
  478. <li>isbirthday<br>
  479. 0 / nicht gesetzt - keine Altersberechnung (Standard) <br>
  480. 1 - aktiviert die Altersberechnung im Modul. Das Alter wird aus der in der Terminbeschreibung (description) angegebenen Jahreszahl (Geburtsjahr) berechnet. (siehe Attribut yobfield)
  481. </li><br>
  482. <li>maxreadings<br>
  483. bestimmt die Anzahl der Termine als Readings
  484. </li><br>
  485. <li>modes<br>
  486. hier können die CALENDAR modi gewählt werden, welche in der View angezeigt werden sollen
  487. </li><br>
  488. <li>oldStyledReadings<br>
  489. 0 die Standarddarstellung für Readings <br>
  490. 1 aktiviert die Termindarstellung im "alten" Format "2015.06.21-00:00" mit Wert "Start of Summer"
  491. </li><br>
  492. <li>sourcecolor &lt;calendername&gt;:&lt;colorcode&gt;[,&lt;calendername&gt;:&lt;colorcode&gt;]<br>
  493. Hier kann man die Farben für die einzelnen Calendar definieren die dann zb im Tabletui widget genutzt werden kann.
  494. Die calendar:color Elemente sind durch Komma zu trennen.
  495. So kann man zb die google-Kalender Farben auch in der TUI für eine gewohnte Anzeige nutzen.
  496. </li><br>
  497. <li>timeshort<br>
  498. 0 Zeit in _timeshort Readings im Format 00:00:00 - 00:00:00 <br>
  499. 1 Zeit in _timeshort Readings im Format 00:00 - 00:00
  500. </li><br>
  501. <li>yobfield<br>
  502. _description - (der Standard) Geburtsjahr wird aus der Terminbechreibung gelesen <br>
  503. _location - Geburtsjahr wird aus dem Terminort gelesen <br>
  504. _summary - Geburtsjahr wird aus dem Termintiele gelesen (verwendet wird die erste folge von 4 Ziffern im String))
  505. </li><br>
  506. <li>weekdayformat<br>
  507. formatiert den Namen im Reading weekdayname <br>
  508. - de-long - (default) Deutsch, lang zb Dienstag <br>
  509. - de-short - Deutsch, kurze zb Di <br>
  510. - en-long - English, lang zb Tuesday <br>
  511. - en-short - English, kurze zb Tue <br>
  512. </li><br>
  513. =end html_DE
  514. =cut