import org.eclipse.jetty.http.HttpStatus;
import org.openhab.binding.hdpowerview.internal.api.Color;
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
+import org.openhab.binding.hdpowerview.internal.api.SurveyData;
import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterBlinking;
import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterColor;
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeCalibrate;
* class instance
*
* @param shadeId id of the shade to be surveyed
- * @return Survey class instance
+ * @return List of SurveyData class instances
* @throws HubInvalidResponseException if response is invalid
* @throws HubProcessingException if there is any processing error
* @throws HubMaintenanceException if the hub is down for maintenance
*/
- public Survey getShadeSurvey(int shadeId)
+ public List<SurveyData> getShadeSurvey(int shadeId)
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
Query.of("survey", Boolean.toString(true)), null);
if (survey == null) {
throw new HubInvalidResponseException("Missing survey response");
}
- return survey;
+ List<SurveyData> surveyData = survey.surveyData;
+ if (surveyData == null) {
+ throw new HubInvalidResponseException("Missing 'survey.surveyData' element");
+ }
+ return surveyData;
} catch (JsonParseException e) {
throw new HubInvalidResponseException("Error parsing survey response", e);
}
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;
public class Survey {
@SerializedName("shade_id")
public int shadeId;
- @Nullable
@SerializedName("survey")
- public List<SurveyData> surveyData;
-
- @Override
- public String toString() {
- List<SurveyData> surveyData = this.surveyData;
- if (surveyData == null) {
- return "{}";
- }
- StringJoiner joiner = new StringJoiner(", ");
- surveyData.forEach(data -> joiner.add(data.toString()));
- return joiner.toString();
- }
+ public @Nullable List<SurveyData> surveyData;
}
import static org.openhab.binding.hdpowerview.internal.api.CoordinateSystem.*;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.StringJoiner;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;
import org.openhab.binding.hdpowerview.internal.api.Firmware;
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
+import org.openhab.binding.hdpowerview.internal.api.SurveyData;
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.config.HDPowerViewShadeConfiguration;
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
updatePositionStates(shadePosition);
}
updateBatteryStates(shadeData.batteryStatus, shadeData.batteryStrength);
- updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
+ updateSignalStrengthState(shadeData.signalStrength);
}
private void updateCapabilities(ShadeData shade) {
updateState(CHANNEL_SHADE_BATTERY_LEVEL, new DecimalType(mappedValue));
}
+ private void updateSignalStrengthState(int signalStrength) {
+ updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(signalStrength));
+ }
+
private void moveShade(CoordinateSystem coordSys, int newPercent, HDPowerViewWebTargets webTargets, int shadeId)
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException,
HubShadeTimeoutException {
updateDetectedCapabilities(shadeData);
break;
case SURVEY:
- Survey survey = webTargets.getShadeSurvey(shadeId);
- if (survey.surveyData != null) {
- logger.debug("Survey response for shade {}: {}", survey.shadeId, survey.toString());
+ List<SurveyData> surveyData = webTargets.getShadeSurvey(shadeId);
+ if (!surveyData.isEmpty()) {
+ if (logger.isDebugEnabled()) {
+ StringJoiner joiner = new StringJoiner(", ");
+ surveyData.forEach(data -> joiner.add(data.toString()));
+ logger.debug("Survey response for shade {}: {}", shadeId, joiner.toString());
+ }
+ shadeData = webTargets.getShade(shadeId);
+ updateSignalStrengthState(shadeData.signalStrength);
} else {
- logger.warn("No response from shade {} survey", shadeId);
+ logger.info("No data from shade {} survey", shadeId);
+ /*
+ * Setting channel to UNDEF here would be reverted on next poll, since
+ * signal strength is part of shade response. So leaving current value,
+ * even though refreshing the value failed.
+ */
}
break;
case BATTERY_LEVEL: