Fix signalStrength channel update after REFRESH command (#12930)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
0cee45f4d5
commit
ebca0812d1
@ -28,6 +28,7 @@ import org.eclipse.jetty.http.HttpMethod;
|
|||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.Color;
|
import org.openhab.binding.hdpowerview.internal.api.Color;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
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.RepeaterBlinking;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterColor;
|
import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterColor;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeCalibrate;
|
import org.openhab.binding.hdpowerview.internal.api.requests.ShadeCalibrate;
|
||||||
@ -637,12 +638,12 @@ public class HDPowerViewWebTargets {
|
|||||||
* class instance
|
* class instance
|
||||||
*
|
*
|
||||||
* @param shadeId id of the shade to be surveyed
|
* @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 HubInvalidResponseException if response is invalid
|
||||||
* @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 Survey getShadeSurvey(int shadeId)
|
public List<SurveyData> getShadeSurvey(int shadeId)
|
||||||
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
|
||||||
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
String jsonResponse = invoke(HttpMethod.GET, shades + Integer.toString(shadeId),
|
||||||
Query.of("survey", Boolean.toString(true)), null);
|
Query.of("survey", Boolean.toString(true)), null);
|
||||||
@ -651,7 +652,11 @@ public class HDPowerViewWebTargets {
|
|||||||
if (survey == null) {
|
if (survey == null) {
|
||||||
throw new HubInvalidResponseException("Missing survey response");
|
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) {
|
} catch (JsonParseException e) {
|
||||||
throw new HubInvalidResponseException("Error parsing survey response", e);
|
throw new HubInvalidResponseException("Error parsing survey response", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
package org.openhab.binding.hdpowerview.internal.api.responses;
|
package org.openhab.binding.hdpowerview.internal.api.responses;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@ -30,18 +29,6 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
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 @Nullable 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,9 @@ import static org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstan
|
|||||||
import static org.openhab.binding.hdpowerview.internal.api.CoordinateSystem.*;
|
import static org.openhab.binding.hdpowerview.internal.api.CoordinateSystem.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringJoiner;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.CoordinateSystem;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
import org.openhab.binding.hdpowerview.internal.api.Firmware;
|
||||||
import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
|
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.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.config.HDPowerViewShadeConfiguration;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase;
|
||||||
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
import org.openhab.binding.hdpowerview.internal.database.ShadeCapabilitiesDatabase.Capabilities;
|
||||||
@ -257,7 +259,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||||||
updatePositionStates(shadePosition);
|
updatePositionStates(shadePosition);
|
||||||
}
|
}
|
||||||
updateBatteryStates(shadeData.batteryStatus, shadeData.batteryStrength);
|
updateBatteryStates(shadeData.batteryStatus, shadeData.batteryStrength);
|
||||||
updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
|
updateSignalStrengthState(shadeData.signalStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCapabilities(ShadeData shade) {
|
private void updateCapabilities(ShadeData shade) {
|
||||||
@ -423,6 +425,10 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||||||
updateState(CHANNEL_SHADE_BATTERY_LEVEL, new DecimalType(mappedValue));
|
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)
|
private void moveShade(CoordinateSystem coordSys, int newPercent, HDPowerViewWebTargets webTargets, int shadeId)
|
||||||
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException,
|
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException,
|
||||||
HubShadeTimeoutException {
|
HubShadeTimeoutException {
|
||||||
@ -528,11 +534,22 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||||||
updateDetectedCapabilities(shadeData);
|
updateDetectedCapabilities(shadeData);
|
||||||
break;
|
break;
|
||||||
case SURVEY:
|
case SURVEY:
|
||||||
Survey survey = webTargets.getShadeSurvey(shadeId);
|
List<SurveyData> surveyData = webTargets.getShadeSurvey(shadeId);
|
||||||
if (survey.surveyData != null) {
|
if (!surveyData.isEmpty()) {
|
||||||
logger.debug("Survey response for shade {}: {}", survey.shadeId, survey.toString());
|
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 {
|
} 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;
|
break;
|
||||||
case BATTERY_LEVEL:
|
case BATTERY_LEVEL:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user