[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.ShadeMove;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop;
|
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.SceneCollections;
|
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.Scenes;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.responses.ScheduledEvents;
|
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.
|
* 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 JsonParseException if there is a JSON parsing 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 @Nullable FirmwareVersion getFirmwareVersion()
|
public FirmwareVersions getFirmwareVersions()
|
||||||
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
throws JsonParseException, HubProcessingException, HubMaintenanceException {
|
||||||
String json = invoke(HttpMethod.GET, firmwareVersion, null, null);
|
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;
|
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
|
* Firmware version information for HD PowerView components
|
||||||
*
|
*
|
||||||
* @author Jacob Laursen - Initial contribution
|
* @author Jacob Laursen - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class Firmware {
|
public class Firmware {
|
||||||
|
@Nullable
|
||||||
public String name;
|
public String name;
|
||||||
public int revision;
|
public int revision;
|
||||||
public int subRevision;
|
public int subRevision;
|
||||||
|
|||||||
@ -12,11 +12,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.hdpowerview.internal.api.responses;
|
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
|
* Firmware information for an HD PowerView hub
|
||||||
*
|
*
|
||||||
* @author Jacob Laursen - Initial contribution
|
* @author Jacob Laursen - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class FirmwareVersion {
|
public class FirmwareVersion {
|
||||||
|
@Nullable
|
||||||
public FirmwareVersions firmware;
|
public FirmwareVersions firmware;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.hdpowerview.internal.api.responses;
|
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;
|
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
|
* @author Jacob Laursen - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class FirmwareVersions {
|
public class FirmwareVersions {
|
||||||
|
@Nullable
|
||||||
public Firmware mainProcessor;
|
public Firmware mainProcessor;
|
||||||
|
@Nullable
|
||||||
public Firmware radio;
|
public Firmware radio;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,9 @@ package org.openhab.binding.hdpowerview.internal.api.responses;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,9 +25,11 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
*
|
*
|
||||||
* @author Jacob Laursen - Initial contribution
|
* @author Jacob Laursen - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class Survey {
|
public class Survey {
|
||||||
@SerializedName("shade_id")
|
@SerializedName("shade_id")
|
||||||
public int shadeId;
|
public int shadeId;
|
||||||
|
@Nullable
|
||||||
@SerializedName("survey")
|
@SerializedName("survey")
|
||||||
public List<SurveyData> surveyData;
|
public List<SurveyData> surveyData;
|
||||||
|
|
||||||
@ -41,6 +46,7 @@ public class Survey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
List<SurveyData> surveyData = this.surveyData;
|
||||||
if (surveyData == null) {
|
if (surveyData == null) {
|
||||||
return "{}";
|
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.HubMaintenanceException;
|
||||||
import org.openhab.binding.hdpowerview.internal.HubProcessingException;
|
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.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.SceneCollections.SceneCollection;
|
||||||
@ -286,24 +285,20 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
if (webTargets == null) {
|
if (webTargets == null) {
|
||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
FirmwareVersion firmwareVersion = webTargets.getFirmwareVersion();
|
FirmwareVersions firmwareVersions = webTargets.getFirmwareVersions();
|
||||||
if (firmwareVersion == null || firmwareVersion.firmware == null) {
|
Firmware mainProcessor = firmwareVersions.mainProcessor;
|
||||||
logger.warn("Unable to get firmware version.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.firmwareVersions = firmwareVersion.firmware;
|
|
||||||
Firmware mainProcessor = firmwareVersion.firmware.mainProcessor;
|
|
||||||
if (mainProcessor == null) {
|
if (mainProcessor == null) {
|
||||||
logger.warn("Main processor firmware version missing in response.");
|
logger.warn("Main processor firmware version missing in response.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("Main processor firmware version received: {}, {}", mainProcessor.name, mainProcessor.toString());
|
logger.debug("Main processor firmware version received: {}, {}", mainProcessor.name, mainProcessor.toString());
|
||||||
Map<String, String> properties = editProperties();
|
Map<String, String> properties = editProperties();
|
||||||
if (mainProcessor.name != null) {
|
String mainProcessorName = mainProcessor.name;
|
||||||
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_NAME, mainProcessor.name);
|
if (mainProcessorName != null) {
|
||||||
|
properties.put(HDPowerViewBindingConstants.PROPERTY_FIRMWARE_NAME, mainProcessorName);
|
||||||
}
|
}
|
||||||
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, mainProcessor.toString());
|
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, mainProcessor.toString());
|
||||||
Firmware radio = firmwareVersion.firmware.radio;
|
Firmware radio = firmwareVersions.radio;
|
||||||
if (radio != null) {
|
if (radio != null) {
|
||||||
logger.debug("Radio firmware version received: {}", radio.toString());
|
logger.debug("Radio firmware version received: {}", radio.toString());
|
||||||
properties.put(HDPowerViewBindingConstants.PROPERTY_RADIO_FIRMWARE_VERSION, radio.toString());
|
properties.put(HDPowerViewBindingConstants.PROPERTY_RADIO_FIRMWARE_VERSION, radio.toString());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user