Simplify DateTimeType handling for AVM FRITZ!

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-12-10 21:32:54 +01:00 committed by lsiepel
parent 0ee5fd952e
commit 1231e7d2e9
2 changed files with 5 additions and 11 deletions

View File

@ -59,7 +59,6 @@ import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.toCelsius;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Map;
@ -314,9 +313,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
NextChangeModel nextChange = heatingModel.getNextchange();
if (nextChange != null) {
int endPeriod = nextChange.getEndperiod();
updateThingChannelState(CHANNEL_NEXT_CHANGE, endPeriod == 0 ? UnDefType.UNDEF
: new DateTimeType(
ZonedDateTime.ofInstant(Instant.ofEpochSecond(endPeriod), ZoneId.systemDefault())));
updateThingChannelState(CHANNEL_NEXT_CHANGE,
endPeriod == 0 ? UnDefType.UNDEF : new DateTimeType(Instant.ofEpochSecond(endPeriod)));
BigDecimal nextTemperature = nextChange.getTchange();
updateThingChannelState(CHANNEL_NEXTTEMP, TEMP_FRITZ_UNDEFINED.equals(nextTemperature) ? UnDefType.UNDEF
: new QuantityType<>(toCelsius(nextTemperature), SIUnits.CELSIUS));

View File

@ -16,8 +16,6 @@ import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
@ -189,13 +187,11 @@ public class AVMFritzButtonHandler extends DeviceHandler {
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_LAST_CHANGE,
UnDefType.UNDEF);
} else {
ZonedDateTime timestamp = ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastPressedTimestamp),
ZoneId.systemDefault());
Instant then = timestamp.toInstant();
Instant timestamp = Instant.ofEpochSecond(lastPressedTimestamp);
// Avoid dispatching events if "lastpressedtimestamp" is older than now "lastTimestamp" (e.g. during
// restart)
if (then.isAfter(lastTimestamp)) {
lastTimestamp = then;
if (timestamp.isAfter(lastTimestamp)) {
lastTimestamp = timestamp;
triggerThingChannel(channelGroupId == null ? CHANNEL_PRESS
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_PRESS, event);
}