mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Network
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
d00d654976
commit
d871b66d3c
@ -17,12 +17,10 @@ import static org.openhab.binding.network.internal.utils.NetworkUtils.durationTo
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.network.internal.NetworkBindingConfiguration;
|
import org.openhab.binding.network.internal.NetworkBindingConfiguration;
|
||||||
@ -104,8 +102,7 @@ public class NetworkHandler extends BaseThingHandler
|
|||||||
case CHANNEL_LASTSEEN:
|
case CHANNEL_LASTSEEN:
|
||||||
Instant lastSeen = presenceDetection.getLastSeen();
|
Instant lastSeen = presenceDetection.getLastSeen();
|
||||||
if (lastSeen != null) {
|
if (lastSeen != null) {
|
||||||
updateState(CHANNEL_LASTSEEN, new DateTimeType(
|
updateState(CHANNEL_LASTSEEN, new DateTimeType(lastSeen));
|
||||||
ZonedDateTime.ofInstant(lastSeen, TimeZone.getDefault().toZoneId()).withFixedOffsetZone()));
|
|
||||||
} else {
|
} else {
|
||||||
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
|
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
@ -146,8 +143,7 @@ public class NetworkHandler extends BaseThingHandler
|
|||||||
|
|
||||||
Instant lastSeen = presenceDetection.getLastSeen();
|
Instant lastSeen = presenceDetection.getLastSeen();
|
||||||
if (value.isReachable() && lastSeen != null) {
|
if (value.isReachable() && lastSeen != null) {
|
||||||
updateState(CHANNEL_LASTSEEN, new DateTimeType(
|
updateState(CHANNEL_LASTSEEN, new DateTimeType(lastSeen));
|
||||||
ZonedDateTime.ofInstant(lastSeen, TimeZone.getDefault().toZoneId()).withFixedOffsetZone()));
|
|
||||||
} else if (!value.isReachable() && lastSeen == null) {
|
} else if (!value.isReachable() && lastSeen == null) {
|
||||||
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
|
updateState(CHANNEL_LASTSEEN, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user