mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[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:
parent
4f1fb4ed51
commit
7a806cd307
@ -497,7 +497,7 @@ public class IndegoController {
|
|||||||
* @throws IndegoAuthenticationException if request was rejected as unauthorized
|
* @throws IndegoAuthenticationException if request was rejected as unauthorized
|
||||||
* @throws IndegoException if any communication or parsing error occurred
|
* @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()) {
|
if (!session.isInitialized()) {
|
||||||
logger.debug("Session not yet initialized when serial number was requested; authenticating...");
|
logger.debug("Session not yet initialized when serial number was requested; authenticating...");
|
||||||
authenticate();
|
authenticate();
|
||||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.boschindego.internal.BoschIndegoBindingConstan
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ public class BoschIndegoHandler extends BaseThingHandler {
|
|||||||
private @Nullable ScheduledFuture<?> statePollFuture;
|
private @Nullable ScheduledFuture<?> statePollFuture;
|
||||||
private @Nullable ScheduledFuture<?> cuttingTimeMapPollFuture;
|
private @Nullable ScheduledFuture<?> cuttingTimeMapPollFuture;
|
||||||
private boolean propertiesInitialized;
|
private boolean propertiesInitialized;
|
||||||
private int previousStateCode;
|
private Optional<Integer> previousStateCode = Optional.empty();
|
||||||
|
|
||||||
public BoschIndegoHandler(Thing thing, HttpClient httpClient, BoschIndegoTranslationProvider translationProvider,
|
public BoschIndegoHandler(Thing thing, HttpClient httpClient, BoschIndegoTranslationProvider translationProvider,
|
||||||
TimeZoneProvider timeZoneProvider) {
|
TimeZoneProvider timeZoneProvider) {
|
||||||
@ -102,6 +103,7 @@ public class BoschIndegoHandler extends BaseThingHandler {
|
|||||||
controller = new IndegoController(httpClient, username, password);
|
controller = new IndegoController(httpClient, username, password);
|
||||||
|
|
||||||
updateStatus(ThingStatus.UNKNOWN);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
|
previousStateCode = Optional.empty();
|
||||||
this.statePollFuture = scheduler.scheduleWithFixedDelay(this::refreshStateAndOperatingDataWithExceptionHandling,
|
this.statePollFuture = scheduler.scheduleWithFixedDelay(this::refreshStateAndOperatingDataWithExceptionHandling,
|
||||||
0, config.refresh, TimeUnit.SECONDS);
|
0, config.refresh, TimeUnit.SECONDS);
|
||||||
this.cuttingTimeMapPollFuture = scheduler.scheduleWithFixedDelay(
|
this.cuttingTimeMapPollFuture = scheduler.scheduleWithFixedDelay(
|
||||||
@ -235,10 +237,10 @@ public class BoschIndegoHandler extends BaseThingHandler {
|
|||||||
updateState(state);
|
updateState(state);
|
||||||
|
|
||||||
// When state code changed, refresh cutting times immediately.
|
// When state code changed, refresh cutting times immediately.
|
||||||
if (state.state != previousStateCode) {
|
if (previousStateCode.isPresent() && state.state != previousStateCode.get()) {
|
||||||
refreshCuttingTimes();
|
refreshCuttingTimes();
|
||||||
previousStateCode = state.state;
|
|
||||||
}
|
}
|
||||||
|
previousStateCode = Optional.of(state.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshOperatingData()
|
private void refreshOperatingData()
|
||||||
|
Loading…
Reference in New Issue
Block a user