2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +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.
# 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

View File

@ -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 <seconds> ",
"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 {
<script>
var ct_$d;
var almtime0_$d = '$alarm';
var almtime0_$d = '$alarm';
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)
StationClock_$d.NoBody = 0;
@ -1557,6 +1595,25 @@ sub stationWatch {
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
function localStoreSetLastalm_$d (dev, lastalmtime) {
localStorage.setItem('lastalmtime_'+dev, lastalmtime);
@ -1754,10 +1811,10 @@ sub stationWatch {
context.restore();
}
var cycletime = new Date();
var cycleseconds = cycletime.getSeconds();
modulo2_$d = cycleseconds % 2; // Taktung für Readingabruf (Serverauslastung reduzieren)
var cycletime = new Date();
var cycleseconds = cycletime.getSeconds();
modulo2_$d = cycleseconds % 2; // Taktung für Readingabruf (Serverauslastung reduzieren)
if (modulo2_$d != zmodulo_$d) {
command = '{ReadingsVal("$d","alarmTime","+almtime0_$d+")}'; // alarmTime Reading lesen
url_$d = makeCommand(command);
@ -1803,10 +1860,12 @@ sub stationWatch {
((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);
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
setrcurrtime (hours_$d, minutes_$d, seconds_$d); // Reading currtime mit angezeigter Zeit setzen
// draw hour hand
context.save();
@ -2081,6 +2140,7 @@ sub modernWatch {
my $fre = AttrVal($d, "modernColorRingEdge", "333");
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");
@ -2094,8 +2154,10 @@ sub modernWatch {
<script>
var ct_$d;
var almtime0_$d = '$alarm';
var zmodulo_$d = 0; // Hilfszähler
var almtime0_$d = '$alarm';
var zmodulo_$d = 0; // Hilfszähler
var modulo2_$d = 0; // Hilfszähler
var showCurrTime_$d = '$showct'; // Reading currtime schreiben oder nicht
// CSRF-Token auslesen
var body = document.querySelector("body");
@ -2117,6 +2179,26 @@ sub modernWatch {
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
function localStoreSetLastalm_$d (dev, lastalmtime) {
localStorage.setItem('lastalmtime_'+dev, lastalmtime);
@ -2251,6 +2333,8 @@ sub modernWatch {
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%12;
hour_$d = (hour_$d*Math.PI/6)+
@ -2336,7 +2420,9 @@ return;
<h3>Watches</h3>
<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 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>
<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>
<li><b>timeSource</b><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>
<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>
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>
<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>
<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>
@ -3170,7 +3270,7 @@ Als Zeitquelle können sowohl der Client (Browserzeit) als auch der FHEM-Server
"Digital display"
],
"version": "v1.1.1",
"release_status": "testing",
"release_status": "stable",
"author": [
"Heiko Maaz <heiko.maaz@t-online.de>",
null