2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

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
This commit is contained in:
nasseeder1 2020-08-01 07:54:26 +00:00
parent 1624995695
commit 3b743b68ed
2 changed files with 125 additions and 23 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # 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 - feature: 48_BlinkCamera: Support for new API on login / new V3 as default
- bugfix: 93_DbRep: crash if delEntries is startet without any - bugfix: 93_DbRep: crash if delEntries is startet without any
time limits, Forum:#113202 time limits, Forum:#113202

View File

@ -50,6 +50,7 @@ BEGIN {
readingsBeginUpdate readingsBeginUpdate
readingsBulkUpdate readingsBulkUpdate
readingsEndUpdate readingsEndUpdate
readingFnAttributes
readingsSingleUpdate readingsSingleUpdate
sortTopicNum sortTopicNum
) )
@ -71,6 +72,8 @@ BEGIN {
# Versions History intern # Versions History intern
my %vNotesIntern = ( 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.25.0" => "03.06.2020 set reading 'stoptime' in type 'stopwatch' ",
"0.24.0" => "26.05.2020 entry of countDownInit can be in format <seconds> ", "0.24.0" => "26.05.2020 entry of countDownInit can be in format <seconds> ",
"0.23.2" => "20.05.2020 english commandref ", "0.23.2" => "20.05.2020 english commandref ",
@ -145,12 +148,14 @@ sub Initialize {
"stationHourHand:Bar,Pointed,Swiss,Vienna ". "stationHourHand:Bar,Pointed,Swiss,Vienna ".
"stationStrokeDial:GermanHour,German,Austria,Swiss,Vienna,No ". "stationStrokeDial:GermanHour,German,Austria,Swiss,Vienna,No ".
"stationBody:Round,SmallWhite,RoundGreen,Square,Vienna,No ". "stationBody:Round,SmallWhite,RoundGreen,Square,Vienna,No ".
"timeAsReading:1,0 ".
"timeSource:server,client ". "timeSource:server,client ".
""; $readingFnAttributes;;
$hash->{FW_hideDisplayName} = 1; # Forum 88667 $hash->{FW_hideDisplayName} = 1; # Forum 88667
# $hash->{FW_addDetailToSummary} = 1; # $hash->{FW_addDetailToSummary} = 1;
$hash->{FW_atPageEnd} = 1; # wenn 1 -> kein Longpoll ohne informid in HTML-Tag $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) eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; ## no critic 'eval' # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html)
@ -333,6 +338,17 @@ sub Attr { ## no critic
readingsSingleUpdate($hash, "state", $val, 1); 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 ($aName eq "digitalDisplayPattern") {
if($cmd eq "set") { if($cmd eq "set") {
$do = $aVal; $do = $aVal;
@ -438,6 +454,7 @@ sub digitalWatch {
my $abdist = AttrVal($d, "digitalBorderDistance", 8); my $abdist = AttrVal($d, "digitalBorderDistance", 8);
my $hattr = AttrVal($d, "htmlattr", "width='150' height='50'"); my $hattr = AttrVal($d, "htmlattr", "width='150' height='50'");
my $tsou = AttrVal($d, "timeSource", "client"); my $tsou = AttrVal($d, "timeSource", "client");
my $showct = AttrVal($d, "timeAsReading", 0);
my $deftxt = " "; my $deftxt = " ";
my $rdtt = ReadingsVal ($d, "displayTextTicker", "off"); my $rdtt = ReadingsVal ($d, "displayTextTicker", "off");
@ -496,6 +513,7 @@ sub digitalWatch {
var digitxt_$d = '$deftxt'; // default Digitaltext initialisieren var digitxt_$d = '$deftxt'; // default Digitaltext initialisieren
var tticker_$d = '$rdtt'; // Tickereinstellung initialisieren var tticker_$d = '$rdtt'; // Tickereinstellung initialisieren
var zmodulo_$d = 0; // Hilfszähler var zmodulo_$d = 0; // Hilfszähler
var showCurrTime_$d = '$showct'; // Reading currtime schreiben oder nicht
var distBorderright_$d = '$bdist'; // Abstand zum rechten Rand var distBorderright_$d = '$bdist'; // Abstand zum rechten Rand
var distBorderleft_$d = '$bdist'; // Abstand zum linken Rand var distBorderleft_$d = '$bdist'; // Abstand zum linken Rand
var allowSetStopTime; // erlaube / verbiete Setzen Reading stoptime var allowSetStopTime; // erlaube / verbiete Setzen Reading stoptime
@ -1096,6 +1114,16 @@ sub digitalWatch {
localStorage.setItem('lastalmtime_'+dev, lastalmtime); 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 // Check ob Alarm ausgelöst werden soll und ggf. Alarmevent triggern
function checkAndDoAlm_$d (dev, acttime, almtime) { function checkAndDoAlm_$d (dev, acttime, almtime) {
lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
@ -1125,7 +1153,7 @@ sub digitalWatch {
var watchkind_$d = '$addp'; var watchkind_$d = '$addp';
var cycletime = new Date(); var cycletime = new Date();
var cycleseconds = cycletime.getSeconds(); 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 (watchkind_$d == 'watch') {
if (modulo2_$d != zmodulo_$d) { if (modulo2_$d != zmodulo_$d) {
@ -1175,12 +1203,16 @@ sub digitalWatch {
} }
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d); checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen
} }
if (watchkind_$d == 'staticwatch') { if (watchkind_$d == 'staticwatch') {
var hours_$d = '$h'; var hours_$d = '$h';
var minutes_$d = '$m'; var minutes_$d = '$m';
var seconds_$d = '$s'; var seconds_$d = '$s';
setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen
} }
if (watchkind_$d == 'stopwatch') { if (watchkind_$d == 'stopwatch') {
@ -1243,6 +1275,8 @@ sub digitalWatch {
checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN); 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') { if (state_$d == 'stopped') {
@ -1356,6 +1390,8 @@ sub digitalWatch {
checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend checkAndDoAlm_$d ('$d', ddt_$d, almtime0_$d); // Alarm auslösen wenn zutreffend
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN); 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') { if (state_$d == 'stopped') {
@ -1469,6 +1505,7 @@ sub stationWatch {
my $sbody = AttrVal ($d, "stationBody", "Round"). "Body"; my $sbody = AttrVal ($d, "stationBody", "Round"). "Body";
my $hattr = AttrVal ($d, "htmlattr", "width='150' height='150'"); my $hattr = AttrVal ($d, "htmlattr", "width='150' height='150'");
my $tsou = AttrVal ($d, "timeSource", "client"); my $tsou = AttrVal ($d, "timeSource", "client");
my $showct = AttrVal ($d, "timeAsReading", 0);
my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc"); my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc");
@ -1484,6 +1521,7 @@ sub stationWatch {
var almtime0_$d = '$alarm'; var almtime0_$d = '$alarm';
var time_$d; var time_$d;
var zmodulo_$d = 0; // Hilfszähler var zmodulo_$d = 0; // Hilfszähler
var showCurrTime_$d = '$showct'; // Reading currtime schreiben oder nicht
// clock body (Uhrgehäuse) // clock body (Uhrgehäuse)
StationClock_$d.NoBody = 0; StationClock_$d.NoBody = 0;
@ -1557,6 +1595,25 @@ sub stationWatch {
return getBaseUrl()+"cmd="+encodeURIComponent(cmd)+"&XHR=1"; return getBaseUrl()+"cmd="+encodeURIComponent(cmd)+"&XHR=1";
} }
// Template digital time display
function buildtime (hours, minutes, seconds) {
var ddt = ((hours < 10) ? '0' : '') + hours + ':' +
((minutes < 10) ? '0' : '') + minutes + ':' +
((seconds < 10) ? '0' : '') + seconds
;
return ddt;
}
// 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);
}
}
// localStorage speichern letzte Alarmzeit // localStorage speichern letzte Alarmzeit
function localStoreSetLastalm_$d (dev, lastalmtime) { function localStoreSetLastalm_$d (dev, lastalmtime) {
localStorage.setItem('lastalmtime_'+dev, lastalmtime); localStorage.setItem('lastalmtime_'+dev, lastalmtime);
@ -1808,6 +1865,8 @@ sub stationWatch {
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d); checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen
// draw hour hand // draw hour hand
context.save(); context.save();
context.rotate(hours_$d * Math.PI / 6 + minutes_$d * Math.PI / 360); context.rotate(hours_$d * Math.PI / 6 + minutes_$d * Math.PI / 360);
@ -2081,6 +2140,7 @@ sub modernWatch {
my $fre = AttrVal($d, "modernColorRingEdge", "333"); my $fre = AttrVal($d, "modernColorRingEdge", "333");
my $hattr = AttrVal($d, "htmlattr", "width='150' height='150'"); my $hattr = AttrVal($d, "htmlattr", "width='150' height='150'");
my $tsou = AttrVal($d, "timeSource", "client"); my $tsou = AttrVal($d, "timeSource", "client");
my $showct = AttrVal($d, "timeAsReading", 0);
my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc"); my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc");
@ -2096,6 +2156,8 @@ sub modernWatch {
var ct_$d; var ct_$d;
var almtime0_$d = '$alarm'; var almtime0_$d = '$alarm';
var zmodulo_$d = 0; // Hilfszähler var zmodulo_$d = 0; // Hilfszähler
var modulo2_$d = 0; // Hilfszähler
var showCurrTime_$d = '$showct'; // Reading currtime schreiben oder nicht
// CSRF-Token auslesen // CSRF-Token auslesen
var body = document.querySelector("body"); var body = document.querySelector("body");
@ -2117,6 +2179,26 @@ sub modernWatch {
return getBaseUrl()+"cmd="+encodeURIComponent(cmd)+"&XHR=1"; return getBaseUrl()+"cmd="+encodeURIComponent(cmd)+"&XHR=1";
} }
// Template digital time display
function buildtime (hours, minutes, seconds) {
var ddt = ((hours < 10) ? '0' : '') + hours + ':' +
((minutes < 10) ? '0' : '') + minutes + ':' +
((seconds < 10) ? '0' : '') + seconds
;
return ddt;
}
// 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);
}
}
// localStorage speichern letzte Alarmzeit // localStorage speichern letzte Alarmzeit
function localStoreSetLastalm_$d (dev, lastalmtime) { function localStoreSetLastalm_$d (dev, lastalmtime) {
localStorage.setItem('lastalmtime_'+dev, lastalmtime); localStorage.setItem('lastalmtime_'+dev, lastalmtime);
@ -2251,6 +2333,8 @@ sub modernWatch {
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d); checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
setrcurrtime (hour_$d, minute_$d, second_$d); // Reading currtime mit angezeigter Zeit setzen
//hour_$d //hour_$d
hour_$d = hour_$d%12; hour_$d = hour_$d%12;
hour_$d = (hour_$d*Math.PI/6)+ hour_$d = (hour_$d*Math.PI/6)+
@ -2336,7 +2420,9 @@ return;
<h3>Watches</h3> <h3>Watches</h3>
<br> <br>
The module Watches provides watches in different styles as Device. The module Watches provides watches in different styles as Device. The module is a JavaScript application that runs on a
client (browser) and not on the FHEM server. Attributes and readings are read asynchronously from the server and possibly
also written, but only if the application is currently running in the browser. <br>
The user can influence the design of the watches via attributes. <br> The user can influence the design of the watches via attributes. <br>
The clocks are based on scripts of these pages: <br> The clocks are based on scripts of these pages: <br>
@ -2525,6 +2611,12 @@ As time source the client (browser time) as well as the FHEM server can be set
</li> </li>
<br> <br>
<a name="timeAsReading"></a>
<li><b>timeAsReading</b><br>
If set, a displayed time is written to the reading currtime.
</li>
<br>
<a name="timeSource"></a> <a name="timeSource"></a>
<li><b>timeSource</b><br> <li><b>timeSource</b><br>
Selects the time source. The local client time (browser) or the FHEM server time can be displayed. <br> Selects the time source. The local client time (browser) or the FHEM server time can be displayed. <br>
@ -2747,7 +2839,9 @@ As time source the client (browser time) as well as the FHEM server can be set
<h3>Watches</h3> <h3>Watches</h3>
<br> <br>
Das Modul Watches stellt Uhren in unterschiedlichen Stilen als Device zur Verfügung. Das Modul Watches stellt Uhren in unterschiedlichen Stilen als Device zur Verfügung. Das Modul ist eine JavaScript Anwendung
die auf einem Client (Browser) ausgeführt wird und nicht auf dem FHEM Server. Attribute und Readings werden asynchron vom
Server gelesen und evtl. auch geschrieben, allerdings nur dann wenn die Anwendung aktuell im Browser ausgeführt wird. <br>
Der Nutzer kann das Design der Uhren über Attribute beeinflussen. <br> Der Nutzer kann das Design der Uhren über Attribute beeinflussen. <br>
Die Uhren basieren auf Skripten dieser Seiten: <br> Die Uhren basieren auf Skripten dieser Seiten: <br>
@ -2937,6 +3031,12 @@ Als Zeitquelle können sowohl der Client (Browserzeit) als auch der FHEM-Server
</li> </li>
<br> <br>
<a name="timeAsReading"></a>
<li><b>timeAsReading</b><br>
Wenn gesetzt, wird eine angezeigte Uhrzeit in das Reading currtime geschrieben.
</li>
<br>
<a name="timeSource"></a> <a name="timeSource"></a>
<li><b>timeSource</b><br> <li><b>timeSource</b><br>
Wählt die Zeitquelle aus. Es kann die lokale Clientzeit (Browser) oder die Zeit des FHEM-Servers angezeigt werden. <br> Wählt die Zeitquelle aus. Es kann die lokale Clientzeit (Browser) oder die Zeit des FHEM-Servers angezeigt werden. <br>
@ -3170,7 +3270,7 @@ Als Zeitquelle können sowohl der Client (Browserzeit) als auch der FHEM-Server
"Digital display" "Digital display"
], ],
"version": "v1.1.1", "version": "v1.1.1",
"release_status": "testing", "release_status": "stable",
"author": [ "author": [
"Heiko Maaz <heiko.maaz@t-online.de>", "Heiko Maaz <heiko.maaz@t-online.de>",
null null