]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bticinosmarter] Fix activationdate parsing (#15474)
authorlsiepel <leosiepel@gmail.com>
Sun, 27 Aug 2023 14:11:33 +0000 (16:11 +0200)
committerGitHub <noreply@github.com>
Sun, 27 Aug 2023 14:11:33 +0000 (16:11 +0200)
* Fix DateTime format
* Switch to TimeZoneProvider

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Chronothermostat.java
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/factory/SmartherHandlerFactory.java
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java

index 6520ea31c7b6849f928f0121c7bf3855268c5238..266570e67e6f5d823211bb3ce6ccaacf699b49a6 100644 (file)
@@ -24,6 +24,7 @@ import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.LoadState;
 import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.MeasureUnit;
 import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherIllegalPropertyValueException;
 import org.openhab.binding.bticinosmarther.internal.util.DateUtil;
+import org.openhab.core.i18n.TimeZoneProvider;
 
 import com.google.gson.annotations.SerializedName;
 
@@ -146,12 +147,16 @@ public class Chronothermostat {
      * @return a string containing the module operational activation time label, or {@code null} if the activation time
      *         cannot be parsed to a valid date/time
      */
-    public @Nullable String getActivationTimeLabel() {
+    public @Nullable String getActivationTimeLabel(TimeZoneProvider timeZoneProvider) {
         String timeLabel = TIME_FOREVER;
         if (activationTime != null) {
             try {
-                final ZonedDateTime dateActivationTime = DateUtil.parseZonedTime(activationTime, DTF_DATETIME_EXT);
-                final ZonedDateTime dateTomorrow = DateUtil.getZonedStartOfDay(1, dateActivationTime.getZone());
+                boolean dateActivationTimeIsZoned = activationTime.length() > 19;
+
+                final ZonedDateTime dateActivationTime = DateUtil.parseZonedTime(activationTime,
+                        dateActivationTimeIsZoned ? DTF_DATETIME_EXT : DTF_DATETIME);
+                final ZonedDateTime dateTomorrow = DateUtil.getZonedStartOfDay(1,
+                        dateActivationTimeIsZoned ? dateActivationTime.getZone() : timeZoneProvider.getTimeZone());
 
                 if (dateActivationTime.isBefore(dateTomorrow)) {
                     timeLabel = DateUtil.format(dateActivationTime, DTF_TODAY);
index 636e0d318dab892cea54eb307f996137fc1df6e4..ab88c78fd3438c0cfc8d602bdc224293a25328fb 100644 (file)
@@ -21,6 +21,7 @@ import org.openhab.binding.bticinosmarther.internal.handler.SmartherBridgeHandle
 import org.openhab.binding.bticinosmarther.internal.handler.SmartherDynamicStateDescriptionProvider;
 import org.openhab.binding.bticinosmarther.internal.handler.SmartherModuleHandler;
 import org.openhab.core.auth.client.oauth2.OAuthFactory;
+import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.io.net.http.HttpClientFactory;
 import org.openhab.core.scheduler.CronScheduler;
 import org.openhab.core.thing.Bridge;
@@ -51,16 +52,19 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory {
     private final HttpClient httpClient;
     private final CronScheduler cronScheduler;
     private final SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
+    private final TimeZoneProvider timeZoneProvider;
 
     @Activate
     public SmartherHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference SmartherAccountService authService,
             @Reference HttpClientFactory httpClientFactory, @Reference CronScheduler cronScheduler,
-            @Reference SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
+            @Reference SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider,
+            final @Reference TimeZoneProvider timeZoneProvider) {
         this.oAuthFactory = oAuthFactory;
         this.authService = authService;
         this.httpClient = httpClientFactory.getCommonHttpClient();
         this.cronScheduler = cronScheduler;
         this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider;
+        this.timeZoneProvider = timeZoneProvider;
     }
 
     @Override
@@ -77,7 +81,7 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory {
             this.authService.addSmartherAccountHandler(handler);
             return handler;
         } else if (SmartherBindingConstants.THING_TYPE_MODULE.equals(thingTypeUID)) {
-            return new SmartherModuleHandler(thing, cronScheduler, dynamicStateDescriptionProvider);
+            return new SmartherModuleHandler(thing, cronScheduler, dynamicStateDescriptionProvider, timeZoneProvider);
         } else {
             logger.debug("Unsupported thing {}", thing.getThingTypeUID());
             return null;
index 48da20713fcf6c5435df4599989e6b059b6aaa57..0ae5cd4c0c0aecd5a2b3fb371508cc11330c3879 100644 (file)
@@ -34,6 +34,7 @@ import org.openhab.binding.bticinosmarther.internal.config.SmartherModuleConfigu
 import org.openhab.binding.bticinosmarther.internal.model.ModuleSettings;
 import org.openhab.binding.bticinosmarther.internal.util.StringUtil;
 import org.openhab.core.cache.ExpiringCache;
+import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.QuantityType;
@@ -74,6 +75,7 @@ public class SmartherModuleHandler extends BaseThingHandler {
     private final SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
     private final ChannelUID programChannelUID;
     private final ChannelUID endDateChannelUID;
+    private final TimeZoneProvider timeZoneProvider;
 
     // Module configuration
     private SmartherModuleConfiguration config;
@@ -98,11 +100,12 @@ public class SmartherModuleHandler extends BaseThingHandler {
      * @param provider
      *            the {@link SmartherDynamicStateDescriptionProvider} dynamic state description provider to be used
      */
-    public SmartherModuleHandler(Thing thing, CronScheduler scheduler,
-            SmartherDynamicStateDescriptionProvider provider) {
+    public SmartherModuleHandler(Thing thing, CronScheduler scheduler, SmartherDynamicStateDescriptionProvider provider,
+            final TimeZoneProvider timeZoneProvider) {
         super(thing);
         this.cronScheduler = scheduler;
         this.dynamicStateDescriptionProvider = provider;
+        this.timeZoneProvider = timeZoneProvider;
         this.programChannelUID = new ChannelUID(thing.getUID(), CHANNEL_SETTINGS_PROGRAM);
         this.endDateChannelUID = new ChannelUID(thing.getUID(), CHANNEL_SETTINGS_ENDDATE);
         this.config = new SmartherModuleConfiguration();
@@ -710,7 +713,8 @@ public class SmartherModuleHandler extends BaseThingHandler {
             updateChannelState(CHANNEL_STATUS_MODE,
                     new StringType(StringUtil.capitalize(localChrono.getMode().toLowerCase())));
             updateChannelState(CHANNEL_STATUS_TEMPERATURE, localChrono.getSetPointTemperature().toState());
-            updateChannelState(CHANNEL_STATUS_ENDTIME, new StringType(localChrono.getActivationTimeLabel()));
+            updateChannelState(CHANNEL_STATUS_ENDTIME,
+                    new StringType(localChrono.getActivationTimeLabel(timeZoneProvider)));
             updateChannelState(CHANNEL_STATUS_TEMP_FORMAT, new StringType(localChrono.getTemperatureFormat()));
             final Program localProgram = localChrono.getProgram();
             if (localProgram != null) {