mirror of https://github.com/arendst/Tasmota.git
Merge pull request #9989 from s-hadinger/zigbee_last_seen_grey
Zigbee UI change color of last seen depending on age
This commit is contained in:
commit
e899e01eef
|
@ -1601,32 +1601,26 @@ extern "C" {
|
||||||
// Convert seconds to a string representing days, hours or minutes present in the n-value.
|
// Convert seconds to a string representing days, hours or minutes present in the n-value.
|
||||||
// The string will contain the most coarse time only, rounded down (61m == 01h, 01h37m == 01h).
|
// The string will contain the most coarse time only, rounded down (61m == 01h, 01h37m == 01h).
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// - n: uint32_t representing some number of seconds
|
// - seconds: uint32_t representing some number of seconds
|
||||||
// - result: a buffer of suitable size (7 bytes would represent the entire solution space
|
// Outputs:
|
||||||
// for UINT32_MAX including the trailing null-byte, or "49710d")
|
// - char for unit (d for day, h for hour, m for minute)
|
||||||
// - result_len: A numeric value representing the total length of the result buffer
|
// - the hex color to be used to display the text
|
||||||
// Returns:
|
|
||||||
// - The number of characters that would have been written were result sufficiently large
|
|
||||||
// - negatve number on encoding error from snprintf
|
|
||||||
//
|
//
|
||||||
int convert_seconds_to_dhm(uint32_t n, char *result, size_t result_len){
|
uint32_t convert_seconds_to_dhm(uint32_t seconds, char *unit, uint8_t *color){
|
||||||
char fmtstr[] = "%02dmhd"; // Don't want this in progmem, because we mutate it.
|
static uint32_t conversions[3] = {24 * 3600, 3600, 60};
|
||||||
uint32_t conversions[3] = {24 * 3600, 3600, 60};
|
static char units[3] = { 'd', 'h', 'm'}; // day, hour, minute
|
||||||
uint32_t value;
|
static uint8_t colors[3] = { 0x60, 0xA0, 0xEA};
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
value = n / conversions[i];
|
*color = colors[i];
|
||||||
if(value > 0) {
|
*unit = units[i];
|
||||||
fmtstr[4] = fmtstr[6-i];
|
if (seconds > conversions[i]) { // always pass even if 00m
|
||||||
break;
|
return seconds / conversions[i];
|
||||||
}
|
}
|
||||||
n = n % conversions[i];
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
// Null-terminate the string at the last "valid" index, removing any excess zero values.
|
|
||||||
fmtstr[5] = '\0';
|
|
||||||
return snprintf(result, result_len, fmtstr, value);
|
|
||||||
}
|
}
|
||||||
}
|
} // extern "C"
|
||||||
|
|
||||||
void ZigbeeShow(bool json)
|
void ZigbeeShow(bool json)
|
||||||
{
|
{
|
||||||
if (json) {
|
if (json) {
|
||||||
|
@ -1708,16 +1702,21 @@ void ZigbeeShow(bool json)
|
||||||
WSContentSend_PD(PSTR("<i class='b%d%s'></i>"), j, (num_bars < j) ? PSTR(" o30") : PSTR(""));
|
WSContentSend_PD(PSTR("<i class='b%d%s'></i>"), j, (num_bars < j) ? PSTR(" o30") : PSTR(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char dhm[16]; // len("🕗" + "49710d" + '\0') == 16
|
char dhm[48];
|
||||||
snprintf_P(dhm, sizeof(dhm), PSTR(" "));
|
snprintf_P(dhm, sizeof(dhm), PSTR("<td> "));
|
||||||
if(device.validLastSeen()){
|
if (device.validLastSeen()) {
|
||||||
snprintf_P(dhm, sizeof(dhm), PSTR("🕗"));
|
char unit;
|
||||||
convert_seconds_to_dhm(now - device.last_seen, &dhm[9], 7);
|
uint8_t color;
|
||||||
|
uint16_t val = convert_seconds_to_dhm(now - device.last_seen, &unit, &color);
|
||||||
|
if (val < 100) {
|
||||||
|
snprintf_P(dhm, sizeof(dhm), PSTR("<td style=\"color:#%02x%02x%02x\">🕗%02d%c"),
|
||||||
|
color, color, color, val, unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WSContentSend_PD(PSTR(
|
WSContentSend_PD(PSTR(
|
||||||
"</div></td>" // Close LQI
|
"</div></td>" // Close LQI
|
||||||
"<td>%s{e}" // dhm (Last Seen)
|
"%s{e}" // dhm (Last Seen)
|
||||||
), dhm );
|
), dhm );
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
|
|
Loading…
Reference in New Issue