]> git.basschouten.com Git - openhab-addons.git/commitdiff
[boschindego] Fix duplicated calls during initialization (#13086)
authorJacob Laursen <jacob-github@vindvejr.dk>
Tue, 5 Jul 2022 21:11:44 +0000 (23:11 +0200)
committerGitHub <noreply@github.com>
Tue, 5 Jul 2022 21:11:44 +0000 (23:11 +0200)
* Fix multiple authentications during initialization
* Fix cutting times being fetched twice during initialization

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java
bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java

index 8ee4898f4c5e2e327b0bfcb9232faecbc23b2c2c..70ef46af5c39fe8b1f320b75eea564d8c4feaaba 100644 (file)
@@ -497,7 +497,7 @@ public class IndegoController {
      * @throws IndegoAuthenticationException if request was rejected as unauthorized
      * @throws IndegoException if any communication or parsing error occurred
      */
-    public String getSerialNumber() throws IndegoAuthenticationException, IndegoException {
+    public synchronized String getSerialNumber() throws IndegoAuthenticationException, IndegoException {
         if (!session.isInitialized()) {
             logger.debug("Session not yet initialized when serial number was requested; authenticating...");
             authenticate();
index a8b6634adc0ed5734af6ede176e4962c5a2452c2..326a5f024c2da63ca227dcde95a0ca41f65d5a54 100644 (file)
@@ -16,6 +16,7 @@ import static org.openhab.binding.boschindego.internal.BoschIndegoBindingConstan
 
 import java.time.Instant;
 import java.time.ZonedDateTime;
+import java.util.Optional;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
@@ -71,7 +72,7 @@ public class BoschIndegoHandler extends BaseThingHandler {
     private @Nullable ScheduledFuture<?> statePollFuture;
     private @Nullable ScheduledFuture<?> cuttingTimeMapPollFuture;
     private boolean propertiesInitialized;
-    private int previousStateCode;
+    private Optional<Integer> previousStateCode = Optional.empty();
 
     public BoschIndegoHandler(Thing thing, HttpClient httpClient, BoschIndegoTranslationProvider translationProvider,
             TimeZoneProvider timeZoneProvider) {
@@ -102,6 +103,7 @@ public class BoschIndegoHandler extends BaseThingHandler {
         controller = new IndegoController(httpClient, username, password);
 
         updateStatus(ThingStatus.UNKNOWN);
+        previousStateCode = Optional.empty();
         this.statePollFuture = scheduler.scheduleWithFixedDelay(this::refreshStateAndOperatingDataWithExceptionHandling,
                 0, config.refresh, TimeUnit.SECONDS);
         this.cuttingTimeMapPollFuture = scheduler.scheduleWithFixedDelay(
@@ -235,10 +237,10 @@ public class BoschIndegoHandler extends BaseThingHandler {
         updateState(state);
 
         // When state code changed, refresh cutting times immediately.
-        if (state.state != previousStateCode) {
+        if (previousStateCode.isPresent() && state.state != previousStateCode.get()) {
             refreshCuttingTimes();
-            previousStateCode = state.state;
         }
+        previousStateCode = Optional.of(state.state);
     }
 
     private void refreshOperatingData()