diff --git a/bundles/org.openhab.binding.netatmo/.classpath b/bundles/org.openhab.binding.netatmo/.classpath
index a5d95095ccaaf..38182156285cb 100644
--- a/bundles/org.openhab.binding.netatmo/.classpath
+++ b/bundles/org.openhab.binding.netatmo/.classpath
@@ -6,6 +6,7 @@
+
@@ -13,9 +14,9 @@
+
-
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/ChannelTypeUtils.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/ChannelTypeUtils.java
index 3217ce919279a..f0043503f9b0e 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/ChannelTypeUtils.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/ChannelTypeUtils.java
@@ -43,17 +43,17 @@ public static State toStringType(@Nullable String value) {
return (value == null) ? UnDefType.NULL : new StringType(value);
}
- public static ZonedDateTime toZonedDateTime(Integer netatmoTS) {
+ public static ZonedDateTime toZonedDateTime(Integer netatmoTS, ZoneId zoneId) {
Instant i = Instant.ofEpochSecond(netatmoTS);
- return ZonedDateTime.ofInstant(i, ZoneId.systemDefault());
+ return ZonedDateTime.ofInstant(i, zoneId);
}
- public static State toDateTimeType(@Nullable Float netatmoTS) {
- return netatmoTS == null ? UnDefType.NULL : toDateTimeType(toZonedDateTime(netatmoTS.intValue()));
+ public static State toDateTimeType(@Nullable Float netatmoTS, ZoneId zoneId) {
+ return netatmoTS == null ? UnDefType.NULL : toDateTimeType(toZonedDateTime(netatmoTS.intValue(), zoneId));
}
- public static State toDateTimeType(@Nullable Integer netatmoTS) {
- return netatmoTS == null ? UnDefType.NULL : toDateTimeType(toZonedDateTime(netatmoTS));
+ public static State toDateTimeType(@Nullable Integer netatmoTS, ZoneId zoneId) {
+ return netatmoTS == null ? UnDefType.NULL : toDateTimeType(toZonedDateTime(netatmoTS, zoneId));
}
public static State toDateTimeType(@Nullable ZonedDateTime zonedDateTime) {
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoHandlerFactory.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoHandlerFactory.java
index 870f6a83ab142..fb508ea07f401 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoHandlerFactory.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoHandlerFactory.java
@@ -23,6 +23,7 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.discovery.DiscoveryService;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
@@ -66,12 +67,15 @@ public class NetatmoHandlerFactory extends BaseThingHandlerFactory {
private final Map> webHookServiceRegs = new HashMap<>();
private final HttpService httpService;
private final NATherm1StateDescriptionProvider stateDescriptionProvider;
+ private final TimeZoneProvider timeZoneProvider;
@Activate
public NetatmoHandlerFactory(final @Reference HttpService httpService,
- final @Reference NATherm1StateDescriptionProvider stateDescriptionProvider) {
+ final @Reference NATherm1StateDescriptionProvider stateDescriptionProvider,
+ final @Reference TimeZoneProvider timeZoneProvider) {
this.httpService = httpService;
this.stateDescriptionProvider = stateDescriptionProvider;
+ this.timeZoneProvider = timeZoneProvider;
}
@Override
@@ -88,27 +92,27 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
registerDeviceDiscoveryService(bridgeHandler);
return bridgeHandler;
} else if (thingTypeUID.equals(MODULE1_THING_TYPE)) {
- return new NAModule1Handler(thing);
+ return new NAModule1Handler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(MODULE2_THING_TYPE)) {
- return new NAModule2Handler(thing);
+ return new NAModule2Handler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(MODULE3_THING_TYPE)) {
- return new NAModule3Handler(thing);
+ return new NAModule3Handler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(MODULE4_THING_TYPE)) {
- return new NAModule4Handler(thing);
+ return new NAModule4Handler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(MAIN_THING_TYPE)) {
- return new NAMainHandler(thing);
+ return new NAMainHandler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(HOMECOACH_THING_TYPE)) {
- return new NAHealthyHomeCoachHandler(thing);
+ return new NAHealthyHomeCoachHandler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(PLUG_THING_TYPE)) {
- return new NAPlugHandler(thing);
+ return new NAPlugHandler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(THERM1_THING_TYPE)) {
- return new NATherm1Handler(thing, stateDescriptionProvider);
+ return new NATherm1Handler(thing, stateDescriptionProvider, timeZoneProvider);
} else if (thingTypeUID.equals(WELCOME_HOME_THING_TYPE)) {
- return new NAWelcomeHomeHandler(thing);
+ return new NAWelcomeHomeHandler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(WELCOME_CAMERA_THING_TYPE) || thingTypeUID.equals(PRESENCE_CAMERA_THING_TYPE)) {
- return new NAWelcomeCameraHandler(thing);
+ return new NAWelcomeCameraHandler(thing, timeZoneProvider);
} else if (thingTypeUID.equals(WELCOME_PERSON_THING_TYPE)) {
- return new NAWelcomePersonHandler(thing);
+ return new NAWelcomePersonHandler(thing, timeZoneProvider);
} else {
logger.warn("ThingHandler not found for {}", thing.getThingTypeUID());
return null;
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/RefreshStrategy.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/RefreshStrategy.java
index 797334daa7242..3e540fc0d3409 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/RefreshStrategy.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/RefreshStrategy.java
@@ -12,6 +12,7 @@
*/
package org.openhab.binding.netatmo.internal;
+import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
@@ -57,7 +58,7 @@ public RefreshStrategy(int dataValidityPeriod) {
}
@SuppressWarnings("null")
- public void setDataTimeStamp(Integer dataTimestamp) {
+ public void setDataTimeStamp(Integer dataTimestamp, ZoneId zoneId) {
if (searchRefreshInterval) {
if (dataTimestamp0 == null) {
dataTimestamp0 = dataTimestamp;
@@ -70,7 +71,7 @@ public void setDataTimeStamp(Integer dataTimestamp) {
logger.debug("Data validity period not yet found - data timestamp unchanged");
}
}
- this.dataTimeStamp = ChannelTypeUtils.toZonedDateTime(dataTimestamp).toInstant().toEpochMilli();
+ this.dataTimeStamp = ChannelTypeUtils.toZonedDateTime(dataTimestamp, zoneId).toInstant().toEpochMilli();
}
public long dataAge() {
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/camera/CameraHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/camera/CameraHandler.java
index b86f06d875379..300c93c198a4b 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/camera/CameraHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/camera/CameraHandler.java
@@ -12,11 +12,11 @@
*/
package org.openhab.binding.netatmo.internal.camera;
-import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.toOnOffType;
-import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.toStringType;
+import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
@@ -37,8 +37,8 @@ public class CameraHandler extends NetatmoModuleHandler {
private static final String LIVE_PICTURE = "/live/snapshot_720.jpg";
- public CameraHandler(@NonNull Thing thing) {
- super(thing);
+ public CameraHandler(@NonNull Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/AbstractNetatmoThingHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/AbstractNetatmoThingHandler.java
index 74266f326f9b7..e6dc8117da4bf 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/AbstractNetatmoThingHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/AbstractNetatmoThingHandler.java
@@ -30,9 +30,15 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.unit.SIUnits;
import org.eclipse.smarthome.core.library.unit.SmartHomeUnits;
-import org.eclipse.smarthome.core.thing.*;
+import org.eclipse.smarthome.core.thing.Bridge;
+import org.eclipse.smarthome.core.thing.ChannelUID;
+import org.eclipse.smarthome.core.thing.Thing;
+import org.eclipse.smarthome.core.thing.ThingStatus;
+import org.eclipse.smarthome.core.thing.ThingStatusDetail;
+import org.eclipse.smarthome.core.thing.ThingStatusInfo;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.thing.binding.BridgeHandler;
import org.eclipse.smarthome.core.thing.type.ChannelKind;
@@ -66,14 +72,16 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
public static final Unit API_CO2_UNIT = SmartHomeUnits.PARTS_PER_MILLION;
public static final Unit API_NOISE_UNIT = SmartHomeUnits.DECIBEL;
+ protected final TimeZoneProvider timeZoneProvider;
protected final MeasurableChannels measurableChannels = new MeasurableChannels();
protected Optional radioHelper;
protected Optional batteryHelper;
protected Configuration config;
protected NetatmoBridgeHandler bridgeHandler;
- AbstractNetatmoThingHandler(@NonNull Thing thing) {
+ AbstractNetatmoThingHandler(@NonNull Thing thing, final TimeZoneProvider timeZoneProvider) {
super(thing);
+ this.timeZoneProvider = timeZoneProvider;
}
@Override
@@ -141,14 +149,14 @@ private void updateDataChannels() {
getThing().getChannels().stream().filter(channel -> !channel.getKind().equals(ChannelKind.TRIGGER))
.forEach(channel -> {
- String channelId = channel.getUID().getId();
- if (isLinked(channelId)) {
- State state = getNAThingProperty(channelId);
- if (state != null) {
- updateState(channel.getUID(), state);
- }
- }
- });
+ String channelId = channel.getUID().getId();
+ if (isLinked(channelId)) {
+ State state = getNAThingProperty(channelId);
+ if (state != null) {
+ updateState(channel.getUID(), state);
+ }
+ }
+ });
}
/**
@@ -162,6 +170,7 @@ private void triggerEventChannels() {
/**
* Triggers the trigger channel with the given channel id when required (when an update is available)
+ *
* @param channelId channel id
*/
protected void triggerChannelIfRequired(@NonNull String channelId) {
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoDeviceHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoDeviceHandler.java
index bbc53664708c6..dccc175b69895 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoDeviceHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoDeviceHandler.java
@@ -25,6 +25,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.PointType;
import org.eclipse.smarthome.core.thing.Thing;
@@ -55,8 +56,8 @@ public abstract class NetatmoDeviceHandler extends AbstractNetatmoThingH
protected DEVICE device;
protected Map childs = new ConcurrentHashMap<>();
- public NetatmoDeviceHandler(Thing thing) {
- super(thing);
+ public NetatmoDeviceHandler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -123,7 +124,7 @@ protected void updateChannels() {
updateProperties(device);
Integer dataTimeStamp = getDataTimestamp();
if (dataTimeStamp != null) {
- refreshStrategy.setDataTimeStamp(dataTimeStamp);
+ refreshStrategy.setDataTimeStamp(dataTimeStamp, timeZoneProvider.getTimeZone());
}
radioHelper.ifPresent(helper -> helper.setModule(device));
NetatmoBridgeHandler handler = getBridgeHandler();
@@ -156,7 +157,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
if (device != null) {
Method getLastStatusStore = device.getClass().getMethod("getLastStatusStore");
Integer lastStatusStore = (Integer) getLastStatusStore.invoke(device);
- return ChannelTypeUtils.toDateTimeType(lastStatusStore);
+ return ChannelTypeUtils.toDateTimeType(lastStatusStore, timeZoneProvider.getTimeZone());
} else {
return UnDefType.UNDEF;
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoModuleHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoModuleHandler.java
index fd0a628c892c4..d6a6b963c1a05 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoModuleHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoModuleHandler.java
@@ -22,6 +22,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.types.State;
@@ -43,8 +44,8 @@ public class NetatmoModuleHandler extends AbstractNetatmoThingHandler {
protected MODULE module;
private boolean refreshRequired;
- protected NetatmoModuleHandler(Thing thing) {
- super(thing);
+ protected NetatmoModuleHandler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -77,7 +78,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
if (channelId.equalsIgnoreCase(CHANNEL_LAST_MESSAGE) && module != null) {
Method getLastMessage = module.getClass().getMethod("getLastMessage");
Integer lastMessage = (Integer) getLastMessage.invoke(module);
- return ChannelTypeUtils.toDateTimeType(lastMessage);
+ return ChannelTypeUtils.toDateTimeType(lastMessage, timeZoneProvider.getTimeZone());
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/homecoach/NAHealthyHomeCoachHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/homecoach/NAHealthyHomeCoachHandler.java
index f76e3d77917e1..ad28e769347d1 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/homecoach/NAHealthyHomeCoachHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/homecoach/NAHealthyHomeCoachHandler.java
@@ -17,6 +17,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.handler.NetatmoDeviceHandler;
@@ -33,8 +34,8 @@
*/
public class NAHealthyHomeCoachHandler extends NetatmoDeviceHandler {
- public NAHealthyHomeCoachHandler(@NonNull Thing thing) {
- super(thing);
+ public NAHealthyHomeCoachHandler(@NonNull Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -78,11 +79,11 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_ABSOLUTE_PRESSURE:
return toQuantityType(dashboardData.getAbsolutePressure(), API_PRESSURE_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MIN_TEMP:
- return toDateTimeType(dashboardData.getDateMinTemp());
+ return toDateTimeType(dashboardData.getDateMinTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MAX_TEMP:
- return toDateTimeType(dashboardData.getDateMaxTemp());
+ return toDateTimeType(dashboardData.getDateMaxTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_HUMIDITY:
return toQuantityType(dashboardData.getHumidity(), API_HUMIDITY_UNIT);
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAMainHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAMainHandler.java
index 15814e3470b1e..8f4643e2f3664 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAMainHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAMainHandler.java
@@ -23,6 +23,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.WeatherUtils;
@@ -45,8 +46,8 @@
public class NAMainHandler extends NetatmoDeviceHandler {
private Map channelMeasurements = new ConcurrentHashMap<>();
- public NAMainHandler(Thing thing) {
- super(thing);
+ public NAMainHandler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -190,11 +191,11 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_ABSOLUTE_PRESSURE:
return toQuantityType(dashboardData.getAbsolutePressure(), API_PRESSURE_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MIN_TEMP:
- return toDateTimeType(dashboardData.getDateMinTemp());
+ return toDateTimeType(dashboardData.getDateMinTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MAX_TEMP:
- return toDateTimeType(dashboardData.getDateMaxTemp());
+ return toDateTimeType(dashboardData.getDateMaxTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_HUMIDITY:
return toQuantityType(dashboardData.getHumidity(), API_HUMIDITY_UNIT);
case CHANNEL_HUMIDEX:
@@ -279,7 +280,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_DATE_MIN_TEMP_THIS_MONTH:
case CHANNEL_DATE_MAX_TEMP_THIS_WEEK:
case CHANNEL_DATE_MAX_TEMP_THIS_MONTH:
- return toDateTimeType(channelMeasurements.get(channelId));
+ return toDateTimeType(channelMeasurements.get(channelId), timeZoneProvider.getTimeZone());
}
return super.getNAThingProperty(channelId);
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule1Handler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule1Handler.java
index e7243d808f9de..42f534ac53ffe 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule1Handler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule1Handler.java
@@ -21,6 +21,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.WeatherUtils;
@@ -40,8 +41,8 @@
public class NAModule1Handler extends NetatmoModuleHandler {
private Map channelMeasurements = new ConcurrentHashMap<>();
- public NAModule1Handler(Thing thing) {
- super(thing);
+ public NAModule1Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -112,9 +113,9 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_TEMPERATURE:
return toQuantityType(dashboardData.getTemperature(), API_TEMPERATURE_UNIT);
case CHANNEL_DATE_MIN_TEMP:
- return toDateTimeType(dashboardData.getDateMinTemp());
+ return toDateTimeType(dashboardData.getDateMinTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MAX_TEMP:
- return toDateTimeType(dashboardData.getDateMaxTemp());
+ return toDateTimeType(dashboardData.getDateMaxTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_MIN_TEMP:
return toQuantityType(dashboardData.getMinTemp(), API_TEMPERATURE_UNIT);
case CHANNEL_MAX_TEMP:
@@ -122,7 +123,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_HUMIDITY:
return toQuantityType(dashboardData.getHumidity(), API_HUMIDITY_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
case CHANNEL_HUMIDEX:
return toDecimalType(
WeatherUtils.getHumidex(dashboardData.getTemperature(), dashboardData.getHumidity()));
@@ -166,7 +167,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_DATE_MIN_TEMP_THIS_MONTH:
case CHANNEL_DATE_MAX_TEMP_THIS_WEEK:
case CHANNEL_DATE_MAX_TEMP_THIS_MONTH:
- return toDateTimeType(channelMeasurements.get(channelId));
+ return toDateTimeType(channelMeasurements.get(channelId), timeZoneProvider.getTimeZone());
}
return super.getNAThingProperty(channelId);
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule2Handler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule2Handler.java
index 20cbd98f716b6..130ddda1ae640 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule2Handler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule2Handler.java
@@ -16,6 +16,7 @@
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler;
@@ -31,8 +32,8 @@
*/
public class NAModule2Handler extends NetatmoModuleHandler {
- public NAModule2Handler(Thing thing) {
- super(thing);
+ public NAModule2Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -55,11 +56,11 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_GUST_STRENGTH:
return toQuantityType(dashboardData.getGustStrength(), API_WIND_SPEED_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
case CHANNEL_MAX_WIND_STRENGTH:
return toQuantityType(dashboardData.getMaxWindStr(), API_WIND_SPEED_UNIT);
case CHANNEL_DATE_MAX_WIND_STRENGTH:
- return toDateTimeType(dashboardData.getDateMaxWindStr());
+ return toDateTimeType(dashboardData.getDateMaxWindStr(), timeZoneProvider.getTimeZone());
}
}
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule3Handler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule3Handler.java
index bf89553bfa597..614a2e4a27a12 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule3Handler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule3Handler.java
@@ -21,6 +21,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler;
@@ -39,8 +40,8 @@
public class NAModule3Handler extends NetatmoModuleHandler {
private Map channelMeasurements = new ConcurrentHashMap<>();
- public NAModule3Handler(Thing thing) {
- super(thing);
+ public NAModule3Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -76,7 +77,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_SUM_RAIN24:
return toQuantityType(dashboardData.getSumRain24(), API_RAIN_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
}
}
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule4Handler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule4Handler.java
index cea1c49479ae4..1ab0402116173 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule4Handler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/station/NAModule4Handler.java
@@ -21,6 +21,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.WeatherUtils;
@@ -40,8 +41,8 @@
public class NAModule4Handler extends NetatmoModuleHandler {
private Map channelMeasurements = new ConcurrentHashMap<>();
- public NAModule4Handler(Thing thing) {
- super(thing);
+ public NAModule4Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -126,15 +127,15 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_TEMPERATURE:
return toQuantityType(dashboardData.getTemperature(), API_TEMPERATURE_UNIT);
case CHANNEL_DATE_MIN_TEMP:
- return toDateTimeType(dashboardData.getDateMinTemp());
+ return toDateTimeType(dashboardData.getDateMinTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_DATE_MAX_TEMP:
- return toDateTimeType(dashboardData.getDateMaxTemp());
+ return toDateTimeType(dashboardData.getDateMaxTemp(), timeZoneProvider.getTimeZone());
case CHANNEL_MIN_TEMP:
return toQuantityType(dashboardData.getMinTemp(), API_TEMPERATURE_UNIT);
case CHANNEL_MAX_TEMP:
return toQuantityType(dashboardData.getMaxTemp(), API_TEMPERATURE_UNIT);
case CHANNEL_TIMEUTC:
- return toDateTimeType(dashboardData.getTimeUtc());
+ return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
case CHANNEL_HUMIDITY:
return toQuantityType(dashboardData.getHumidity(), API_HUMIDITY_UNIT);
case CHANNEL_HUMIDEX:
@@ -193,7 +194,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_DATE_MIN_TEMP_THIS_MONTH:
case CHANNEL_DATE_MAX_TEMP_THIS_WEEK:
case CHANNEL_DATE_MAX_TEMP_THIS_MONTH:
- return toDateTimeType(channelMeasurements.get(channelId));
+ return toDateTimeType(channelMeasurements.get(channelId), timeZoneProvider.getTimeZone());
}
return super.getNAThingProperty(channelId);
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NAPlugHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NAPlugHandler.java
index c551ce2b93b00..e49e88c60da5e 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NAPlugHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NAPlugHandler.java
@@ -20,6 +20,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
@@ -38,8 +39,8 @@
*/
public class NAPlugHandler extends NetatmoDeviceHandler {
- public NAPlugHandler(@NonNull Thing thing) {
- super(thing);
+ public NAPlugHandler(@NonNull Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
@@ -67,7 +68,8 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_CONNECTED_BOILER:
return device != null ? toOnOffType(device.getPlugConnectedBoiler()) : UnDefType.UNDEF;
case CHANNEL_LAST_PLUG_SEEN:
- return device != null ? toDateTimeType(device.getLastPlugSeen()) : UnDefType.UNDEF;
+ return device != null ? toDateTimeType(device.getLastPlugSeen(), timeZoneProvider.getTimeZone())
+ : UnDefType.UNDEF;
case CHANNEL_LAST_BILAN:
return toDateTimeType(getLastBilan());
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NATherm1Handler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NATherm1Handler.java
index fc59b026d6d18..2b3effafd8199 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NATherm1Handler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/thermostat/NATherm1Handler.java
@@ -26,6 +26,7 @@
import javax.measure.quantity.Temperature;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.types.StringType;
@@ -62,8 +63,9 @@ public class NATherm1Handler extends NetatmoModuleHandler {
private final Logger logger = LoggerFactory.getLogger(NATherm1Handler.class);
private final NATherm1StateDescriptionProvider stateDescriptionProvider;
- public NATherm1Handler(@NonNull Thing thing, NATherm1StateDescriptionProvider stateDescriptionProvider) {
- super(thing);
+ public NATherm1Handler(@NonNull Thing thing, NATherm1StateDescriptionProvider stateDescriptionProvider,
+ final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
this.stateDescriptionProvider = stateDescriptionProvider;
}
@@ -113,7 +115,8 @@ protected State getNAThingProperty(@NonNull String channelId) {
case CHANNEL_SETPOINT_TEMP:
return getCurrentSetpoint();
case CHANNEL_TIMEUTC:
- return module != null ? toDateTimeType(module.getMeasured().getTime()) : UnDefType.UNDEF;
+ return module != null ? toDateTimeType(module.getMeasured().getTime(), timeZoneProvider.getTimeZone())
+ : UnDefType.UNDEF;
case CHANNEL_SETPOINT_END_TIME: {
if (module != null) {
NASetpoint setpoint = module.getSetpoint();
@@ -122,7 +125,7 @@ protected State getNAThingProperty(@NonNull String channelId) {
if (endTime == null) {
endTime = getNextProgramTime(module.getThermProgramList());
}
- return toDateTimeType(endTime);
+ return toDateTimeType(endTime, timeZoneProvider.getTimeZone());
}
return UnDefType.NULL;
}
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeCameraHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeCameraHandler.java
index 385d00094b08b..4b2a22d095d42 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeCameraHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeCameraHandler.java
@@ -15,6 +15,7 @@
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.netatmo.internal.camera.CameraHandler;
@@ -27,8 +28,8 @@
*/
public class NAWelcomeCameraHandler extends CameraHandler {
- public NAWelcomeCameraHandler(@NonNull Thing thing) {
- super(thing);
+ public NAWelcomeCameraHandler(@NonNull Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@SuppressWarnings("null")
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeHomeHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeHomeHandler.java
index fb593238aa22e..9c39152311344 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeHomeHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomeHomeHandler.java
@@ -15,12 +15,16 @@
import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Optional;
+import java.util.Set;
+import java.util.TreeSet;
import java.util.function.Function;
-import io.swagger.client.model.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Thing;
@@ -34,6 +38,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import io.swagger.client.model.NAWelcomeEvent;
+import io.swagger.client.model.NAWelcomeHome;
+import io.swagger.client.model.NAWelcomeHomeData;
+import io.swagger.client.model.NAWelcomePlace;
+import io.swagger.client.model.NAWelcomeSnapshot;
+import io.swagger.client.model.NAWelcomeSubEvent;
+
/**
* {@link NAWelcomeHomeHandler} is the class used to handle the Welcome Home Data
*
@@ -51,13 +62,14 @@ public class NAWelcomeHomeHandler extends NetatmoDeviceHandler {
private boolean isNewLastEvent;
private @Nullable Integer dataTimeStamp;
- public NAWelcomeHomeHandler(Thing thing) {
- super(thing);
+ public NAWelcomeHomeHandler(Thing thing, final TimeZoneProvider timeZoneProvider) {
+ super(thing, timeZoneProvider);
}
@Override
protected @Nullable NAWelcomeHome updateReadings() {
- @Nullable NAWelcomeHome result = null;
+ @Nullable
+ NAWelcomeHome result = null;
NAWelcomeHomeData homeDataBody = getBridgeHandler().getWelcomeDataBody(getId());
if (homeDataBody != null) {
// data time stamp is updated to now as WelcomeDataBody does not provide any information according to this
@@ -106,7 +118,8 @@ protected State getNAThingProperty(String channelId) {
case CHANNEL_WELCOME_EVENT_TYPE:
return lastEvent.map(e -> toStringType(e.getType())).orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_TIME:
- return lastEvent.map(e -> toDateTimeType(e.getTime())).orElse(UnDefType.UNDEF);
+ return lastEvent.map(e -> toDateTimeType(e.getTime(), timeZoneProvider.getTimeZone()))
+ .orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_CAMERAID:
if (lastEvent.isPresent()) {
Optional camera = getBridgeHandler()
@@ -124,7 +137,7 @@ protected State getNAThingProperty(String channelId) {
return UnDefType.UNDEF;
}
case CHANNEL_WELCOME_EVENT_SNAPSHOT:
- return findSnapshotURL().map(url -> (State)HttpUtil.downloadImage(url)).orElse(UnDefType.UNDEF);
+ return findSnapshotURL().map(url -> (State) HttpUtil.downloadImage(url)).orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_SNAPSHOT_URL:
return findSnapshotURL().map(ChannelTypeUtils::toStringType).orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_VIDEO_URL:
@@ -145,9 +158,8 @@ protected State getNAThingProperty(String channelId) {
case CHANNEL_WELCOME_EVENT_ISARRIVAL:
return lastEvent.map(e -> toOnOffType(e.getIsArrival())).orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_MESSAGE:
- return findEventMessage().map(
- m -> (State)new StringType(m.replace("", "").replace("", ""))
- ).orElse(UnDefType.UNDEF);
+ return findEventMessage().map(m -> (State) new StringType(m.replace("", "").replace("", "")))
+ .orElse(UnDefType.UNDEF);
case CHANNEL_WELCOME_EVENT_SUBTYPE:
return lastEvent.map(e -> toDecimalType(e.getSubType())).orElse(UnDefType.UNDEF);
}
@@ -189,7 +201,8 @@ private static Set findDetectedObjectTypes(Optional even
private Optional findEventMessage() {
if (lastEvent.isPresent()) {
- @Nullable String message = lastEvent.get().getMessage();
+ @Nullable
+ String message = lastEvent.get().getMessage();
if (message != null) {
return Optional.of(message);
}
@@ -206,7 +219,8 @@ private Optional findEventMessage() {
*/
protected Optional findSnapshotURL() {
if (lastEvent.isPresent()) {
- @Nullable NAWelcomeSnapshot snapshot = lastEvent.get().getSnapshot();
+ @Nullable
+ NAWelcomeSnapshot snapshot = lastEvent.get().getSnapshot();
if (snapshot == null) {
snapshot = findFirstSubEvent(lastEvent).map(NAWelcomeSubEvent::getSnapshot).orElse(null);
}
@@ -227,9 +241,8 @@ protected Optional findSnapshotURL() {
}
private State getPlaceInfo(Function infoGetFunction) {
- return Optional.ofNullable(device).map(
- d -> toStringType(infoGetFunction.apply(d.getPlace()))
- ).orElse(UnDefType.UNDEF);
+ return Optional.ofNullable(device).map(d -> toStringType(infoGetFunction.apply(d.getPlace())))
+ .orElse(UnDefType.UNDEF);
}
private static Optional findFirstSubEvent(Optional event) {
diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomePersonHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomePersonHandler.java
index 580024c51aed8..7797134ce97d8 100644
--- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomePersonHandler.java
+++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomePersonHandler.java
@@ -18,6 +18,7 @@
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
@@ -43,8 +44,8 @@ public class NAWelcomePersonHandler extends NetatmoModuleHandler", "").replace("", ""))
: UnDefType.UNDEF;
case CHANNEL_WELCOME_PERSON_LASTTIME:
- return lastEvent != null ? toDateTimeType(lastEvent.getTime()) : UnDefType.UNDEF;
+ return lastEvent != null ? toDateTimeType(lastEvent.getTime(), timeZoneProvider.getTimeZone())
+ : UnDefType.UNDEF;
case CHANNEL_WELCOME_PERSON_LASTEVENT:
return getLastEventURL() != null ? HttpUtil.downloadImage(getLastEventURL()) : UnDefType.UNDEF;
case CHANNEL_WELCOME_PERSON_LASTEVENT_URL: