Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify DateTimeType handling #17725

Merged
merged 82 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
eb50940
Simplify DateTimeType handling for aha Waste Collection
jlaur Dec 10, 2024
54ae58c
Simplify DateTimeType handling for Air Quality
jlaur Dec 10, 2024
e19a563
Simplify DateTimeType handling for Automower
jlaur Nov 9, 2024
1e47f39
Simplify DateTimeType handling for AVM FRITZ!
jlaur Dec 10, 2024
ff155df
Simplify DateTimeType handling for aWATTar
jlaur Nov 11, 2024
633c61c
Simplify DateTimeType handling for BigAssFan
jlaur Nov 30, 2024
46d4c4a
Simplify DateTimeType handling for Bosch Indego
jlaur Nov 27, 2024
122eb09
Simplify DateTimeType handling for Bosch Smart Home
jlaur Nov 28, 2024
100fe11
Simplify DateTimeType handling for Broadlink
jlaur Nov 16, 2024
8719e05
Simplify DateTimeType handling for DBQuery
jlaur Dec 9, 2024
362682c
Simplify DateTimeType handling for deCONZ
jlaur Nov 9, 2024
de0928b
Simplify DateTimeType handling for Deutsche Bahn
jlaur Dec 10, 2024
12ed4c3
Simplify DateTimeType handling for Digiplex/EVO
jlaur Dec 9, 2024
8549484
Simplify DateTimeType handling for Doorbird
jlaur Dec 9, 2024
5bad35f
Simplify DateTimeType handling for DWD Pollenflug
jlaur Dec 10, 2024
cf6fe16
Simplify DateTimeType handling for DWD Unwetter
jlaur Nov 14, 2024
6bf87d5
Simplify DateTimeType handling for Ecobee
jlaur Nov 27, 2024
17e3e19
Simplify DateTimeType handling for Ecovacs
jlaur Nov 10, 2024
1409bb8
Simplify DateTimeType handling for Enphase
jlaur Dec 9, 2024
0605b18
Simplify DateTimeType handling for EVCC
jlaur Nov 19, 2024
4b2480f
Simplify DateTimeType handling for Exec
jlaur Nov 25, 2024
bf87383
Simplify DateTimeType handling for Feed
jlaur Dec 10, 2024
d8c1c14
Simplify DateTimeType handling for Fine Offset Weather Station
jlaur Nov 17, 2024
c63eadb
Simplify DateTimeType handling for Flume
jlaur Nov 9, 2024
9a37124
Simplify DateTimeType handling for FMI Weather
jlaur Nov 25, 2024
4f6aec8
Simplify DateTimeType handling for Foobot
jlaur Dec 10, 2024
5a04fc6
Simplify DateTimeType handling for FreeboxOS
jlaur Nov 25, 2024
f55c8c7
Simplify DateTimeType handling for Freecurrency
jlaur Dec 17, 2024
5305084
Simplify DateTimeType handling for Gardena
jlaur Dec 10, 2024
3353397
Simplify DateTimeType handling for Groupe PSA
jlaur Nov 9, 2024
2f541ec
Simplify DateTimeType handling for Helios easyControls
jlaur Nov 17, 2024
56d0fc3
Simplify DateTimeType handling for Philips Hue
jlaur Nov 27, 2024
3c51fa8
Simplify DateTimeType handling for Hydrawise
jlaur Nov 17, 2024
824e19a
Simplify DateTimeType handling for IHC
jlaur Nov 9, 2024
902e871
Simplify DateTimeType handling for Insteon
jlaur Nov 15, 2024
829e3b7
Simplify DateTimeType handling for JuiceNet
jlaur Nov 9, 2024
90e5650
Simplify DateTimeType handling for KM200
jlaur Nov 17, 2024
63921a1
Simplify DateTimeType handling for LaMetric
jlaur Nov 17, 2024
53a36dd
Simplify DateTimeType handling for Lutron
jlaur Nov 17, 2024
0f6204e
Simplify DateTimeType handling for LuxtronikHeatpump
jlaur Nov 28, 2024
a7b6ee0
Simplify DateTimeType handling for Meater
jlaur Nov 25, 2024
056ae95
Simplify DateTimeType handling for Mercedes Me
jlaur Nov 19, 2024
bce98c4
Simplify DateTimeType handling for Met Office DataHub
jlaur Nov 25, 2024
3ed5038
Simplify DateTimeType handling for Meteo France
jlaur Dec 16, 2024
36843df
Simplify DateTimeType handling for Mi IO
jlaur Nov 9, 2024
f86d771
Simplify DateTimeType handling for Millheat
jlaur Nov 15, 2024
ca729a9
Simplify DateTimeType handling for MQTT
jlaur Nov 19, 2024
f5207fa
Simplify DateTimeType handling for Ruuvi Gateway MQTT
jlaur Nov 24, 2024
0291b5b
Simplify DateTimeType handling for Network
jlaur Nov 9, 2024
931c150
Simplify DateTimeType handling for Nest
jlaur Nov 16, 2024
8b732d2
Simplify DateTimeType handling for OJElectronics
jlaur Nov 17, 2024
53ddcef
Simplify DateTimeType handling for OneBusAway
jlaur Nov 28, 2024
b18a5b0
Simplify DateTimeType handling for OpenUV
jlaur Nov 18, 2024
e986ba0
Simplify DateTimeType handling for OpenWeatherMap
jlaur Nov 26, 2024
96c0426
Simplify DateTimeType handling for PLCLogo
jlaur Nov 18, 2024
a654595
Simplify DateTimeType handling for SAICiSMART
jlaur Nov 9, 2024
2279b7d
Simplify DateTimeType handling for Satel Integra Alarm System
jlaur Nov 18, 2024
03a0993
Simplify DateTimeType handling for Shelly
jlaur Nov 15, 2024
a132914
Simplify DateTimeType handling for Siemens HVAC
jlaur Nov 10, 2024
0440a85
Simplify DateTimeType handling for Solax
jlaur Nov 24, 2024
ca804f6
Simplify DateTimeType handling for Philips Somneo
jlaur Nov 19, 2024
fc136ce
Simplify DateTimeType handling for TA C.M.I.
jlaur Nov 18, 2024
333c177
Simplify DateTimeType handling for Tado
jlaur Nov 9, 2024
c85dfee
Simplify DateTimeType handling for Teleinfo
jlaur Nov 18, 2024
b3f9024
Simplify DateTimeType handling for Tellstick
jlaur Nov 27, 2024
4c79dea
Simplify DateTimeType handling for UniFi
jlaur Nov 26, 2024
7d58dbf
Simplify DateTimeType handling for Vallox MV
jlaur Nov 9, 2024
efe87f2
Simplify DateTimeType handling for VeSync
jlaur Nov 25, 2024
fdb75ee
Simplify DateTimeType handling for Video Disk Recorder
jlaur Nov 10, 2024
b8cf4f2
Simplify DateTimeType handling for VisualCrossing
jlaur Dec 10, 2024
bf25450
Simplify DateTimeType handling for VolvoOnCall
jlaur Nov 26, 2024
70c8fb2
Simplify DateTimeType handling for WeatherUnderground
jlaur Dec 16, 2024
9c54f56
Simplify DateTimeType handling for WeMo
jlaur Nov 9, 2024
cca4a12
Simplify DateTimeType handling for WiZ
jlaur Dec 17, 2024
3757e51
Simplify DateTimeType handling for Wolf Smartset
jlaur Dec 9, 2024
9cea776
Simplify DateTimeType handling for XmlTv
jlaur Dec 17, 2024
a443412
Simplify DateTimeType handling for ZoneMinder
jlaur Nov 27, 2024
afd4301
Simplify DateTimeType handling for Amazon DynamoDB
jlaur Nov 9, 2024
8c5faa1
Simplify DateTimeType handling for InfluxDB
jlaur Nov 9, 2024
49167d7
Simplify DateTimeType handling for Java Persistence API
jlaur Nov 18, 2024
19d869b
Simplify DateTimeType handling for JDBC
jlaur Nov 14, 2024
a525c1c
Simplify DateTimeType handling for MongoDB
jlaur Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.IOException;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
Expand All @@ -26,7 +25,6 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.ahawastecollection.internal.CollectionDate.WasteType;
import org.openhab.core.cache.ExpiringCache;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.scheduler.CronScheduler;
import org.openhab.core.scheduler.ScheduledCompletableFuture;
Expand Down Expand Up @@ -57,7 +55,6 @@ public class AhaWasteCollectionHandler extends BaseThingHandler {
private final Lock monitor = new ReentrantLock();
private final ExpiringCache<Map<WasteType, CollectionDate>> cache;

private final TimeZoneProvider timeZoneProvider;
private final Logger logger = LoggerFactory.getLogger(AhaWasteCollectionHandler.class);

private @Nullable AhaCollectionSchedule collectionSchedule;
Expand All @@ -69,11 +66,10 @@ public class AhaWasteCollectionHandler extends BaseThingHandler {
private final ScheduledExecutorService executorService;

public AhaWasteCollectionHandler(final Thing thing, final CronScheduler scheduler,
final TimeZoneProvider timeZoneProvider, final AhaCollectionScheduleFactory scheduleFactory,
final AhaCollectionScheduleFactory scheduleFactory,
@Nullable final ScheduledExecutorService executorService) {
super(thing);
this.cronScheduler = scheduler;
this.timeZoneProvider = timeZoneProvider;
this.scheduleFactory = scheduleFactory;
this.cache = new ExpiringCache<>(Duration.ofMinutes(5), this::loadCollectionDates);
this.executorService = executorService == null ? this.scheduler : executorService;
Expand Down Expand Up @@ -190,9 +186,7 @@ private void updateChannels(final Map<WasteType, CollectionDate> collectionDates

final Date nextCollectionDate = collectionDate.getDates().get(0);

final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(nextCollectionDate.toInstant(),
this.timeZoneProvider.getTimeZone());
this.updateState(channel.getUID(), new DateTimeType(zonedDateTime));
this.updateState(channel.getUID(), new DateTimeType(nextCollectionDate.toInstant()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.scheduler.CronScheduler;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
Expand All @@ -40,27 +39,23 @@ public class AhaWasteCollectionHandlerFactory extends BaseThingHandlerFactory {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SCHEDULE);
private final CronScheduler scheduler;
private final TimeZoneProvider timeZoneProvider;

@Override
public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}

@Activate
public AhaWasteCollectionHandlerFactory(final @Reference CronScheduler scheduler,
final @Reference TimeZoneProvider timeZoneProvider) {
public AhaWasteCollectionHandlerFactory(final @Reference CronScheduler scheduler) {
this.scheduler = scheduler;
this.timeZoneProvider = timeZoneProvider;
}

@Override
protected @Nullable ThingHandler createHandler(final Thing thing) {
final ThingTypeUID thingTypeUID = thing.getThingTypeUID();

if (THING_TYPE_SCHEDULE.equals(thingTypeUID)) {
return new AhaWasteCollectionHandler(thing, this.scheduler, this.timeZoneProvider,
AhaCollectionScheduleImpl::new, null);
return new AhaWasteCollectionHandler(thing, this.scheduler, AhaCollectionScheduleImpl::new, null);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
Expand Down Expand Up @@ -136,15 +134,14 @@ private static AhaWasteCollectionHandler createAndInitHandler(final ThingHandler
}).when(executorStub).execute(any(Runnable.class));

final AhaWasteCollectionHandler handler = new AhaWasteCollectionHandler(thing, createStubScheduler(),
ZoneId::systemDefault, new AhaCollectionScheduleStubFactory(), executorStub);
new AhaCollectionScheduleStubFactory(), executorStub);
handler.setCallback(callback);
handler.initialize();
return handler;
}

private static State getDateTime(final Date day) {
final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(day.toInstant(), ZoneId.systemDefault());
return new DateTimeType(zonedDateTime);
return new DateTimeType(day.toInstant());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.openhab.binding.airquality.internal.handler.AirQualityBridgeHandler;
import org.openhab.binding.airquality.internal.handler.AirQualityStationHandler;
import org.openhab.core.i18n.LocationProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
Expand All @@ -43,13 +42,10 @@
public class AirQualityHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(BRIDGE_TYPE_API, THING_TYPE_STATION);

private final TimeZoneProvider timeZoneProvider;
private final LocationProvider locationProvider;

@Activate
public AirQualityHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider,
final @Reference LocationProvider locationProvider) {
this.timeZoneProvider = timeZoneProvider;
public AirQualityHandlerFactory(final @Reference LocationProvider locationProvider) {
this.locationProvider = locationProvider;
}

Expand All @@ -62,8 +58,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

return THING_TYPE_STATION.equals(thingTypeUID)
? new AirQualityStationHandler(thing, timeZoneProvider, locationProvider)
return THING_TYPE_STATION.equals(thingTypeUID) ? new AirQualityStationHandler(thing, locationProvider)
: BRIDGE_TYPE_API.equals(thingTypeUID) ? new AirQualityBridgeHandler((Bridge) thing) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.openhab.binding.airquality.internal.config.SensitiveGroupConfiguration;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.LocationProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
Expand Down Expand Up @@ -78,14 +77,12 @@
public class AirQualityStationHandler extends BaseThingHandler {
private final @NonNullByDefault({}) ClassLoader classLoader = AirQualityStationHandler.class.getClassLoader();
private final Logger logger = LoggerFactory.getLogger(AirQualityStationHandler.class);
private final TimeZoneProvider timeZoneProvider;
private final LocationProvider locationProvider;

private @Nullable ScheduledFuture<?> refreshJob;

public AirQualityStationHandler(Thing thing, TimeZoneProvider timeZoneProvider, LocationProvider locationProvider) {
public AirQualityStationHandler(Thing thing, LocationProvider locationProvider) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
this.locationProvider = locationProvider;
}

Expand Down Expand Up @@ -263,9 +260,7 @@ private State getValue(String channelId, @Nullable String groupId, AirQualityDat
return hum != -1 ? new QuantityType<>(hum, Units.PERCENT) : UnDefType.NULL;
case TIMESTAMP:
AirQualityTime time = data.getTime();
return time != null
? new DateTimeType(time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone()))
: UnDefType.NULL;
return time != null ? new DateTimeType(time.getObservationTime()) : UnDefType.NULL;
case DOMINENT:
return new StringType(data.getDominentPol());
case DEW_POINT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openhab.binding.automower.internal.things.AutomowerHandler;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -56,14 +55,12 @@ public class AutomowerHandlerFactory extends BaseThingHandlerFactory {
private final OAuthFactory oAuthFactory;
protected final @NonNullByDefault({}) HttpClient httpClient;
private @Nullable ServiceRegistration<?> automowerDiscoveryServiceRegistration;
private final TimeZoneProvider timeZoneProvider;

@Activate
public AutomowerHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory,
@Reference TimeZoneProvider timeZoneProvider) {
public AutomowerHandlerFactory(@Reference OAuthFactory oAuthFactory,
@Reference HttpClientFactory httpClientFactory) {
this.oAuthFactory = oAuthFactory;
this.httpClient = httpClientFactory.getCommonHttpClient();
this.timeZoneProvider = timeZoneProvider;
}

@Override
Expand All @@ -80,7 +77,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
}

if (AutomowerHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new AutomowerHandler(thing, timeZoneProvider);
return new AutomowerHandler(thing);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.*;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
Expand All @@ -36,7 +35,6 @@
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.RestrictedReason;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.State;
import org.openhab.binding.automower.internal.rest.exceptions.AutomowerCommunicationException;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.PointType;
Expand Down Expand Up @@ -76,7 +74,6 @@ public class AutomowerHandler extends BaseThingHandler {
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.MINUTES.toSeconds(10);

private final Logger logger = LoggerFactory.getLogger(AutomowerHandler.class);
private final TimeZoneProvider timeZoneProvider;

private AtomicReference<String> automowerId = new AtomicReference<>(NO_ID);
private long lastQueryTimeMs = 0L;
Expand All @@ -97,9 +94,8 @@ public class AutomowerHandler extends BaseThingHandler {
}
};

public AutomowerHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
public AutomowerHandler(Thing thing) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
}

@Override
Expand Down Expand Up @@ -287,7 +283,7 @@ private void updateChannelState(@Nullable Mower mower) {
}

updateState(CHANNEL_STATUS_LAST_UPDATE,
new DateTimeType(toZonedDateTime(mower.getAttributes().getMetadata().getStatusTimestamp())));
new DateTimeType(Instant.ofEpochMilli(mower.getAttributes().getMetadata().getStatusTimestamp())));
updateState(CHANNEL_STATUS_BATTERY,
new QuantityType<>(mower.getAttributes().getBattery().getBatteryPercent(), Units.PERCENT));

Expand All @@ -297,15 +293,15 @@ private void updateChannelState(@Nullable Mower mower) {
if (errorCodeTimestamp == 0L) {
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, UnDefType.NULL);
} else {
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, new DateTimeType(toZonedDateTime(errorCodeTimestamp)));
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, new DateTimeType(Instant.ofEpochMilli(errorCodeTimestamp)));
}

long nextStartTimestamp = mower.getAttributes().getPlanner().getNextStartTimestamp();
// If next start timestamp is 0 it means the mower should start now, so using current timestamp
if (nextStartTimestamp == 0L) {
updateState(CHANNEL_PLANNER_NEXT_START, UnDefType.NULL);
} else {
updateState(CHANNEL_PLANNER_NEXT_START, new DateTimeType(toZonedDateTime(nextStartTimestamp)));
updateState(CHANNEL_PLANNER_NEXT_START, new DateTimeType(Instant.ofEpochMilli(nextStartTimestamp)));
}
updateState(CHANNEL_PLANNER_OVERRIDE_ACTION,
new StringType(mower.getAttributes().getPlanner().getOverride().getAction()));
Expand Down Expand Up @@ -339,18 +335,4 @@ private void initializeProperties(@Nullable Mower mower) {

updateProperties(properties);
}

/**
* Converts timestamp returned by the Automower API into local time-zone.
* Timestamp returned by the API doesn't have offset and it always in the current time zone - it can be treated as
* UTC.
* Method builds a ZonedDateTime with same hour value but in the current system timezone.
*
* @param timestamp - Automower API timestamp
* @return ZonedDateTime in system timezone
*/
private ZonedDateTime toZonedDateTime(long timestamp) {
Instant timestampInstant = Instant.ofEpochMilli(timestamp);
return ZonedDateTime.ofInstant(timestampInstant, timeZoneProvider.getTimeZone());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Map;

Expand Down Expand Up @@ -314,9 +313,8 @@ private void updateHeatingThermostat(@Nullable HeatingModel heatingModel) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -189,13 +187,11 @@ private void updateButton(ButtonModel buttonModel, String event, @Nullable Strin
: 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;

Expand All @@ -47,10 +46,6 @@ public static ZonedDateTime getCalendarForHour(int hour, ZoneId zone) {
return ZonedDateTime.now(zone).truncatedTo(ChronoUnit.DAYS).plusHours(hour);
}

public static DateTimeType getDateTimeType(long time, TimeZoneProvider tz) {
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), tz.getTimeZone()));
}

public static QuantityType<Time> getDuration(long millis) {
long minutes = millis / 60000;
return QuantityType.valueOf(minutes, Units.MINUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_REMAINING;
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_START;
import static org.openhab.binding.awattar.internal.AwattarUtil.getCalendarForHour;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDateTimeType;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDuration;
import static org.openhab.binding.awattar.internal.AwattarUtil.getMillisToNextMinute;

Expand All @@ -41,6 +40,7 @@
import org.openhab.binding.awattar.internal.AwattarNonConsecutiveBestPriceResult;
import org.openhab.binding.awattar.internal.AwattarPrice;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
Expand Down Expand Up @@ -166,10 +166,10 @@ public void refreshChannel(ChannelUID channelUID) {
state = OnOffType.from(result.isActive());
break;
case CHANNEL_START:
state = getDateTimeType(result.getStart(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getStart()));
break;
case CHANNEL_END:
state = getDateTimeType(result.getEnd(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getEnd()));
break;
case CHANNEL_COUNTDOWN:
diff = result.getStart() - Instant.now().toEpochMilli();
Expand Down
Loading