diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java index 8ee4898f4c5..70ef46af5c3 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java @@ -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(); diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java index a8b6634adc0..326a5f024c2 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java @@ -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 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()