[network] Fix last-seen channel being set to UNDEF at startup (#17971)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2024-12-24 15:37:16 +01:00 committed by Leo Siepel
parent 5a1030b9f5
commit 7bb499b7df

View File

@ -100,11 +100,11 @@ public class NetworkHandler extends BaseThingHandler
});
break;
case CHANNEL_LASTSEEN:
// We should not set the last seen state to UNDEF, it prevents restoreOnStartup from working
// For reference: https://github.com/openhab/openhab-addons/issues/17404
Instant lastSeen = presenceDetection.getLastSeen();
if (lastSeen != null) {
updateState(CHANNEL_LASTSEEN, new DateTimeType(lastSeen));
} else {
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
}
break;
default:
@ -144,9 +144,9 @@ public class NetworkHandler extends BaseThingHandler
Instant lastSeen = presenceDetection.getLastSeen();
if (value.isReachable() && lastSeen != null) {
updateState(CHANNEL_LASTSEEN, new DateTimeType(lastSeen));
} else if (!value.isReachable() && lastSeen == null) {
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
}
// We should not set the last seen state to UNDEF, it prevents restoreOnStartup from working
// For reference: https://github.com/openhab/openhab-addons/issues/17404
updateNetworkProperties();
}