mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Insteon
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
e898312e9e
commit
6e2eb70950
@ -18,8 +18,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -601,19 +599,13 @@ public abstract class MessageHandler extends BaseFeatureHandler {
|
||||
|
||||
@Override
|
||||
public void handleMessage(byte cmd1, Msg msg) {
|
||||
Instant instant = Instant.ofEpochMilli(msg.getTimestamp());
|
||||
ZonedDateTime timestamp = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||
ZonedDateTime lastTimestamp = getLastTimestamp();
|
||||
// set last time if not defined yet or message timestamp is greater than last value
|
||||
if (lastTimestamp == null || timestamp.compareTo(lastTimestamp) > 0) {
|
||||
Instant timestamp = Instant.ofEpochMilli(msg.getTimestamp());
|
||||
Instant lastTimestamp = feature.getState() instanceof DateTimeType datetime ? datetime.getInstant() : null;
|
||||
// update state if not defined or is older than message timestamp
|
||||
if (lastTimestamp == null || lastTimestamp.isBefore(timestamp)) {
|
||||
feature.updateState(new DateTimeType(timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable ZonedDateTime getLastTimestamp() {
|
||||
State state = feature.getState();
|
||||
return state instanceof DateTimeType datetime ? datetime.getZonedDateTime() : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user