Skip to content

Commit

Permalink
[network] Fix last-seen channel being set to UNDEF at startup (#17971)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <[email protected]>
  • Loading branch information
lsiepel authored Dec 24, 2024
1 parent 7e99669 commit 50e3ca6
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ private void refreshValue(ChannelUID channelUID) {
});
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:
Expand Down Expand Up @@ -144,9 +144,9 @@ public void finalDetectionResult(PresenceDetectionValue value) {
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();
}
Expand Down

0 comments on commit 50e3ca6

Please sign in to comment.