From b2443ec548f58d62d01406dac0f8f976aca270fd Mon Sep 17 00:00:00 2001 From: Justin Monroe Date: Sun, 27 Sep 2020 17:23:54 +0000 Subject: [PATCH] Fixed last_seen calculation with zigbee devices. The specific circumstances of this bug typically involve a restart, after which a zigbee device pings the bridge before the Rtc.utc_time is set by NTP. This results in a large "last seen" time calculation. This is cosmetic only. This patch ensures the "last seen" time is after 2020-01-01 0000 UTC when pulled from the Rtc.utc_time field, otherwise, last_seen updates are ignored. --- tasmota/xdrv_23_zigbee_2_devices.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_23_zigbee_2_devices.ino b/tasmota/xdrv_23_zigbee_2_devices.ino index 4e16ea11f..506962f3a 100644 --- a/tasmota/xdrv_23_zigbee_2_devices.ino +++ b/tasmota/xdrv_23_zigbee_2_devices.ino @@ -645,7 +645,12 @@ void Z_Devices::setLQI(uint16_t shortaddr, uint8_t lqi) { void Z_Devices::setLastSeenNow(uint16_t shortaddr) { if (shortaddr == localShortAddr) { return; } - getShortAddr(shortaddr).last_seen= Rtc.utc_time; + // Only update time if after 2020-01-01 0000. + // Fixes issue where zigbee device pings before WiFi/NTP has set utc_time + // to the correct time, and "last seen" calculations are based on the + // pre-corrected last_seen time and the since-corrected utc_time. + if (Rtc.utc_time < 1577836800) { return; } + getShortAddr(shortaddr).last_seen = Rtc.utc_time; }