display time since last contact for sensors. added 'unknown' as well as 'ok' and 'low' for battery status.

This commit is contained in:
Matthew Wall
2021-12-21 07:09:38 -05:00
parent add326e356
commit 63ab69a920
2 changed files with 39 additions and 4 deletions

View File

@@ -19,6 +19,7 @@
--loval-color:#4444aa;
--ok-color:#44aa44;
--low-color:#aa4444;
--unknown-color:#dfdfdf;
}
/* use the fonts from google */
@@ -179,6 +180,10 @@ a:hover {
color: var(--low-color);
}
.status_unknown {
color: var(--unknown-color);
}
.button {
cursor: pointer;
padding-left: 10px;

View File

@@ -8,14 +8,42 @@
## battery status, and various voltages. if there are no data available,
## then this degenerates to nothing displayed.
#import time
#set $now = time.time()
#def get_battery_status($x)
#if $x == 0
<span class="status_ok">OK</span>
#else
#if $x is None
<span class="status_unknown">UNKNOWN</span>
#elif $x == 1
<span class="status_low">LOW</span>
#else
<span class="status_ok">OK</span>
#end if
#end def
## provide an indication of how much time has passed since the last sensor
## reading.
#def get_time_delta($last_ts, $now)
#if $last_ts
#set $delta = int($now - $last_ts)
#if $delta < 60
#elif $delta < 3600
#set $minutes = int($delta / 60)
$minutes $gettext('minutes ago')
#elif $delta < 86400
#set $hours = int($delta / 3600)
$hours $gettext('hours ago')
#else
#set $days = int($delta / 86400)
$days $gettext('days ago')
#end if
#else
never
#end if
#end def
## Get the list of sensor observations from the configuration file, otherwise
## fallback to a very rudimentary set.
#set $sensor_connections = $DisplayOptions.get('sensor_connections', ['rxCheckPercent'])
@@ -64,6 +92,7 @@
<tr>
<td class="label">$obs.label[$x]</td>
<td class="data">$getVar('current.' + $x)</td>
<td class="timestamp">$get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now)</td>
</tr>
#end if
#end for
@@ -76,7 +105,7 @@
<tr>
<td class="label">$obs.label[$x]</td>
<td class="data">$get_battery_status($getVar('current.%s.raw' % $x))</td>
<td class="data">$getVar('year.%s.lasttime' % $x)</td>
<td class="timestamp">$get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now)</td>
</tr>
#end if
#end for
@@ -89,6 +118,7 @@
<tr>
<td class="label">$obs.label[$x]</td>
<td class="data">$getVar('current.' + $x)</td>
<td class="timestamp">$get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now)</td>
</tr>
#end if
#end for