[hdpowerview] Refactor exception handling (#12049)
* Refactor exception handling. Fixes #12048 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
ddfab66849
commit
fee45a5b94
|
@ -13,6 +13,7 @@
|
||||||
package org.openhab.binding.hdpowerview.internal;
|
package org.openhab.binding.hdpowerview.internal;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -32,15 +33,23 @@ import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersion;
|
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersion;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersions;
|
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersions;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes.Scene;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents;
|
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents.ScheduledEvent;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Survey;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Survey;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubInvalidResponseException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
@ -133,22 +142,26 @@ public class HDPowerViewWebTargets {
|
||||||
* Fetches a JSON package with firmware information for the hub.
|
* Fetches a JSON package with firmware information for the hub.
|
||||||
*
|
*
|
||||||
* @return FirmwareVersions class instance
|
* @return FirmwareVersions class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public FirmwareVersions getFirmwareVersions()
|
public FirmwareVersions getFirmwareVersions()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, firmwareVersion, null, null);
|
String json = invoke(HttpMethod.GET, firmwareVersion, null, null);
|
||||||
|
try {
|
||||||
FirmwareVersion firmwareVersion = gson.fromJson(json, FirmwareVersion.class);
|
FirmwareVersion firmwareVersion = gson.fromJson(json, FirmwareVersion.class);
|
||||||
if (firmwareVersion == null) {
|
if (firmwareVersion == null) {
|
||||||
throw new JsonParseException("Missing firmware response");
|
throw new HubInvalidResponseException("Missing firmware response");
|
||||||
}
|
}
|
||||||
FirmwareVersions firmwareVersions = firmwareVersion.firmware;
|
FirmwareVersions firmwareVersions = firmwareVersion.firmware;
|
||||||
if (firmwareVersions == null) {
|
if (firmwareVersions == null) {
|
||||||
throw new JsonParseException("Missing 'firmware' element");
|
throw new HubInvalidResponseException("Missing 'firmware' element");
|
||||||
}
|
}
|
||||||
return firmwareVersions;
|
return firmwareVersions;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing firmware response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,13 +169,25 @@ public class HDPowerViewWebTargets {
|
||||||
* a Shades class instance
|
* a Shades class instance
|
||||||
*
|
*
|
||||||
* @return Shades class instance
|
* @return Shades class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shades getShades() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
public Shades getShades() throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, shades, null, null);
|
String json = invoke(HttpMethod.GET, shades, null, null);
|
||||||
return gson.fromJson(json, Shades.class);
|
try {
|
||||||
|
Shades shades = gson.fromJson(json, Shades.class);
|
||||||
|
if (shades == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing shades response");
|
||||||
|
}
|
||||||
|
List<ShadeData> shadeData = shades.shadeData;
|
||||||
|
if (shadeData == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'shades.shadeData' element");
|
||||||
|
}
|
||||||
|
return shades;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing shades response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,45 +195,64 @@ public class HDPowerViewWebTargets {
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be moved
|
* @param shadeId id of the shade to be moved
|
||||||
* @param position instance of ShadePosition containing the new position
|
* @param position instance of ShadePosition containing the new position
|
||||||
* @return Shade class instance (with new position)
|
* @return ShadeData class instance (with new position)
|
||||||
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade moveShade(int shadeId, ShadePosition position)
|
public ShadeData moveShade(int shadeId, ShadePosition position)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String jsonRequest = gson.toJson(new ShadeMove(position));
|
String jsonRequest = gson.toJson(new ShadeMove(position));
|
||||||
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
||||||
return gson.fromJson(jsonResponse, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShadeData shadeDataFromJson(String json) throws HubInvalidResponseException {
|
||||||
|
try {
|
||||||
|
Shade shade = gson.fromJson(json, Shade.class);
|
||||||
|
if (shade == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing shade response");
|
||||||
|
}
|
||||||
|
ShadeData shadeData = shade.shade;
|
||||||
|
if (shadeData == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'shade.shade' element");
|
||||||
|
}
|
||||||
|
return shadeData;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing shade response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instructs the hub to stop movement of a specific shade
|
* Instructs the hub to stop movement of a specific shade
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be stopped
|
* @param shadeId id of the shade to be stopped
|
||||||
* @return Shade class instance (new position cannot be relied upon)
|
* @return ShadeData class instance (new position cannot be relied upon)
|
||||||
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade stopShade(int shadeId)
|
public ShadeData stopShade(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String jsonRequest = gson.toJson(new ShadeStop());
|
String jsonRequest = gson.toJson(new ShadeStop());
|
||||||
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
||||||
return gson.fromJson(jsonResponse, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instructs the hub to calibrate a specific shade
|
* Instructs the hub to calibrate a specific shade
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be calibrated
|
* @param shadeId id of the shade to be calibrated
|
||||||
* @return Shade class instance
|
* @return ShadeData class instance
|
||||||
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade calibrateShade(int shadeId)
|
public ShadeData calibrateShade(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String jsonRequest = gson.toJson(new ShadeCalibrate());
|
String jsonRequest = gson.toJson(new ShadeCalibrate());
|
||||||
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest);
|
||||||
return gson.fromJson(jsonResponse, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,13 +260,25 @@ public class HDPowerViewWebTargets {
|
||||||
* a Scenes class instance
|
* a Scenes class instance
|
||||||
*
|
*
|
||||||
* @return Scenes class instance
|
* @return Scenes class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Scenes getScenes() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
public Scenes getScenes() throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, scenes, null, null);
|
String json = invoke(HttpMethod.GET, scenes, null, null);
|
||||||
return gson.fromJson(json, Scenes.class);
|
try {
|
||||||
|
Scenes scenes = gson.fromJson(json, Scenes.class);
|
||||||
|
if (scenes == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing scenes response");
|
||||||
|
}
|
||||||
|
List<Scene> sceneData = scenes.sceneData;
|
||||||
|
if (sceneData == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'scenes.sceneData' element");
|
||||||
|
}
|
||||||
|
return scenes;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing scenes response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,14 +297,26 @@ public class HDPowerViewWebTargets {
|
||||||
* a SceneCollections class instance
|
* a SceneCollections class instance
|
||||||
*
|
*
|
||||||
* @return SceneCollections class instance
|
* @return SceneCollections class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable SceneCollections getSceneCollections()
|
public SceneCollections getSceneCollections()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, sceneCollections, null, null);
|
String json = invoke(HttpMethod.GET, sceneCollections, null, null);
|
||||||
return gson.fromJson(json, SceneCollections.class);
|
try {
|
||||||
|
SceneCollections sceneCollections = gson.fromJson(json, SceneCollections.class);
|
||||||
|
if (sceneCollections == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing sceneCollections response");
|
||||||
|
}
|
||||||
|
List<SceneCollection> sceneCollectionData = sceneCollections.sceneCollectionData;
|
||||||
|
if (sceneCollectionData == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'sceneCollections.sceneCollectionData' element");
|
||||||
|
}
|
||||||
|
return sceneCollections;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing sceneCollections response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,14 +336,26 @@ public class HDPowerViewWebTargets {
|
||||||
* a ScheduledEvents class instance
|
* a ScheduledEvents class instance
|
||||||
*
|
*
|
||||||
* @return ScheduledEvents class instance
|
* @return ScheduledEvents class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable ScheduledEvents getScheduledEvents()
|
public ScheduledEvents getScheduledEvents()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, scheduledEvents, null, null);
|
String json = invoke(HttpMethod.GET, scheduledEvents, null, null);
|
||||||
return gson.fromJson(json, ScheduledEvents.class);
|
try {
|
||||||
|
ScheduledEvents scheduledEvents = gson.fromJson(json, ScheduledEvents.class);
|
||||||
|
if (scheduledEvents == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing scheduledEvents response");
|
||||||
|
}
|
||||||
|
List<ScheduledEvent> scheduledEventData = scheduledEvents.scheduledEventData;
|
||||||
|
if (scheduledEventData == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'scheduledEvents.scheduledEventData' element");
|
||||||
|
}
|
||||||
|
return scheduledEvents;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing scheduledEvents response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -283,19 +363,26 @@ public class HDPowerViewWebTargets {
|
||||||
*
|
*
|
||||||
* @param scheduledEventId id of the scheduled event to be enabled or disabled
|
* @param scheduledEventId id of the scheduled event to be enabled or disabled
|
||||||
* @param enable true to enable scheduled event, false to disable
|
* @param enable true to enable scheduled event, false to disable
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws JsonSyntaxException if there is a JSON syntax error
|
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public void enableScheduledEvent(int scheduledEventId, boolean enable)
|
public void enableScheduledEvent(int scheduledEventId, boolean enable)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String uri = scheduledEvents + "/" + scheduledEventId;
|
String uri = scheduledEvents + "/" + scheduledEventId;
|
||||||
String json = invoke(HttpMethod.GET, uri, null, null);
|
String jsonResponse = invoke(HttpMethod.GET, uri, null, null);
|
||||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
try {
|
||||||
JsonObject scheduledEventObject = jsonObject.get("scheduledEvent").getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
|
||||||
|
JsonElement scheduledEventElement = jsonObject.get("scheduledEvent");
|
||||||
|
if (scheduledEventElement == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing 'scheduledEvent' element");
|
||||||
|
}
|
||||||
|
JsonObject scheduledEventObject = scheduledEventElement.getAsJsonObject();
|
||||||
scheduledEventObject.addProperty("enabled", enable);
|
scheduledEventObject.addProperty("enabled", enable);
|
||||||
invoke(HttpMethod.PUT, uri, null, jsonObject.toString());
|
invoke(HttpMethod.PUT, uri, null, jsonObject.toString());
|
||||||
|
} catch (JsonParseException | IllegalStateException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing scheduledEvent response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,15 +453,15 @@ public class HDPowerViewWebTargets {
|
||||||
* in a Shade class instance
|
* in a Shade class instance
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be fetched
|
* @param shadeId id of the shade to be fetched
|
||||||
* @return Shade class instance
|
* @return ShadeData class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade getShade(int shadeId)
|
public ShadeData getShade(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, shades + Integer.toString(shadeId), null, null);
|
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId), null, null);
|
||||||
return gson.fromJson(json, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,16 +470,16 @@ public class HDPowerViewWebTargets {
|
||||||
* and wraps it in a Shade class instance
|
* and wraps it in a Shade class instance
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be refreshed
|
* @param shadeId id of the shade to be refreshed
|
||||||
* @return Shade class instance
|
* @return ShadeData class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade refreshShadePosition(int shadeId)
|
public ShadeData refreshShadePosition(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
||||||
Query.of("refresh", Boolean.toString(true)), null);
|
Query.of("refresh", Boolean.toString(true)), null);
|
||||||
return gson.fromJson(json, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -403,15 +490,23 @@ public class HDPowerViewWebTargets {
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be surveyed
|
* @param shadeId id of the shade to be surveyed
|
||||||
* @return Survey class instance
|
* @return Survey class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Survey getShadeSurvey(int shadeId)
|
public Survey getShadeSurvey(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
||||||
Query.of("survey", Boolean.toString(true)), null);
|
Query.of("survey", Boolean.toString(true)), null);
|
||||||
return gson.fromJson(json, Survey.class);
|
try {
|
||||||
|
Survey survey = gson.fromJson(jsonResponse, Survey.class);
|
||||||
|
if (survey == null) {
|
||||||
|
throw new HubInvalidResponseException("Missing survey response");
|
||||||
|
}
|
||||||
|
return survey;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new HubInvalidResponseException("Error parsing survey response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -420,15 +515,15 @@ public class HDPowerViewWebTargets {
|
||||||
* and wraps it in a Shade class instance
|
* and wraps it in a Shade class instance
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be refreshed
|
* @param shadeId id of the shade to be refreshed
|
||||||
* @return Shade class instance
|
* @return ShadeData class instance
|
||||||
* @throws JsonParseException if there is a JSON parsing error
|
* @throws HubInvalidResponseException if response is invalid
|
||||||
* @throws HubProcessingException if there is any processing error
|
* @throws HubProcessingException if there is any processing error
|
||||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||||
*/
|
*/
|
||||||
public @Nullable Shade refreshShadeBatteryLevel(int shadeId)
|
public ShadeData refreshShadeBatteryLevel(int shadeId)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
||||||
Query.of("updateBatteryLevel", Boolean.toString(true)), null);
|
Query.of("updateBatteryLevel", Boolean.toString(true)), null);
|
||||||
return gson.fromJson(json, Shade.class);
|
return shadeDataFromJson(jsonResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.hdpowerview.internal.api;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Survey data of a single Shade, as returned by an HD PowerView hub
|
||||||
|
*
|
||||||
|
* @author Jacob Laursen - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class SurveyData {
|
||||||
|
@SerializedName("neighbor_id")
|
||||||
|
public int neighborId;
|
||||||
|
public int rssi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("{neighbor id:%d, rssi:%d}", neighborId, rssi);
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import java.util.StringJoiner;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.api.SurveyData;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
@ -33,17 +34,6 @@ public class Survey {
|
||||||
@SerializedName("survey")
|
@SerializedName("survey")
|
||||||
public List<SurveyData> surveyData;
|
public List<SurveyData> surveyData;
|
||||||
|
|
||||||
public static class SurveyData {
|
|
||||||
@SerializedName("neighbor_id")
|
|
||||||
public int neighborId;
|
|
||||||
public int rssi;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("{neighbor id:%d, rssi:%d}", neighborId, rssi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
List<SurveyData> surveyData = this.surveyData;
|
List<SurveyData> surveyData = this.surveyData;
|
||||||
|
|
|
@ -21,13 +21,14 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
|
||||||
import org.openhab.binding.hdpowerview.internal.handler.HDPowerViewHubHandler;
|
import org.openhab.binding.hdpowerview.internal.handler.HDPowerViewHubHandler;
|
||||||
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
||||||
|
@ -35,8 +36,6 @@ import org.openhab.core.thing.ThingUID;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discovers an HD PowerView Shade from an existing hub
|
* Discovers an HD PowerView Shade from an existing hub
|
||||||
*
|
*
|
||||||
|
@ -89,7 +88,7 @@ public class HDPowerViewShadeDiscoveryService extends AbstractDiscoveryService {
|
||||||
throw new HubProcessingException("Web targets not initialized");
|
throw new HubProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
Shades shades = webTargets.getShades();
|
Shades shades = webTargets.getShades();
|
||||||
if (shades != null && shades.shadeData != null) {
|
if (shades.shadeData != null) {
|
||||||
ThingUID bridgeUID = hub.getThing().getUID();
|
ThingUID bridgeUID = hub.getThing().getUID();
|
||||||
List<ShadeData> shadesData = shades.shadeData;
|
List<ShadeData> shadesData = shades.shadeData;
|
||||||
if (shadesData != null) {
|
if (shadesData != null) {
|
||||||
|
@ -116,10 +115,10 @@ public class HDPowerViewShadeDiscoveryService extends AbstractDiscoveryService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (HubProcessingException | JsonParseException e) {
|
|
||||||
logger.warn("Unexpected error: {}", e.getMessage());
|
|
||||||
} catch (HubMaintenanceException e) {
|
} catch (HubMaintenanceException e) {
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
|
} catch (HubException e) {
|
||||||
|
logger.warn("Unexpected error: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
stopScan();
|
stopScan();
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.hdpowerview.internal.exceptions;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link HubException} is a generic custom exception for the HD PowerView Hub
|
||||||
|
* with the intent of being derived into specific exception classes.
|
||||||
|
*
|
||||||
|
* @author Jacob Laursen - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class HubException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 4052375893291196875L;
|
||||||
|
|
||||||
|
public HubException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HubException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.hdpowerview.internal.exceptions;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link HubInvalidResponseException} is a custom exception for the HD PowerView Hub
|
||||||
|
* which is thrown when a response does not adhere to a defined contract.
|
||||||
|
*
|
||||||
|
* @author Jacob Laursen - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class HubInvalidResponseException extends HubProcessingException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2293572741003905474L;
|
||||||
|
|
||||||
|
public HubInvalidResponseException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HubInvalidResponseException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: EPL-2.0
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.hdpowerview.internal;
|
package org.openhab.binding.hdpowerview.internal.exceptions;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
* @author Andrew Fiddian-Green - Initial contribution
|
* @author Andrew Fiddian-Green - Initial contribution
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HubMaintenanceException extends Exception {
|
public class HubMaintenanceException extends HubException {
|
||||||
|
|
||||||
private static final long serialVersionUID = -708582495003057343L;
|
private static final long serialVersionUID = -708582495003057343L;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: EPL-2.0
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.hdpowerview.internal;
|
package org.openhab.binding.hdpowerview.internal.exceptions;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
@ -20,11 +20,15 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
* @author Andrew Fiddian-Green - Initial contribution
|
* @author Andrew Fiddian-Green - Initial contribution
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HubProcessingException extends Exception {
|
public class HubProcessingException extends HubException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4307088023775166450L;
|
private static final long serialVersionUID = 4307088023775166450L;
|
||||||
|
|
||||||
public HubProcessingException(String message) {
|
public HubProcessingException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HubProcessingException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -34,8 +34,6 @@ import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewTranslationProvider;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewTranslationProvider;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersions;
|
import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersions;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
||||||
|
@ -48,6 +46,10 @@ import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewHubConfiguration;
|
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewHubConfiguration;
|
||||||
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubInvalidResponseException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
|
||||||
import org.openhab.core.library.CoreItemFactory;
|
import org.openhab.core.library.CoreItemFactory;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.thing.Bridge;
|
import org.openhab.core.thing.Bridge;
|
||||||
|
@ -66,8 +68,6 @@ import org.openhab.core.types.RefreshType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link HDPowerViewHubHandler} is responsible for handling commands, which
|
* The {@link HDPowerViewHubHandler} is responsible for handling commands, which
|
||||||
* are sent to one of the channels.
|
* are sent to one of the channels.
|
||||||
|
@ -147,7 +147,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
} catch (HubMaintenanceException e) {
|
} catch (HubMaintenanceException e) {
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
} catch (NumberFormatException | HubProcessingException e) {
|
} catch (NumberFormatException | HubException e) {
|
||||||
logger.debug("Unexpected error {}", e.getMessage());
|
logger.debug("Unexpected error {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,17 +267,23 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
// Scheduled events should also have their current state updated if event has been
|
// Scheduled events should also have their current state updated if event has been
|
||||||
// enabled or disabled through app or other integration.
|
// enabled or disabled through app or other integration.
|
||||||
updateScheduledEventStates(scheduledEvents);
|
updateScheduledEventStates(scheduledEvents);
|
||||||
} catch (JsonParseException e) {
|
} catch (HubInvalidResponseException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause == null) {
|
||||||
logger.warn("Bridge returned a bad JSON response: {}", e.getMessage());
|
logger.warn("Bridge returned a bad JSON response: {}", e.getMessage());
|
||||||
} catch (HubProcessingException e) {
|
} else {
|
||||||
logger.warn("Error connecting to bridge: {}", e.getMessage());
|
logger.warn("Bridge returned a bad JSON response: {} -> {}", e.getMessage(), cause.getMessage());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, e.getMessage());
|
}
|
||||||
} catch (HubMaintenanceException e) {
|
} catch (HubMaintenanceException e) {
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
|
} catch (HubException e) {
|
||||||
|
logger.warn("Error connecting to bridge: {}", e.getMessage());
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFirmwareProperties() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
private void updateFirmwareProperties()
|
||||||
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
if (firmwareVersions != null) {
|
if (firmwareVersions != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -306,20 +312,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
updateProperties(properties);
|
updateProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pollShades() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
private void pollShades() throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
HDPowerViewWebTargets webTargets = this.webTargets;
|
HDPowerViewWebTargets webTargets = this.webTargets;
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
Shades shades = webTargets.getShades();
|
Shades shades = webTargets.getShades();
|
||||||
if (shades == null) {
|
|
||||||
throw new JsonParseException("Missing 'shades' element");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ShadeData> shadesData = shades.shadeData;
|
List<ShadeData> shadesData = shades.shadeData;
|
||||||
if (shadesData == null) {
|
if (shadesData == null) {
|
||||||
throw new JsonParseException("Missing 'shades.shadeData' element");
|
throw new HubInvalidResponseException("Missing 'shades.shadeData' element");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
@ -349,20 +351,17 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
thingHandler.onReceiveUpdate(shadeData);
|
thingHandler.onReceiveUpdate(shadeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Scene> fetchScenes() throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
private List<Scene> fetchScenes()
|
||||||
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
HDPowerViewWebTargets webTargets = this.webTargets;
|
HDPowerViewWebTargets webTargets = this.webTargets;
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenes scenes = webTargets.getScenes();
|
Scenes scenes = webTargets.getScenes();
|
||||||
if (scenes == null) {
|
|
||||||
throw new JsonParseException("Missing 'scenes' element");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Scene> sceneData = scenes.sceneData;
|
List<Scene> sceneData = scenes.sceneData;
|
||||||
if (sceneData == null) {
|
if (sceneData == null) {
|
||||||
throw new JsonParseException("Missing 'scenes.sceneData' element");
|
throw new HubInvalidResponseException("Missing 'scenes.sceneData' element");
|
||||||
}
|
}
|
||||||
logger.debug("Received data for {} scenes", sceneData.size());
|
logger.debug("Received data for {} scenes", sceneData.size());
|
||||||
|
|
||||||
|
@ -370,7 +369,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Scene> updateSceneChannels()
|
private List<Scene> updateSceneChannels()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
List<Scene> scenes = fetchScenes();
|
List<Scene> scenes = fetchScenes();
|
||||||
|
|
||||||
if (scenes.size() == sceneCache.size() && sceneCache.containsAll(scenes)) {
|
if (scenes.size() == sceneCache.size() && sceneCache.containsAll(scenes)) {
|
||||||
|
@ -445,20 +444,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SceneCollection> fetchSceneCollections()
|
private List<SceneCollection> fetchSceneCollections()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
HDPowerViewWebTargets webTargets = this.webTargets;
|
HDPowerViewWebTargets webTargets = this.webTargets;
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneCollections sceneCollections = webTargets.getSceneCollections();
|
SceneCollections sceneCollections = webTargets.getSceneCollections();
|
||||||
if (sceneCollections == null) {
|
|
||||||
throw new JsonParseException("Missing 'sceneCollections' element");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<SceneCollection> sceneCollectionData = sceneCollections.sceneCollectionData;
|
List<SceneCollection> sceneCollectionData = sceneCollections.sceneCollectionData;
|
||||||
if (sceneCollectionData == null) {
|
if (sceneCollectionData == null) {
|
||||||
throw new JsonParseException("Missing 'sceneCollections.sceneCollectionData' element");
|
throw new HubInvalidResponseException("Missing 'sceneCollections.sceneCollectionData' element");
|
||||||
}
|
}
|
||||||
logger.debug("Received data for {} sceneCollections", sceneCollectionData.size());
|
logger.debug("Received data for {} sceneCollections", sceneCollectionData.size());
|
||||||
|
|
||||||
|
@ -466,7 +461,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SceneCollection> updateSceneCollectionChannels()
|
private List<SceneCollection> updateSceneCollectionChannels()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
List<SceneCollection> sceneCollections = fetchSceneCollections();
|
List<SceneCollection> sceneCollections = fetchSceneCollections();
|
||||||
|
|
||||||
if (sceneCollections.size() == sceneCollectionCache.size()
|
if (sceneCollections.size() == sceneCollectionCache.size()
|
||||||
|
@ -502,20 +497,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ScheduledEvent> fetchScheduledEvents()
|
private List<ScheduledEvent> fetchScheduledEvents()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
HDPowerViewWebTargets webTargets = this.webTargets;
|
HDPowerViewWebTargets webTargets = this.webTargets;
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
ScheduledEvents scheduledEvents = webTargets.getScheduledEvents();
|
ScheduledEvents scheduledEvents = webTargets.getScheduledEvents();
|
||||||
if (scheduledEvents == null) {
|
|
||||||
throw new JsonParseException("Missing 'scheduledEvents' element");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ScheduledEvent> scheduledEventData = scheduledEvents.scheduledEventData;
|
List<ScheduledEvent> scheduledEventData = scheduledEvents.scheduledEventData;
|
||||||
if (scheduledEventData == null) {
|
if (scheduledEventData == null) {
|
||||||
throw new JsonParseException("Missing 'scheduledEvents.scheduledEventData' element");
|
throw new HubInvalidResponseException("Missing 'scheduledEvents.scheduledEventData' element");
|
||||||
}
|
}
|
||||||
logger.debug("Received data for {} scheduledEvents", scheduledEventData.size());
|
logger.debug("Received data for {} scheduledEvents", scheduledEventData.size());
|
||||||
|
|
||||||
|
@ -524,7 +515,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||||
|
|
||||||
private List<ScheduledEvent> updateScheduledEventChannels(List<Scene> scenes,
|
private List<ScheduledEvent> updateScheduledEventChannels(List<Scene> scenes,
|
||||||
List<SceneCollection> sceneCollections)
|
List<SceneCollection> sceneCollections)
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
List<ScheduledEvent> scheduledEvents = fetchScheduledEvents();
|
List<ScheduledEvent> scheduledEvents = fetchScheduledEvents();
|
||||||
|
|
||||||
if (scheduledEvents.size() == scheduledEventCache.size() && scheduledEventCache.containsAll(scheduledEvents)) {
|
if (scheduledEvents.size() == scheduledEventCache.size() && scheduledEventCache.containsAll(scheduledEvents)) {
|
||||||
|
|
|
@ -25,17 +25,18 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;
|
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Survey;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Survey;
|
||||||
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubInvalidResponseException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
import org.openhab.core.library.types.DecimalType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
|
@ -54,8 +55,6 @@ import org.openhab.core.types.UnDefType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles commands for an HD PowerView Shade
|
* Handles commands for an HD PowerView Shade
|
||||||
*
|
*
|
||||||
|
@ -171,21 +170,26 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
handleShadeCommand(channelId, command, webTargets, shadeId);
|
handleShadeCommand(channelId, command, webTargets, shadeId);
|
||||||
} catch (JsonParseException e) {
|
} catch (HubInvalidResponseException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause == null) {
|
||||||
logger.warn("Bridge returned a bad JSON response: {}", e.getMessage());
|
logger.warn("Bridge returned a bad JSON response: {}", e.getMessage());
|
||||||
} catch (HubProcessingException e) {
|
} else {
|
||||||
|
logger.warn("Bridge returned a bad JSON response: {} -> {}", e.getMessage(), cause.getMessage());
|
||||||
|
}
|
||||||
|
} catch (HubMaintenanceException e) {
|
||||||
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
|
} catch (HubException e) {
|
||||||
// ScheduledFutures will be cancelled by dispose(), naturally causing InterruptedException in invoke()
|
// ScheduledFutures will be cancelled by dispose(), naturally causing InterruptedException in invoke()
|
||||||
// for any ongoing requests. Logging this would only cause confusion.
|
// for any ongoing requests. Logging this would only cause confusion.
|
||||||
if (!isDisposing) {
|
if (!isDisposing) {
|
||||||
logger.warn("Unexpected error: {}", e.getMessage());
|
logger.warn("Unexpected error: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (HubMaintenanceException e) {
|
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleShadeCommand(String channelId, Command command, HDPowerViewWebTargets webTargets, int shadeId)
|
private void handleShadeCommand(String channelId, Command command, HDPowerViewWebTargets webTargets, int shadeId)
|
||||||
throws HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
switch (channelId) {
|
switch (channelId) {
|
||||||
case CHANNEL_SHADE_POSITION:
|
case CHANNEL_SHADE_POSITION:
|
||||||
if (command instanceof PercentType) {
|
if (command instanceof PercentType) {
|
||||||
|
@ -417,53 +421,36 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveShade(CoordinateSystem coordSys, int newPercent, HDPowerViewWebTargets webTargets, int shadeId)
|
private void moveShade(CoordinateSystem coordSys, int newPercent, HDPowerViewWebTargets webTargets, int shadeId)
|
||||||
throws HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
ShadePosition newPosition = null;
|
ShadePosition newPosition = null;
|
||||||
// (try to) read the positions from the hub
|
// (try to) read the positions from the hub
|
||||||
Shade shade = webTargets.getShade(shadeId);
|
ShadeData shadeData = webTargets.getShade(shadeId);
|
||||||
if (shade != null) {
|
|
||||||
ShadeData shadeData = shade.shade;
|
|
||||||
if (shadeData != null) {
|
|
||||||
updateCapabilities(shadeData);
|
updateCapabilities(shadeData);
|
||||||
newPosition = shadeData.positions;
|
newPosition = shadeData.positions;
|
||||||
}
|
|
||||||
}
|
|
||||||
// if no positions returned, then create a new position
|
// if no positions returned, then create a new position
|
||||||
if (newPosition == null) {
|
if (newPosition == null) {
|
||||||
newPosition = new ShadePosition();
|
newPosition = new ShadePosition();
|
||||||
}
|
}
|
||||||
Capabilities capabilities = getCapabilitiesOrDefault();
|
Capabilities capabilities = getCapabilitiesOrDefault();
|
||||||
// set the new position value, and write the positions to the hub
|
// set the new position value, and write the positions to the hub
|
||||||
shade = webTargets.moveShade(shadeId, newPosition.setPosition(capabilities, coordSys, newPercent));
|
shadeData = webTargets.moveShade(shadeId, newPosition.setPosition(capabilities, coordSys, newPercent));
|
||||||
if (shade != null) {
|
updateShadePositions(shadeData);
|
||||||
updateShadePositions(shade);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopShade(HDPowerViewWebTargets webTargets, int shadeId)
|
private void stopShade(HDPowerViewWebTargets webTargets, int shadeId)
|
||||||
throws HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
Shade shade = webTargets.stopShade(shadeId);
|
updateShadePositions(webTargets.stopShade(shadeId));
|
||||||
if (shade != null) {
|
|
||||||
updateShadePositions(shade);
|
|
||||||
}
|
|
||||||
// Positions in response from stop motion is not updated to to actual positions yet,
|
// Positions in response from stop motion is not updated to to actual positions yet,
|
||||||
// so we need to request hard refresh.
|
// so we need to request hard refresh.
|
||||||
requestRefreshShadePosition();
|
requestRefreshShadePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calibrateShade(HDPowerViewWebTargets webTargets, int shadeId)
|
private void calibrateShade(HDPowerViewWebTargets webTargets, int shadeId)
|
||||||
throws HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
Shade shade = webTargets.calibrateShade(shadeId);
|
updateShadePositions(webTargets.calibrateShade(shadeId));
|
||||||
if (shade != null) {
|
|
||||||
updateShadePositions(shade);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateShadePositions(Shade shade) {
|
private void updateShadePositions(ShadeData shadeData) {
|
||||||
ShadeData shadeData = shade.shade;
|
|
||||||
if (shadeData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ShadePosition shadePosition = shadeData.positions;
|
ShadePosition shadePosition = shadeData.positions;
|
||||||
if (shadePosition == null) {
|
if (shadePosition == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -532,44 +519,46 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new HubProcessingException("Web targets not initialized");
|
throw new HubProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
Shade shade;
|
ShadeData shadeData;
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case POSITION:
|
case POSITION:
|
||||||
shade = webTargets.refreshShadePosition(shadeId);
|
shadeData = webTargets.refreshShadePosition(shadeId);
|
||||||
break;
|
break;
|
||||||
case SURVEY:
|
case SURVEY:
|
||||||
Survey survey = webTargets.getShadeSurvey(shadeId);
|
Survey survey = webTargets.getShadeSurvey(shadeId);
|
||||||
if (survey != null && survey.surveyData != null) {
|
if (survey.surveyData != null) {
|
||||||
logger.debug("Survey response for shade {}: {}", survey.shadeId, survey.toString());
|
logger.debug("Survey response for shade {}: {}", survey.shadeId, survey.toString());
|
||||||
} else {
|
} else {
|
||||||
logger.warn("No response from shade {} survey", shadeId);
|
logger.warn("No response from shade {} survey", shadeId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case BATTERY_LEVEL:
|
case BATTERY_LEVEL:
|
||||||
shade = webTargets.refreshShadeBatteryLevel(shadeId);
|
shadeData = webTargets.refreshShadeBatteryLevel(shadeId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException("Unsupported refresh kind " + kind.toString());
|
throw new NotSupportedException("Unsupported refresh kind " + kind.toString());
|
||||||
}
|
}
|
||||||
if (shade != null) {
|
|
||||||
ShadeData shadeData = shade.shade;
|
|
||||||
if (shadeData != null) {
|
|
||||||
if (Boolean.TRUE.equals(shadeData.timedOut)) {
|
if (Boolean.TRUE.equals(shadeData.timedOut)) {
|
||||||
logger.warn("Shade {} wireless refresh time out", shadeId);
|
logger.warn("Shade {} wireless refresh time out", shadeId);
|
||||||
} else if (kind == RefreshKind.POSITION) {
|
} else if (kind == RefreshKind.POSITION) {
|
||||||
updateShadePositions(shade);
|
updateShadePositions(shadeData);
|
||||||
updateHardProperties(shadeData);
|
updateHardProperties(shadeData);
|
||||||
}
|
}
|
||||||
|
} catch (HubInvalidResponseException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause == null) {
|
||||||
|
logger.warn("Bridge returned a bad JSON response: {}", e.getMessage());
|
||||||
|
} else {
|
||||||
|
logger.warn("Bridge returned a bad JSON response: {} -> {}", e.getMessage(), cause.getMessage());
|
||||||
}
|
}
|
||||||
}
|
} catch (HubMaintenanceException e) {
|
||||||
} catch (HubProcessingException e) {
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
|
} catch (HubException e) {
|
||||||
// ScheduledFutures will be cancelled by dispose(), naturally causing InterruptedException in invoke()
|
// ScheduledFutures will be cancelled by dispose(), naturally causing InterruptedException in invoke()
|
||||||
// for any ongoing requests. Logging this would only cause confusion.
|
// for any ongoing requests. Logging this would only cause confusion.
|
||||||
if (!isDisposing) {
|
if (!isDisposing) {
|
||||||
logger.warn("Unexpected error: {}", e.getMessage());
|
logger.warn("Unexpected error: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (HubMaintenanceException e) {
|
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,18 +26,18 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
|
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes.Scene;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes.Scene;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
|
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
|
||||||
|
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
import org.openhab.core.types.State;
|
import org.openhab.core.types.State;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
|
@ -120,7 +120,6 @@ public class HDPowerViewJUnitTests {
|
||||||
try {
|
try {
|
||||||
shadesX = webTargets.getShades();
|
shadesX = webTargets.getShades();
|
||||||
assertNotNull(shadesX);
|
assertNotNull(shadesX);
|
||||||
if (shadesX != null) {
|
|
||||||
List<ShadeData> shadesData = shadesX.shadeData;
|
List<ShadeData> shadesData = shadesX.shadeData;
|
||||||
assertNotNull(shadesData);
|
assertNotNull(shadesData);
|
||||||
|
|
||||||
|
@ -142,8 +141,7 @@ public class HDPowerViewJUnitTests {
|
||||||
assertNotNull(shadeName);
|
assertNotNull(shadeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (HubException e) {
|
||||||
} catch (JsonParseException | HubProcessingException | HubMaintenanceException e) {
|
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +151,6 @@ public class HDPowerViewJUnitTests {
|
||||||
Scenes scenes = webTargets.getScenes();
|
Scenes scenes = webTargets.getScenes();
|
||||||
assertNotNull(scenes);
|
assertNotNull(scenes);
|
||||||
|
|
||||||
if (scenes != null) {
|
|
||||||
List<Scene> scenesData = scenes.sceneData;
|
List<Scene> scenesData = scenes.sceneData;
|
||||||
assertNotNull(scenesData);
|
assertNotNull(scenesData);
|
||||||
|
|
||||||
|
@ -169,38 +166,30 @@ public class HDPowerViewJUnitTests {
|
||||||
assertNotNull(sceneName);
|
assertNotNull(sceneName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (HubException e) {
|
||||||
} catch (JsonParseException | HubProcessingException | HubMaintenanceException e) {
|
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== refresh a specific shade ====
|
// ==== refresh a specific shade ====
|
||||||
Shade shade = null;
|
ShadeData shadeData = null;
|
||||||
try {
|
try {
|
||||||
assertNotEquals(0, shadeId);
|
assertNotEquals(0, shadeId);
|
||||||
shade = webTargets.refreshShadePosition(shadeId);
|
shadeData = webTargets.refreshShadePosition(shadeId);
|
||||||
assertNotNull(shade);
|
} catch (HubException e) {
|
||||||
} catch (HubProcessingException | HubMaintenanceException e) {
|
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== move a specific shade ====
|
// ==== move a specific shade ====
|
||||||
try {
|
try {
|
||||||
assertNotEquals(0, shadeId);
|
assertNotEquals(0, shadeId);
|
||||||
assertNotNull(shade);
|
|
||||||
if (shade != null) {
|
|
||||||
ShadeData shadeData = shade.shade;
|
|
||||||
assertNotNull(shadeData);
|
|
||||||
|
|
||||||
if (shadeData != null) {
|
if (shadeData != null) {
|
||||||
ShadePosition positions = shadeData.positions;
|
ShadePosition positions = shadeData.positions;
|
||||||
assertNotNull(positions);
|
assertNotNull(positions);
|
||||||
|
|
||||||
if (positions != null) {
|
|
||||||
Integer capabilitiesValue = shadeData.capabilities;
|
Integer capabilitiesValue = shadeData.capabilities;
|
||||||
assertNotNull(capabilitiesValue);
|
assertNotNull(capabilitiesValue);
|
||||||
|
|
||||||
if (capabilitiesValue != null) {
|
if (positions != null && capabilitiesValue != null) {
|
||||||
Capabilities capabilities = db.getCapabilities(capabilitiesValue.intValue());
|
Capabilities capabilities = db.getCapabilities(capabilitiesValue.intValue());
|
||||||
|
|
||||||
State pos = positions.getState(capabilities, PRIMARY_ZERO_IS_CLOSED);
|
State pos = positions.getState(capabilities, PRIMARY_ZERO_IS_CLOSED);
|
||||||
|
@ -216,27 +205,17 @@ public class HDPowerViewJUnitTests {
|
||||||
if (allowShadeMovementCommands) {
|
if (allowShadeMovementCommands) {
|
||||||
webTargets.moveShade(shadeId, targetPosition);
|
webTargets.moveShade(shadeId, targetPosition);
|
||||||
|
|
||||||
Shade newShade = webTargets.getShade(shadeId);
|
ShadeData newData = webTargets.getShade(shadeId);
|
||||||
assertNotNull(newShade);
|
|
||||||
if (newShade != null) {
|
|
||||||
ShadeData newData = newShade.shade;
|
|
||||||
assertNotNull(newData);
|
|
||||||
if (newData != null) {
|
|
||||||
ShadePosition actualPosition = newData.positions;
|
ShadePosition actualPosition = newData.positions;
|
||||||
assertNotNull(actualPosition);
|
assertNotNull(actualPosition);
|
||||||
if (actualPosition != null) {
|
if (actualPosition != null) {
|
||||||
assertEquals(
|
assertEquals(targetPosition.getState(capabilities, PRIMARY_ZERO_IS_CLOSED),
|
||||||
targetPosition.getState(capabilities, PRIMARY_ZERO_IS_CLOSED),
|
|
||||||
actualPosition.getState(capabilities, PRIMARY_ZERO_IS_CLOSED));
|
actualPosition.getState(capabilities, PRIMARY_ZERO_IS_CLOSED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (HubException e) {
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (HubProcessingException | HubMaintenanceException e) {
|
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +234,7 @@ public class HDPowerViewJUnitTests {
|
||||||
try {
|
try {
|
||||||
assertNotNull(sceneId);
|
assertNotNull(sceneId);
|
||||||
webTargets.stopShade(shadeId);
|
webTargets.stopShade(shadeId);
|
||||||
} catch (HubProcessingException | HubMaintenanceException e) {
|
} catch (HubException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue