Skip to content

Commit

Permalink
Added some more debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Jan 25, 2020
1 parent 7823c84 commit 00c1f62
Showing 1 changed file with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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())) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -355,6 +359,7 @@ public Collection<ChannelType> getChannelTypes(@Nullable final Locale locale) {
}

public StateChange checkStateChangeValid(SensiboSky sensiboSky, String property, Object value) {

StateChange stateChange = new StateChange(value);

ModeCapability currentModeCapabilities = sensiboSky.getCurrentModeCapabilities();
Expand All @@ -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(),
Expand All @@ -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;
}

Expand All @@ -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() + "]";
}

}
Expand Down

0 comments on commit 00c1f62

Please sign in to comment.