use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class MpdBinding method volumeChanged.
/**
* Implementation of {@link VolumeChangeListener}. Posts the volume value
* of the {@link VolumeChangeEvent} onto the internal event bus.
*
* @param vce the event which volume value is posted onto the internal event bus
*/
@Override
public void volumeChanged(VolumeChangeEvent vce) {
String playerId = findPlayerId(vce.getSource());
int volume = vce.getVolume();
if (volumeInvalid(volume)) {
logger.warn("Ignoring volume change because the volume is invalid: {}", volume);
} else {
logger.debug("Volume on player '{}' changed to {}", playerId, volume);
String[] itemNames = getItemNamesByPlayerAndPlayerCommand(playerId, PlayerCommandTypeMapping.VOLUME);
for (String itemName : itemNames) {
if (StringUtils.isNotBlank(itemName)) {
eventPublisher.postUpdate(itemName, new PercentType(volume));
}
}
}
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class MpdBinding method internalReceiveCommand.
/**
* @{inheritDoc}
*/
@Override
public void internalReceiveCommand(String itemName, Command command) {
MpdBindingProvider provider;
String matchingPlayerCommand;
// nothing by default
Object params = new Object();
if (command instanceof PercentType) {
// we have received volume adjustment request
matchingPlayerCommand = "PERCENT";
params = command;
} else if (command instanceof DecimalType) {
// we have received play song id request
matchingPlayerCommand = "NUMBER";
params = command;
} else {
matchingPlayerCommand = command.toString();
}
provider = findFirstMatchingBindingProvider(itemName, matchingPlayerCommand);
if (provider == null) {
logger.warn("Cannot find matching binding provider [itemName={}, command={}]", itemName, command);
return;
}
String playerCommand = provider.getPlayerCommand(itemName, matchingPlayerCommand);
if (StringUtils.isNotBlank(playerCommand)) {
String playerCommandParam = provider.getPlayerCommandParam(itemName, matchingPlayerCommand);
if (playerCommandParam != null) {
params = playerCommandParam;
}
executePlayerCommand(playerCommand, params);
}
}
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());
}
}
Aggregations