mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for AVM FRITZ!
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
0ee5fd952e
commit
1231e7d2e9
@ -59,7 +59,6 @@ import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.toCelsius;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -314,9 +313,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
|
|||||||
NextChangeModel nextChange = heatingModel.getNextchange();
|
NextChangeModel nextChange = heatingModel.getNextchange();
|
||||||
if (nextChange != null) {
|
if (nextChange != null) {
|
||||||
int endPeriod = nextChange.getEndperiod();
|
int endPeriod = nextChange.getEndperiod();
|
||||||
updateThingChannelState(CHANNEL_NEXT_CHANGE, endPeriod == 0 ? UnDefType.UNDEF
|
updateThingChannelState(CHANNEL_NEXT_CHANGE,
|
||||||
: new DateTimeType(
|
endPeriod == 0 ? UnDefType.UNDEF : new DateTimeType(Instant.ofEpochSecond(endPeriod)));
|
||||||
ZonedDateTime.ofInstant(Instant.ofEpochSecond(endPeriod), ZoneId.systemDefault())));
|
|
||||||
BigDecimal nextTemperature = nextChange.getTchange();
|
BigDecimal nextTemperature = nextChange.getTchange();
|
||||||
updateThingChannelState(CHANNEL_NEXTTEMP, TEMP_FRITZ_UNDEFINED.equals(nextTemperature) ? UnDefType.UNDEF
|
updateThingChannelState(CHANNEL_NEXTTEMP, TEMP_FRITZ_UNDEFINED.equals(nextTemperature) ? UnDefType.UNDEF
|
||||||
: new QuantityType<>(toCelsius(nextTemperature), SIUnits.CELSIUS));
|
: new QuantityType<>(toCelsius(nextTemperature), SIUnits.CELSIUS));
|
||||||
|
@ -16,8 +16,6 @@ import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -189,13 +187,11 @@ public class AVMFritzButtonHandler extends DeviceHandler {
|
|||||||
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_LAST_CHANGE,
|
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_LAST_CHANGE,
|
||||||
UnDefType.UNDEF);
|
UnDefType.UNDEF);
|
||||||
} else {
|
} else {
|
||||||
ZonedDateTime timestamp = ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastPressedTimestamp),
|
Instant timestamp = Instant.ofEpochSecond(lastPressedTimestamp);
|
||||||
ZoneId.systemDefault());
|
|
||||||
Instant then = timestamp.toInstant();
|
|
||||||
// Avoid dispatching events if "lastpressedtimestamp" is older than now "lastTimestamp" (e.g. during
|
// Avoid dispatching events if "lastpressedtimestamp" is older than now "lastTimestamp" (e.g. during
|
||||||
// restart)
|
// restart)
|
||||||
if (then.isAfter(lastTimestamp)) {
|
if (timestamp.isAfter(lastTimestamp)) {
|
||||||
lastTimestamp = then;
|
lastTimestamp = timestamp;
|
||||||
triggerThingChannel(channelGroupId == null ? CHANNEL_PRESS
|
triggerThingChannel(channelGroupId == null ? CHANNEL_PRESS
|
||||||
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_PRESS, event);
|
: channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_PRESS, event);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user