From 63ab69a9203c0198c4e5069bcbf07ebbb8ac3050 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Tue, 21 Dec 2021 07:09:38 -0500 Subject: [PATCH] display time since last contact for sensors. added 'unknown' as well as 'ok' and 'low' for battery status. --- skins/Seasons/seasons.css | 5 +++++ skins/Seasons/sensors.inc | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/skins/Seasons/seasons.css b/skins/Seasons/seasons.css index d29fab87..58358adc 100644 --- a/skins/Seasons/seasons.css +++ b/skins/Seasons/seasons.css @@ -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; diff --git a/skins/Seasons/sensors.inc b/skins/Seasons/sensors.inc index 3569ba87..42656438 100644 --- a/skins/Seasons/sensors.inc +++ b/skins/Seasons/sensors.inc @@ -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 -OK -#else +#if $x is None +UNKNOWN +#elif $x == 1 LOW +#else +OK #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 @@ $obs.label[$x] $getVar('current.' + $x) + $get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now) #end if #end for @@ -76,7 +105,7 @@ $obs.label[$x] $get_battery_status($getVar('current.%s.raw' % $x)) - $getVar('year.%s.lasttime' % $x) + $get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now) #end if #end for @@ -89,6 +118,7 @@ $obs.label[$x] $getVar('current.' + $x) + $get_time_delta($getVar('year.%s.lasttime.raw' % $x), $now) #end if #end for