use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class WagoBinding method updateItemPWM.
public void updateItemPWM(String itemName, String couplerName, int module, int[] values) {
for (WagoBindingProvider provider : providers) {
if (provider.providesBindingFor(itemName)) {
WagoBindingConfig conf = provider.getConfig(itemName);
if (conf.couplerName.equals(couplerName) && conf.module == module) {
State currentState = conf.getItemState();
State newState;
if (conf.getItem() instanceof DimmerItem) {
newState = new PercentType((int) ((float) values[conf.channel] / 1023 * 100));
} else if (conf.getItem() instanceof SwitchItem) {
if (values[conf.channel] == 0) {
newState = OnOffType.OFF;
} else {
newState = OnOffType.ON;
}
} else {
logger.debug("Unsupported Itemtype");
return;
}
if (!newState.equals(currentState)) {
eventPublisher.postUpdate(itemName, newState);
}
}
}
}
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class UPBBinding method messageReceived.
/**
* {@inheritDoc}
*/
@Override
public void messageReceived(UPBMessage message) {
if (message.getType() != Type.MESSAGE_REPORT) {
return;
}
String sourceName = getItemName(message.getSource(), false);
String destinationName = getItemName(message.getDestination(), message.getControlWord().isLink());
UPBBindingConfig sourceConfig = getConfig(sourceName);
UPBBindingConfig destinationConfig = getConfig(destinationName);
String itemName = isValidId(message.getDestination()) ? destinationName : sourceName;
UPBBindingConfig config = isValidId(message.getDestination()) ? destinationConfig : sourceConfig;
if (itemName == null || config == null) {
logger.debug("Received message for unknown {} with id {}.", message.getControlWord().isLink() ? "Link" : "Device", message.getDestination() & 0xff);
return;
}
State newState = null;
byte level = 100;
switch(message.getCommand()) {
case GOTO:
case DEVICE_STATE:
case ACTIVATE:
if (message.getArguments() != null && message.getArguments().length > 0) {
level = message.getArguments()[0];
} else {
level = (byte) (message.getCommand() == UPBMessage.Command.ACTIVATE ? 100 : 0);
}
// Links will send FF (-1) for their level.
if (level == -1 || level >= 100 || (level > 0 && !config.isDimmable())) {
newState = OnOffType.ON;
} else if (level == 0) {
newState = OnOffType.OFF;
} else {
newState = new PercentType(level);
}
break;
case DEACTIVATE:
newState = OnOffType.OFF;
break;
default:
break;
}
if (newState != null) {
logger.debug("Posting update: {},{}", itemName, newState);
eventPublisher.postUpdate(itemName, newState);
}
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class XbmcConnector method processApplicationStateChanged.
private void processApplicationStateChanged(String method, Map<String, Object> json) {
if ("Application.OnVolumeChanged".equals(method)) {
// get the player id and make a new request for the media details
Map<String, Object> params = RpcCall.getMap(json, "params");
Map<String, Object> data = RpcCall.getMap(params, "data");
Object o = data.get("volume");
PercentType volume = new PercentType(0);
if (o instanceof Integer) {
volume = new PercentType((Integer) o);
} else {
if (o instanceof Double) {
volume = new PercentType(((Double) o).intValue());
}
}
updateProperty("Application.Volume", volume);
this.volume = new BigDecimal(volume.intValue());
}
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class LightwaveRfBindingFunctionalTest method testInOnlyMessageReceived.
@Test
public void testInOnlyMessageReceived() throws Exception {
String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
testReceivingACommandAndVerify(new DimmerItem("LivingRoom"), "<room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class LightwaveRfBindingFunctionalTest method testDimMessageSentByAndriodApp.
@Test
public void testDimMessageSentByAndriodApp() throws Exception {
String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
testReceivingACommandAndVerify(new DimmerItem("LivingRoom"), "room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
Aggregations