use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class ItemStateRequestProcessor method getState.
private StateTransformable getState(Item item) {
StateTransformable state = null;
if (item.getState() instanceof HSBType) {
HSBType hsb = (HSBType) item.getState();
state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue());
} else if (item.getState() instanceof DateTimeType) {
DateTimeType dt = (DateTimeType) item.getState();
DateTimeDataType data = new DateTimeDataType(dt.toString());
state = new DateTimeData(data);
} else if (item.getState() instanceof DecimalType) {
} else if (item.getState() instanceof OnOffType) {
} else if (item.getState() instanceof OpenClosedType) {
} else if (item.getState() instanceof PercentType) {
} else if (item.getState() instanceof UpDownType) {
}
return state;
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class OutputVisualize method visualizationHandleOutputStatus.
/** {@inheritDoc} */
@Override
public boolean visualizationHandleOutputStatus(ModStatusOutput pchkInput, Command cmd, Item item, EventPublisher eventPublisher) {
if (pchkInput.getLogicalSourceAddr().equals(this.addr) && pchkInput.getOutputId() == this.outputId) {
if (item.getAcceptedDataTypes().contains(StringType.class)) {
String value = new DecimalFormat("0.#").format(pchkInput.getPercent());
eventPublisher.postUpdate(item.getName(), new StringType(value));
return true;
} else if (item.getAcceptedDataTypes().contains(PercentType.class)) {
eventPublisher.postUpdate(item.getName(), new PercentType((int) Math.round(pchkInput.getPercent())));
return true;
} else if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
eventPublisher.postUpdate(item.getName(), new DecimalType(pchkInput.getPercent()));
return true;
} else if (item.getAcceptedDataTypes().contains(OnOffType.class)) {
eventPublisher.postUpdate(item.getName(), pchkInput.getPercent() != 0 ? OnOffType.ON : OnOffType.OFF);
return true;
}
}
return false;
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class MilightBinding method sendWarmer.
private PercentType sendWarmer(int bulb, String bridgeId) {
logger.debug("milight: sendWarmer");
int newPercent = getCurrentState(bulb, bridgeId, BindingType.brightness).intValue() + 10;
if (newPercent > 100) {
newPercent = 100;
}
PercentType newValue = new PercentType(newPercent);
String messageBytes = "3E:00:55";
sendMessage(messageBytes, bridgeId);
setCurrentState(bulb, bridgeId, newValue, BindingType.brightness);
return newValue;
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class MilightBinding method internalReceiveCommand.
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
super.internalReceiveCommand(itemName, command);
MilightBindingConfig deviceConfig = getConfigForItemName(itemName);
if (deviceConfig == null) {
return;
}
try {
int bulb = deviceConfig.getChannelNumber();
int rgbwSteps = deviceConfig.getSteps();
String bridgeId = deviceConfig.getDeviceId();
if (deviceConfig.getCommandType().equals(BindingType.brightness)) {
logger.debug("milight: item is of type brightness");
if (OnOffType.ON.equals(command)) {
sendOn(bulb, bridgeId);
} else if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
PercentType newValue = sendIncrease(bulb, rgbwSteps, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
PercentType newValue = sendDecrease(bulb, rgbwSteps, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (command instanceof PercentType) {
logger.debug("milight: command is of type PercentType");
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.brightness);
}
} else if (deviceConfig.getCommandType().equals(BindingType.nightMode)) {
logger.debug("milight: item is of type nightMode");
if (OnOffType.ON.equals(command)) {
sendNightMode(bulb, bridgeId);
}
if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
} else if (deviceConfig.getCommandType().equals(BindingType.whiteMode)) {
logger.debug("milight: item is of type whiteMode");
if (OnOffType.ON.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendWhiteMode(bulb, bridgeId);
}
if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
} else if (deviceConfig.getCommandType().equals(BindingType.colorTemperature)) {
logger.debug("milight: item is of type warm/cold white");
if (OnOffType.ON.equals(command)) {
sendPercent(bulb, rgbwSteps, bridgeId, PercentType.HUNDRED, BindingType.colorTemperature);
} else if (OnOffType.OFF.equals(command)) {
sendPercent(bulb, rgbwSteps, bridgeId, PercentType.ZERO, BindingType.colorTemperature);
} else if (IncreaseDecreaseType.INCREASE.equals(command)) {
PercentType newValue = sendWarmer(bulb, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
PercentType newValue = sendCooler(bulb, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.colorTemperature);
}
} else if (deviceConfig.getCommandType().equals(BindingType.discoMode)) {
logger.debug("milight: item is of type discoMode");
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendDiscoModeUp(bulb, bridgeId);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
sendDiscoModeDown(bulb, bridgeId);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.discoMode);
}
} else if (deviceConfig.getCommandType().equals(BindingType.discoSpeed)) {
logger.debug("milight: item is of type discoSpeed");
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendIncreaseSpeed(bulb, bridgeId);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendDecreaseSpeed(bulb, bridgeId);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.discoSpeed);
}
} else if (deviceConfig.getCommandType().equals(BindingType.rgb)) {
logger.debug("milight: item is of type rgb");
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
DecimalType saturation = hsbCommand.getSaturation();
if (saturation.equals(0)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendWhiteMode(bulb, bridgeId);
} else {
sendColor(command, bridgeId, bulb);
}
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.brightness);
}
}
} catch (Exception e) {
logger.error("milight: Failed to send {} command ", deviceConfig.getCommandType(), e);
}
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class MilightBinding method sendCooler.
private PercentType sendCooler(int bulb, String bridgeId) {
logger.debug("milight: sendCooler");
int newPercent = getCurrentState(bulb, bridgeId, BindingType.brightness).intValue() - 10;
if (newPercent < 0) {
newPercent = 0;
}
PercentType newValue = new PercentType(newPercent);
String messageBytes = "3F:00:55";
sendMessage(messageBytes, bridgeId);
setCurrentState(bulb, bridgeId, newValue, BindingType.brightness);
return newValue;
}
Aggregations