* @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();
import java.time.Instant;
import java.time.ZonedDateTime;
+import java.util.Optional;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
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) {
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(
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()