Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hdpowerview] Fix SAT warnings #12032

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -130,15 +131,23 @@ public HDPowerViewWebTargets(HttpClient httpClient, String ipAddress) {
/**
* 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
*/
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;

/**
* Firmware information for an HD PowerView hub
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public class FirmwareVersions {
@Nullable
public Firmware mainProcessor;
@Nullable
public Firmware radio;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
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;

/**
* Survey data of a single Shade, as returned by an HD PowerView hub
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public class Survey {
@SerializedName("shade_id")
public int shadeId;
@Nullable
@SerializedName("survey")
public List<SurveyData> surveyData;

Expand All @@ -41,6 +46,7 @@ public String toString() {

@Override
public String toString() {
List<SurveyData> surveyData = this.surveyData;
if (surveyData == null) {
return "{}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
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;
Expand Down Expand Up @@ -286,24 +285,20 @@ private void updateFirmwareProperties() throws JsonParseException, HubProcessing
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());
Expand Down