Fix signalStrength channel update after REFRESH command (#12930)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2022-06-13 07:46:20 +02:00 committed by GitHub
parent 0cee45f4d5
commit ebca0812d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 23 deletions

View File

@ -28,6 +28,7 @@ import org.eclipse.jetty.http.HttpMethod;
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;
@ -637,12 +638,12 @@ public class HDPowerViewWebTargets {
* 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);
@ -651,7 +652,11 @@ public class HDPowerViewWebTargets {
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);
}

View File

@ -13,7 +13,6 @@
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;
@ -30,18 +29,6 @@ import com.google.gson.annotations.SerializedName;
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;
}

View File

@ -16,7 +16,9 @@ import static org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstan
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;
@ -29,8 +31,8 @@ import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
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;
@ -257,7 +259,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
updatePositionStates(shadePosition);
}
updateBatteryStates(shadeData.batteryStatus, shadeData.batteryStrength);
updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
updateSignalStrengthState(shadeData.signalStrength);
}
private void updateCapabilities(ShadeData shade) {
@ -423,6 +425,10 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
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 {
@ -528,11 +534,22 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
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: