*/
package org.openhab.binding.hdpowerview.internal;
+import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.ExecutionException;
* exception handling during the five minute maintenance period after a 423
* error is received
*/
- private final int maintenancePeriod = 300;
- private Instant maintenanceScheduledEnd = Instant.now().minusSeconds(2 * maintenancePeriod);
+ private final Duration maintenancePeriod = Duration.ofMinutes(5);
+ private Instant maintenanceScheduledEnd = Instant.MIN;
private final String base;
private final String firmwareVersion;
int statusCode = response.getStatus();
if (statusCode == HttpStatus.LOCKED_423) {
// set end of maintenance window, and throw a "softer" exception
- maintenanceScheduledEnd = Instant.now().plusSeconds(maintenancePeriod);
+ maintenanceScheduledEnd = Instant.now().plus(maintenancePeriod);
logger.debug("Hub undergoing maintenance");
throw new HubMaintenanceException("Hub undergoing maintenance");
}
throw new HubProcessingException(String.format("HTTP %d error", statusCode));
}
String jsonResponse = response.getContentAsString();
- if ("".equals(jsonResponse)) {
- logger.warn("Hub returned no content");
- throw new HubProcessingException("Missing response entity");
- }
if (logger.isTraceEnabled()) {
logger.trace("JSON response = {}", jsonResponse);
}
+ if (jsonResponse == null || jsonResponse.isEmpty()) {
+ logger.warn("Hub returned no content");
+ throw new HubProcessingException("Missing response entity");
+ }
return jsonResponse;
}
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import javax.ws.rs.ProcessingException;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
private long hardRefreshPositionInterval;
private long hardRefreshBatteryLevelInterval;
- private @Nullable HDPowerViewWebTargets webTargets;
+ private @NonNullByDefault({}) HDPowerViewWebTargets webTargets;
private @Nullable ScheduledFuture<?> pollFuture;
private @Nullable ScheduledFuture<?> hardRefreshPositionFuture;
private @Nullable ScheduledFuture<?> hardRefreshBatteryLevelFuture;
}
try {
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
int id = Integer.parseInt(channelUID.getIdWithoutGroup());
if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) {
webTargets.activateScene(id);
return;
}
- updateStatus(ThingStatus.UNKNOWN);
pendingShadeInitializations.clear();
webTargets = new HDPowerViewWebTargets(httpClient, host);
refreshInterval = config.refresh;
hardRefreshBatteryLevelInterval = config.hardRefreshBatteryLevel;
initializeChannels();
firmwareVersions = null;
+
+ updateStatus(ThingStatus.UNKNOWN);
schedulePoll();
}
deprecatedChannelsCreated = false;
}
- public @Nullable HDPowerViewWebTargets getWebTargets() {
+ public HDPowerViewWebTargets getWebTargets() {
return webTargets;
}
if (firmwareVersions != null) {
return;
}
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
FirmwareVersions firmwareVersions = webTargets.getFirmwareVersions();
Firmware mainProcessor = firmwareVersions.mainProcessor;
if (mainProcessor == null) {
}
private void pollShades() throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
-
Shades shades = webTargets.getShades();
List<ShadeData> shadesData = shades.shadeData;
if (shadesData == null) {
private List<Scene> fetchScenes()
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
-
Scenes scenes = webTargets.getScenes();
List<Scene> sceneData = scenes.sceneData;
if (sceneData == null) {
private List<SceneCollection> fetchSceneCollections()
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
-
SceneCollections sceneCollections = webTargets.getSceneCollections();
List<SceneCollection> sceneCollectionData = sceneCollections.sceneCollectionData;
if (sceneCollectionData == null) {
private List<ScheduledEvent> fetchScheduledEvents()
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
- HDPowerViewWebTargets webTargets = this.webTargets;
- if (webTargets == null) {
- throw new ProcessingException("Web targets not initialized");
- }
-
ScheduledEvents scheduledEvents = webTargets.getScheduledEvents();
List<ScheduledEvent> scheduledEventData = scheduledEvents.scheduledEventData;
if (scheduledEventData == null) {