[boschindego] Fix duplicated calls during initialization (#13086)

* Fix multiple authentications during initialization
* Fix cutting times being fetched twice during initialization

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2022-07-05 23:11:44 +02:00 committed by GitHub
parent 4f1fb4ed51
commit 7a806cd307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View 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();

View 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()