diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/factory/OpenWeatherMapHandlerFactory.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/factory/OpenWeatherMapHandlerFactory.java index 2432169ac2d66..5ed9721c1d34d 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/factory/OpenWeatherMapHandlerFactory.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/factory/OpenWeatherMapHandlerFactory.java @@ -28,6 +28,7 @@ import org.eclipse.smarthome.config.discovery.DiscoveryService; import org.eclipse.smarthome.core.i18n.LocaleProvider; import org.eclipse.smarthome.core.i18n.LocationProvider; +import org.eclipse.smarthome.core.i18n.TimeZoneProvider; import org.eclipse.smarthome.core.i18n.TranslationProvider; import org.eclipse.smarthome.core.thing.Bridge; import org.eclipse.smarthome.core.thing.Thing; @@ -65,15 +66,17 @@ public class OpenWeatherMapHandlerFactory extends BaseThingHandlerFactory { private final LocaleProvider localeProvider; private final LocationProvider locationProvider; private final TranslationProvider i18nProvider; + private final TimeZoneProvider timeZoneProvider; @Activate public OpenWeatherMapHandlerFactory(final @Reference HttpClientFactory httpClientFactory, final @Reference LocaleProvider localeProvider, final @Reference LocationProvider locationProvider, - final @Reference TranslationProvider i18nProvider) { + final @Reference TranslationProvider i18nProvider, final @Reference TimeZoneProvider timeZoneProvider) { this.httpClient = httpClientFactory.getCommonHttpClient(); this.localeProvider = localeProvider; this.locationProvider = locationProvider; this.i18nProvider = i18nProvider; + this.timeZoneProvider = timeZoneProvider; } @Override @@ -94,9 +97,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { .registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>())); return handler; } else if (THING_TYPE_WEATHER_AND_FORECAST.equals(thingTypeUID)) { - return new OpenWeatherMapWeatherAndForecastHandler(thing); + return new OpenWeatherMapWeatherAndForecastHandler(thing, timeZoneProvider); } else if (THING_TYPE_UVINDEX.equals(thingTypeUID)) { - return new OpenWeatherMapUVIndexHandler(thing); + return new OpenWeatherMapUVIndexHandler(thing, timeZoneProvider); } return null; diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/AbstractOpenWeatherMapHandler.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/AbstractOpenWeatherMapHandler.java index dc7f42e64003b..b06a527bf9007 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/AbstractOpenWeatherMapHandler.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/AbstractOpenWeatherMapHandler.java @@ -15,7 +15,6 @@ import static org.openhab.binding.openweathermap.internal.OpenWeatherMapBindingConstants.*; import java.time.Instant; -import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; @@ -28,6 +27,7 @@ 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.DateTimeType; import org.eclipse.smarthome.core.library.types.DecimalType; import org.eclipse.smarthome.core.library.types.PointType; @@ -72,11 +72,14 @@ public abstract class AbstractOpenWeatherMapHandler extends BaseThingHandler { public static final Set SUPPORTED_THING_TYPES = Collections.unmodifiableSet( Stream.of(THING_TYPE_WEATHER_AND_FORECAST, THING_TYPE_UVINDEX).collect(Collectors.toSet())); + private final TimeZoneProvider timeZoneProvider; + // keeps track of the parsed location protected @Nullable PointType location; - public AbstractOpenWeatherMapHandler(Thing thing) { + public AbstractOpenWeatherMapHandler(Thing thing, final TimeZoneProvider timeZoneProvider) { super(thing); + this.timeZoneProvider = timeZoneProvider; } @Override @@ -176,8 +179,8 @@ && isLinked(channelUID)) { protected State getDateTimeTypeState(@Nullable Integer value) { return (value == null) ? UnDefType.UNDEF - : new DateTimeType( - ZonedDateTime.ofInstant(Instant.ofEpochSecond(value.longValue()), ZoneId.systemDefault())); + : new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(value.longValue()), + timeZoneProvider.getTimeZone())); } protected State getDecimalTypeState(@Nullable Double value) { diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapUVIndexHandler.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapUVIndexHandler.java index 6a1fc4bf00341..46b3e335ffa54 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapUVIndexHandler.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapUVIndexHandler.java @@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.i18n.TimeZoneProvider; import org.eclipse.smarthome.core.thing.Channel; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; @@ -60,8 +61,8 @@ public class OpenWeatherMapUVIndexHandler extends AbstractOpenWeatherMapHandler private @Nullable OpenWeatherMapJsonUVIndexData uvindexData; private @Nullable List uvindexForecastData; - public OpenWeatherMapUVIndexHandler(Thing thing) { - super(thing); + public OpenWeatherMapUVIndexHandler(Thing thing, final TimeZoneProvider timeZoneProvider) { + super(thing, timeZoneProvider); } @Override diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapWeatherAndForecastHandler.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapWeatherAndForecastHandler.java index 045451dfb917c..6522a2434d6d3 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapWeatherAndForecastHandler.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapWeatherAndForecastHandler.java @@ -27,6 +27,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpResponseException; import org.eclipse.smarthome.config.core.Configuration; +import org.eclipse.smarthome.core.i18n.TimeZoneProvider; import org.eclipse.smarthome.core.library.types.QuantityType; import org.eclipse.smarthome.core.thing.Channel; import org.eclipse.smarthome.core.thing.ChannelUID; @@ -77,8 +78,8 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather private @Nullable OpenWeatherMapJsonHourlyForecastData hourlyForecastData; private @Nullable OpenWeatherMapJsonDailyForecastData dailyForecastData; - public OpenWeatherMapWeatherAndForecastHandler(Thing thing) { - super(thing); + public OpenWeatherMapWeatherAndForecastHandler(Thing thing, final TimeZoneProvider timeZoneProvider) { + super(thing, timeZoneProvider); } @Override