mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for FreeboxOS
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
0a46ff2a79
commit
f0ba39f121
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.freeboxos.internal.handler;
|
package org.openhab.binding.freeboxos.internal.handler;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@ -288,7 +289,7 @@ public abstract class ApiConsumerHandler extends BaseThingHandler implements Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateChannelDateTimeState(String channelId, @Nullable ZonedDateTime timestamp) {
|
protected void updateChannelDateTimeState(String channelId, @Nullable Instant timestamp) {
|
||||||
updateIfActive(channelId, timestamp == null ? UnDefType.NULL : new DateTimeType(timestamp));
|
updateIfActive(channelId, timestamp == null ? UnDefType.NULL : new DateTimeType(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ package org.openhab.binding.freeboxos.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -84,7 +84,7 @@ public class FreeplugHandler extends ApiConsumerHandler {
|
|||||||
"internalPoll is not possible because MAC address is undefined for the thing " + thing.getUID());
|
"internalPoll is not possible because MAC address is undefined for the thing " + thing.getUID());
|
||||||
}
|
}
|
||||||
getManager(FreeplugManager.class).getPlug(mac).ifPresent(plug -> {
|
getManager(FreeplugManager.class).getPlug(mac).ifPresent(plug -> {
|
||||||
updateChannelDateTimeState(LAST_SEEN, ZonedDateTime.now().minusSeconds(plug.inactive()));
|
updateChannelDateTimeState(LAST_SEEN, Instant.now().minusSeconds(plug.inactive()));
|
||||||
|
|
||||||
updateChannelString(LINE_STATUS, plug.ethPortStatus());
|
updateChannelString(LINE_STATUS, plug.ethPortStatus());
|
||||||
updateChannelOnOff(REACHABLE, plug.hasNetwork());
|
updateChannelOnOff(REACHABLE, plug.hasNetwork());
|
||||||
|
@ -15,8 +15,6 @@ package org.openhab.binding.freeboxos.internal.handler;
|
|||||||
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -50,11 +48,9 @@ public class KeyfobHandler extends HomeNodeHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected State getChannelState(String channelId, EndpointState state, Optional<Endpoint> endPoint) {
|
protected State getChannelState(String channelId, EndpointState state, Optional<Endpoint> endPoint) {
|
||||||
if (channelId.startsWith(KEYFOB_PUSHED)) {
|
if (channelId.startsWith(KEYFOB_PUSHED)) {
|
||||||
return Objects.requireNonNull(endPoint.map(ep -> ep
|
return Objects.requireNonNull(endPoint.map(ep -> ep.getLastChange()
|
||||||
.getLastChange().map(
|
.map(change -> (State) (KEYFOB_PUSHED.equals(channelId) ? new DecimalType(change.value())
|
||||||
change -> (State) (KEYFOB_PUSHED.equals(channelId) ? new DecimalType(change.value())
|
: new DateTimeType(Instant.ofEpochSecond(change.timestamp()))))
|
||||||
: new DateTimeType(ZonedDateTime
|
|
||||||
.ofInstant(Instant.ofEpochSecond(change.timestamp()), ZoneOffset.UTC))))
|
|
||||||
.orElse(UnDefType.UNDEF)).orElse(UnDefType.UNDEF));
|
.orElse(UnDefType.UNDEF)).orElse(UnDefType.UNDEF));
|
||||||
}
|
}
|
||||||
String value = state.value();
|
String value = state.value();
|
||||||
|
@ -15,8 +15,6 @@ package org.openhab.binding.freeboxos.internal.handler;
|
|||||||
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -48,8 +46,7 @@ public class PirHandler extends HomeNodeHandler {
|
|||||||
protected State getChannelState(String channelId, EndpointState state, Optional<Endpoint> endPoint) {
|
protected State getChannelState(String channelId, EndpointState state, Optional<Endpoint> endPoint) {
|
||||||
if (PIR_TAMPER_UPDATE.equals(channelId) || PIR_TRIGGER_UPDATE.equals(channelId)) {
|
if (PIR_TAMPER_UPDATE.equals(channelId) || PIR_TRIGGER_UPDATE.equals(channelId)) {
|
||||||
return Objects.requireNonNull(endPoint.map(ep -> ep.getLastChange()
|
return Objects.requireNonNull(endPoint.map(ep -> ep.getLastChange()
|
||||||
.map(change -> (State) new DateTimeType(
|
.map(change -> (State) new DateTimeType(Instant.ofEpochSecond(change.timestamp())))
|
||||||
ZonedDateTime.ofInstant(Instant.ofEpochSecond(change.timestamp()), ZoneOffset.UTC)))
|
|
||||||
.orElse(UnDefType.UNDEF)).orElse(UnDefType.UNDEF));
|
.orElse(UnDefType.UNDEF)).orElse(UnDefType.UNDEF));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user