From 00c1f62547f3c7c8c45d9aac5437a0f2e90c7a6a Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Sat, 25 Jan 2020 16:34:21 +0100 Subject: [PATCH] Added some more debug info --- .../internal/handler/SensiboSkyHandler.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java index 3f141efc2d0da..2ffbca161eb29 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java @@ -77,6 +77,10 @@ */ @NonNullByDefault public class SensiboSkyHandler extends SensiboBaseThingHandler implements ChannelTypeProvider { + public static final String SWING_PROPERTY = "swing"; + public static final String MASTER_SWITCH_PROPERTY = "on"; + public static final String FAN_LEVEL_PROPERTY = "fanLevel"; + public static final String MODE_PROPERTY = "mode"; public static final String TARGET_TEMPERATURE_PROPERTY = "targetTemperature"; private final Logger logger = LoggerFactory.getLogger(SensiboSkyHandler.class); private @NonNullByDefault({}) SensiboSkyConfiguration config; @@ -130,7 +134,7 @@ protected void handleCommand(final ChannelUID channelUID, final Command command, updateState(channelUID, unit.getAcState().isOn() ? OnOffType.ON : OnOffType.OFF); } else if (command instanceof OnOffType) { final OnOffType newValue = (OnOffType) command; - updateAcState(unit, "on", newValue == OnOffType.ON); + updateAcState(unit, MASTER_SWITCH_PROPERTY, newValue == OnOffType.ON); } } else if (CHANNEL_TARGET_TEMPERATURE.equals(channelUID.getId())) { if (command instanceof RefreshType) { @@ -166,7 +170,7 @@ protected void handleCommand(final ChannelUID channelUID, final Command command, updateState(channelUID, new StringType(unit.getAcState().getMode())); } else if (command instanceof StringType) { final StringType newValue = (StringType) command; - updateAcState(unit, "mode", newValue.toString()); + updateAcState(unit, MODE_PROPERTY, newValue.toString()); addDynamicChannelsAndProperties(unit); } } else if (CHANNEL_SWING_MODE.equals(channelUID.getId())) { @@ -179,7 +183,7 @@ protected void handleCommand(final ChannelUID channelUID, final Command command, } else if (command instanceof StringType) { final StringType newValue = (StringType) command; - updateAcState(unit, "swing", newValue.toString()); + updateAcState(unit, SWING_PROPERTY, newValue.toString()); } } else if (CHANNEL_FAN_LEVEL.equals(channelUID.getId())) { if (command instanceof RefreshType) { @@ -190,7 +194,7 @@ protected void handleCommand(final ChannelUID channelUID, final Command command, } } else if (command instanceof StringType) { final StringType newValue = (StringType) command; - updateAcState(unit, "fanLevel", newValue.toString()); + updateAcState(unit, FAN_LEVEL_PROPERTY, newValue.toString()); } } else if (CHANNEL_TIMER.equals(channelUID.getId())) { if (command instanceof RefreshType) { @@ -355,6 +359,7 @@ public Collection getChannelTypes(@Nullable final Locale locale) { } public StateChange checkStateChangeValid(SensiboSky sensiboSky, String property, Object value) { + StateChange stateChange = new StateChange(value); ModeCapability currentModeCapabilities = sensiboSky.getCurrentModeCapabilities(); @@ -368,31 +373,31 @@ public StateChange checkStateChangeValid(SensiboSky sensiboSky, String property, DecimalType rawValue = (DecimalType) value; stateChange.updateValue(rawValue.intValue()); if (!validTemperatures.validValues.contains(rawValue.intValue())) { - stateChange.addError( - String.format("Cannot change targetTemperature to %s, valid targetTemperatures are %s", - value, ToStringBuilder.reflectionToString( - validTemperatures.validValues.toArray(), ToStringStyle.SIMPLE_STYLE))); + stateChange.addError(String.format( + "Cannot change targetTemperature to '%d', valid targetTemperatures are one of %s", + rawValue.intValue(), ToStringBuilder.reflectionToString( + validTemperatures.validValues.toArray(), ToStringStyle.SIMPLE_STYLE))); } } break; - case "mode": + case MODE_PROPERTY: if (!sensiboSky.getRemoteCapabilities().keySet().contains(value)) { stateChange.addError(String.format("Cannot change mode to %s, valid modes are %s", value, ToStringBuilder.reflectionToString(sensiboSky.getRemoteCapabilities().keySet().toArray(), ToStringStyle.SIMPLE_STYLE))); } break; - case "fanLevel": + case FAN_LEVEL_PROPERTY: if (currentModeCapabilities != null && !currentModeCapabilities.fanLevels.contains(value)) { stateChange.addError(String.format("Cannot change fanLevel to %s, valid fanLevels are %s", value, ToStringBuilder.reflectionToString(currentModeCapabilities.fanLevels.toArray(), ToStringStyle.SIMPLE_STYLE))); } break; - case "on": + case MASTER_SWITCH_PROPERTY: // Always allowed break; - case "swing": + case SWING_PROPERTY: if (currentModeCapabilities != null && !currentModeCapabilities.swingModes.contains(value)) { stateChange.addError(String.format("Cannot change swing to %s, valid swings are %s", value, ToStringBuilder.reflectionToString(currentModeCapabilities.swingModes.toArray(), @@ -403,6 +408,8 @@ public StateChange checkStateChangeValid(SensiboSky sensiboSky, String property, stateChange.addError(String.format("No such ac state property %s", property)); } + logger.debug("State change request {}", stateChange); + return stateChange; } @@ -428,7 +435,8 @@ public void addError(String validationMessage) { @Override public String toString() { - return "StateChange [valid=" + valid + ", validationMessage=" + validationMessage + "]"; + return "StateChange [valid=" + valid + ", validationMessage=" + validationMessage + ", value=" + value + + ", value Class=" + value.getClass() + "]"; } }