@Override public void handleCommand(final Command command) { if (clusterOnOffServer == null) { logger.warn("{}: OnOff converter is not linked to a server and cannot accept commands", endpoint.getIeeeAddress()); return; } OnOffType cmdOnOff = null; if (command instanceof PercentType) { if (((PercentType) command).intValue() == 0) { cmdOnOff = OnOffType.OFF; } else { cmdOnOff = OnOffType.ON; } } else if (command instanceof OnOffType) { cmdOnOff = (OnOffType) command; } else { logger.warn("{}: OnOff converter only accepts PercentType and OnOffType - not {}", endpoint.getIeeeAddress(), command.getClass().getSimpleName()); return; } if (cmdOnOff == OnOffType.ON) { clusterOnOffServer.onCommand(); } else { clusterOnOffServer.offCommand(); } }
/** * Convert an integer value into a PercentType state. * This handles inversion, and setting value to 100% when ZWave returns the maximum value of 99% * * @param value the integer value (range 0 to 100) * @param invert true to invert the state * @return {@link PercentType} state */ protected PercentType convertPercent(int value, boolean invert) { // Don't allow values out of range if (value < 0 || value > 100) { return null; } PercentType state = null; if (invert) { state = new PercentType(100 - value); } else { state = new PercentType(value); } // If we read greater than 99%, then change it to 100% // This just appears better in OH otherwise you can't get 100%! if (state.intValue() >= 99) { state = new PercentType(100); } return state; }
private void changeBrightness(PercentType brightness) throws InterruptedException, ExecutionException { if (clusterLevelControl == null) { if (clusterOnOff != null) { changeOnOff(brightness.intValue() == 0 ? OnOffType.OFF : OnOffType.ON); } else { logger.warn("{}: ignoring brightness command", endpoint.getIeeeAddress()); } return; } HSBType oldHSB = currentHSB; currentHSB = new HSBType(oldHSB.getHue(), oldHSB.getSaturation(), brightness); lastBrightness = brightness; int level = percentToLevel(brightness); if (clusterOnOff != null) { if (brightness.equals(PercentType.ZERO)) { clusterOnOff.offCommand(); } else { clusterLevelControl.moveToLevelWithOnOffCommand(level, configLevelControl.getDefaultTransitionTime()) .get(); } } else { clusterLevelControl.moveToLevelCommand(level, configLevelControl.getDefaultTransitionTime()).get(); } }
int value = percentType.intValue(); if (configInvertPercent) { value = 100 - value;