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