From 3b743b68ed24ce759b4fb28f118ca911edd7a727 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sat, 1 Aug 2020 07:54:26 +0000 Subject: [PATCH] 60_Watches: add attr timeAsReading -> write into reading 'currtime' if time is displayed, git-svn-id: https://svn.fhem.de/fhem/trunk@22507 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/60_Watches.pm | 146 +++++++++++++++++++++++++++++++++------- 2 files changed, 125 insertions(+), 23 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 8d1ccba40..77686af20 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 60_Watches: attr timeAsReading -> write displayed time to reading + currtime - feature: 48_BlinkCamera: Support for new API on login / new V3 as default - bugfix: 93_DbRep: crash if delEntries is startet without any time limits, Forum:#113202 diff --git a/fhem/FHEM/60_Watches.pm b/fhem/FHEM/60_Watches.pm index 147a818a1..33ef78c5a 100644 --- a/fhem/FHEM/60_Watches.pm +++ b/fhem/FHEM/60_Watches.pm @@ -50,6 +50,7 @@ BEGIN { readingsBeginUpdate readingsBulkUpdate readingsEndUpdate + readingFnAttributes readingsSingleUpdate sortTopicNum ) @@ -71,6 +72,8 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "0.26.0" => "01.08.2020 add attr timeAsReading -> write into reading 'currtime' if time is displayed, ". + "add \$readingFnAttributes, set release_status to stable ", "0.25.0" => "03.06.2020 set reading 'stoptime' in type 'stopwatch' ", "0.24.0" => "26.05.2020 entry of countDownInit can be in format ", "0.23.2" => "20.05.2020 english commandref ", @@ -145,13 +148,15 @@ sub Initialize { "stationHourHand:Bar,Pointed,Swiss,Vienna ". "stationStrokeDial:GermanHour,German,Austria,Swiss,Vienna,No ". "stationBody:Round,SmallWhite,RoundGreen,Square,Vienna,No ". + "timeAsReading:1,0 ". "timeSource:server,client ". - ""; + $readingFnAttributes;; $hash->{FW_hideDisplayName} = 1; # Forum 88667 # $hash->{FW_addDetailToSummary} = 1; $hash->{FW_atPageEnd} = 1; # wenn 1 -> kein Longpoll ohne informid in HTML-Tag - + # $hash->{FW_deviceOverview} = 1; + eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; ## no critic 'eval' # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html) return; @@ -302,7 +307,7 @@ return; ############################################################################## # Attributfunktion ############################################################################## -sub Attr { ## no critic 'complexity' +sub Attr { ## no critic 'complexity' my ($cmd,$name,$aName,$aVal) = @_; my $hash = $defs{$name}; my ($do,$val); @@ -333,6 +338,17 @@ sub Attr { ## no critic readingsSingleUpdate($hash, "state", $val, 1); } + if ($aName eq "timeAsReading") { + if($cmd eq "set") { + $do = $aVal; + } + $do = 0 if($cmd eq "del"); + + if(!$do) { + delReadings ($name, "currtime"); + } + } + if ($aName eq "digitalDisplayPattern") { if($cmd eq "set") { $do = $aVal; @@ -438,6 +454,7 @@ sub digitalWatch { my $abdist = AttrVal($d, "digitalBorderDistance", 8); my $hattr = AttrVal($d, "htmlattr", "width='150' height='50'"); my $tsou = AttrVal($d, "timeSource", "client"); + my $showct = AttrVal($d, "timeAsReading", 0); my $deftxt = " "; my $rdtt = ReadingsVal ($d, "displayTextTicker", "off"); @@ -491,11 +508,12 @@ sub digitalWatch { var minutes_$d; var seconds_$d; var startDate_$d; - var ddt_$d; + var ddt_$d; var almtime0_$d = '$alarm'; // Alarmzeit initialisieren var digitxt_$d = '$deftxt'; // default Digitaltext initialisieren var tticker_$d = '$rdtt'; // Tickereinstellung initialisieren var zmodulo_$d = 0; // Hilfszähler + var showCurrTime_$d = '$showct'; // Reading currtime schreiben oder nicht var distBorderright_$d = '$bdist'; // Abstand zum rechten Rand var distBorderleft_$d = '$bdist'; // Abstand zum linken Rand var allowSetStopTime; // erlaube / verbiete Setzen Reading stoptime @@ -1096,6 +1114,16 @@ sub digitalWatch { localStorage.setItem('lastalmtime_'+dev, lastalmtime); } + // Reading currtime setzen + function setrcurrtime (h_$d, m_$d, s_$d) { + var time_$d = buildtime (h_$d, m_$d, s_$d); + if (modulo2_$d != zmodulo_$d && showCurrTime_$d != 0 && time_$d != 'NaN:NaN:NaN') { + command = '{ CommandSetReading(undef, "$d currtime '+time_$d+'") }'; + url_$d = makeCommand(command); + \$.get(url_$d); + } + } + // Check ob Alarm ausgelöst werden soll und ggf. Alarmevent triggern function checkAndDoAlm_$d (dev, acttime, almtime) { lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden @@ -1125,7 +1153,7 @@ sub digitalWatch { var watchkind_$d = '$addp'; var cycletime = new Date(); var cycleseconds = cycletime.getSeconds(); - modulo2_$d = cycleseconds % 2; // Taktung für Readingabruf (Serverauslastung reduzieren) + modulo2_$d = cycleseconds % 2; // Taktung für Reading lesen/schreiben (Serverauslastung reduzieren) if (watchkind_$d == 'watch') { if (modulo2_$d != zmodulo_$d) { @@ -1153,10 +1181,10 @@ sub digitalWatch { time_$d = new Date(ct_$d); } else { - time_$d = new Date(); // Clientzeit + time_$d = new Date(); // Clientzeit } - if (typeof ct_$d === 'undefined') { // wenn Zeit noch undef mit lokaler Zeit initialisieren -> springen Zeiger verhindern + if (typeof ct_$d === 'undefined') { // wenn Zeit noch undef mit lokaler Zeit initialisieren -> springen Zeiger verhindern time_$d = new Date(); } else { time_$d = new Date(ct_$d); @@ -1171,20 +1199,24 @@ sub digitalWatch { ((seconds_$d < 10) ? '0' : '') + seconds_$d; if (acttime_$d == '00:00:00') { - localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen zum Tageswechsel + localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen zum Tageswechsel } checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d); + + setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen } if (watchkind_$d == 'staticwatch') { var hours_$d = '$h'; var minutes_$d = '$m'; var seconds_$d = '$s'; + + setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen } if (watchkind_$d == 'stopwatch') { - command = '{ReadingsVal("$d","state","")}'; // state Reading lesen + command = '{ReadingsVal("$d","state","")}'; // state Reading lesen url_$d = makeCommand(command); \$.get( url_$d, function (data) { state_$d = data.replace(/\\n/g, ''); @@ -1243,6 +1275,8 @@ sub digitalWatch { checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN); + + setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen } if (state_$d == 'stopped') { @@ -1356,6 +1390,8 @@ sub digitalWatch { checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN); } + + setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen } if (state_$d == 'stopped') { @@ -1408,7 +1444,7 @@ sub digitalWatch { } if (modulo2_$d != zmodulo_$d) { - command = '{ReadingsVal("$d","displayText", "$deftxt")}'; // Text dynamisch aus Reading lesen + command = '{ReadingsVal("$d","displayText", "$deftxt")}'; // Text dynamisch aus Reading lesen url_$d = makeCommand(command); \$.get( url_$d, function (data) { digitxt_$d = data.replace(/\\n/g, ''); @@ -1469,6 +1505,7 @@ sub stationWatch { my $sbody = AttrVal ($d, "stationBody", "Round"). "Body"; my $hattr = AttrVal ($d, "htmlattr", "width='150' height='150'"); my $tsou = AttrVal ($d, "timeSource", "client"); + my $showct = AttrVal ($d, "timeAsReading", 0); my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc"); @@ -1481,9 +1518,10 @@ sub stationWatch {