[hdpowerview] Fix SAT warnings (#12032)
* Fix SAT warnings about missing @NonNullByDefault. * Move part of firmware JSON response validation to HDPowerViewWebTargets. Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
e3e4cd667d
commit
d07348b216
@ -29,6 +29,7 @@ import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
||||
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeMove;
|
||||
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.FirmwareVersions;
|
||||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections;
|
||||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes;
|
||||
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents;
|
||||
@ -130,15 +131,23 @@ public class HDPowerViewWebTargets {
|
||||
/**
|
||||
* Fetches a JSON package with firmware information for the hub.
|
||||
*
|
||||
* @return FirmwareVersion class instance
|
||||
* @return FirmwareVersions class instance
|
||||
* @throws JsonParseException if there is a JSON parsing error
|
||||
* @throws HubProcessingException if there is any processing error
|
||||
* @throws HubMaintenanceException if the hub is down for maintenance
|
||||
*/
|
||||
public @Nullable FirmwareVersion getFirmwareVersion()
|
||||
public FirmwareVersions getFirmwareVersions()
|
||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
||||
String json = invoke(HttpMethod.GET, firmwareVersion, null, null);
|
||||
return gson.fromJson(json, FirmwareVersion.class);
|
||||
FirmwareVersion firmwareVersion = gson.fromJson(json, FirmwareVersion.class);
|
||||
if (firmwareVersion == null) {
|
||||
throw new JsonParseException("Missing firmware response");
|
||||
}
|
||||
FirmwareVersions firmwareVersions = firmwareVersion.firmware;
|
||||
if (firmwareVersions == null) {
|
||||
throw new JsonParseException("Missing 'firmware' element");
|
||||
}
|
||||
return firmwareVersions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -12,12 +12,17 @@
|
||||
*/
|
||||
package org.openhab.binding.hdpowerview.internal.api;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Firmware version information for HD PowerView components
|
||||
*
|
||||
* @author Jacob Laursen - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Firmware {
|
||||
@Nullable
|
||||
public String name;
|
||||
public int revision;
|
||||
public int subRevision;
|
||||
|
||||
@ -12,11 +12,16 @@
|
||||
*/
|
||||
package org.openhab.binding.hdpowerview.internal.api.responses;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Firmware information for an HD PowerView hub
|
||||
*
|
||||
* @author Jacob Laursen - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class FirmwareVersion {
|
||||
@Nullable
|
||||
public FirmwareVersions firmware;
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.hdpowerview.internal.api.responses;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||
|
||||
/**
|
||||
@ -19,7 +21,10 @@ import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||
*
|
||||
* @author Jacob Laursen - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class FirmwareVersions {
|
||||
@Nullable
|
||||
public Firmware mainProcessor;
|
||||
@Nullable
|
||||
public Firmware radio;
|
||||
}
|
||||
|
||||
@ -15,6 +15,9 @@ package org.openhab.binding.hdpowerview.internal.api.responses;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
@ -22,9 +25,11 @@ import com.google.gson.annotations.SerializedName;
|
||||
*
|
||||
* @author Jacob Laursen - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Survey {
|
||||
@SerializedName("shade_id")
|
||||
public int shadeId;
|
||||
@Nullable
|
||||
@SerializedName("survey")
|
||||
public List<SurveyData> surveyData;
|
||||
|
||||
@ -41,6 +46,7 @@ public class Survey {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
List<SurveyData> surveyData = this.surveyData;
|
||||
if (surveyData == null) {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ 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.responses.FirmwareVersion;
|
||||
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.SceneCollection;
|
||||
@ -286,24 +285,20 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||
if (webTargets == null) {
|
||||
throw new ProcessingException("Web targets not initialized");
|
||||
}
|
||||
FirmwareVersion firmwareVersion = webTargets.getFirmwareVersion();
|
||||
if (firmwareVersion == null || firmwareVersion.firmware == null) {
|
||||
logger.warn("Unable to get firmware version.");
|
||||
return;
|
||||
}
|
||||
this.firmwareVersions = firmwareVersion.firmware;
|
||||
Firmware mainProcessor = firmwareVersion.firmware.mainProcessor;
|
||||
FirmwareVersions firmwareVersions = webTargets.getFirmwareVersions();
|
||||
Firmware mainProcessor = firmwareVersions.mainProcessor;
|
||||
if (mainProcessor == null) {
|
||||
logger.warn("Main processor firmware version missing in response.");
|
||||
return;
|
||||
}
|
||||
logger.debug("Main processor firmware version received: {}, {}", mainProcessor.name, mainProcessor.toString());
|
||||
Map<String, String> properties = editProperties();
|
||||
if (mainProcessor.name != null) {
|
||||
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_NAME, mainProcessor.name);
|
||||
String mainProcessorName = mainProcessor.name;
|
||||
if (mainProcessorName != null) {
|
||||
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_NAME, mainProcessorName);
|
||||
}
|
||||
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, mainProcessor.toString());
|
||||
Firmware radio = firmwareVersion.firmware.radio;
|
||||
Firmware radio = firmwareVersions.radio;
|
||||
if (radio != null) {
|
||||
logger.debug("Radio firmware version received: {}", radio.toString());
|
||||
properties.put(HDPowerViewBindingConstants.PROPERTY_RADIO_FIRMWARE_VERSION, radio.toString());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user