mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Meater
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
7f3138585a
commit
2f33a2d1ae
@ -15,14 +15,12 @@ package org.openhab.binding.meater.internal.handler;
|
||||
import static org.openhab.binding.meater.internal.MeaterBindingConstants.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.meater.internal.MeaterConfiguration;
|
||||
import org.openhab.binding.meater.internal.dto.MeaterProbeDTO.Cook;
|
||||
import org.openhab.binding.meater.internal.dto.MeaterProbeDTO.Device;
|
||||
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.types.StringType;
|
||||
@ -49,11 +47,9 @@ import org.openhab.core.types.UnDefType;
|
||||
public class MeaterHandler extends BaseThingHandler {
|
||||
|
||||
private String deviceId = "";
|
||||
private TimeZoneProvider timeZoneProvider;
|
||||
|
||||
public MeaterHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
|
||||
public MeaterHandler(Thing thing) {
|
||||
super(thing);
|
||||
this.timeZoneProvider = timeZoneProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,14 +143,13 @@ public class MeaterHandler extends BaseThingHandler {
|
||||
case CHANNEL_LAST_CONNECTION:
|
||||
Instant instant = meaterProbe.getLastConnection();
|
||||
if (instant != null) {
|
||||
return new DateTimeType(ZonedDateTime.ofInstant(instant, timeZoneProvider.getTimeZone()));
|
||||
return new DateTimeType(instant);
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COOK_ESTIMATED_END_TIME:
|
||||
if (cook != null) {
|
||||
if (cook.time.remaining > -1) {
|
||||
return new DateTimeType(
|
||||
ZonedDateTime.now(timeZoneProvider.getTimeZone()).plusSeconds(cook.time.remaining));
|
||||
return new DateTimeType(Instant.now().plusSeconds(cook.time.remaining));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.openhab.core.i18n.LocaleProvider;
|
||||
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;
|
||||
@ -49,13 +48,11 @@ public class MeaterHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private final Gson gson;
|
||||
private final HttpClient httpClient;
|
||||
private final TimeZoneProvider timeZoneProvider;
|
||||
private final LocaleProvider localeProvider;
|
||||
|
||||
@Activate
|
||||
public MeaterHandlerFactory(@Reference TimeZoneProvider timeZoneProvider, @Reference LocaleProvider localeProvider,
|
||||
public MeaterHandlerFactory(@Reference LocaleProvider localeProvider,
|
||||
@Reference HttpClientFactory httpClientFactory) {
|
||||
this.timeZoneProvider = timeZoneProvider;
|
||||
this.localeProvider = localeProvider;
|
||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||
this.gson = new Gson();
|
||||
@ -71,7 +68,7 @@ public class MeaterHandlerFactory extends BaseThingHandlerFactory {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
if (THING_TYPE_MEATER_PROBE.equals(thingTypeUID)) {
|
||||
return new MeaterHandler(thing, timeZoneProvider);
|
||||
return new MeaterHandler(thing);
|
||||
} else if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
|
||||
return new MeaterBridgeHandler((Bridge) thing, httpClient, gson, localeProvider);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user