use of org.openhab.binding.squeezebox.SqueezeboxBindingConfig in project openhab1-addons by openhab.
the class SqueezeboxBinding method internalReceiveCommand.
/**
* @{inheritDoc}
*/
@Override
public void internalReceiveCommand(String itemName, Command command) {
if (squeezeServer == null) {
logger.warn("Squeeze Server not initialised or configured yet, ignoring command '{}' for item '{}'", command.toString(), itemName);
return;
}
logger.trace("internalReceiveCommand(itemname = {}, command = {})", itemName, command.toString());
for (SqueezeboxBindingProvider provider : providers) {
SqueezeboxBindingConfig bindingConfig = provider.getSqueezeboxBindingConfig(itemName);
String playerId = bindingConfig.getPlayerId();
try {
switch(bindingConfig.getCommandType()) {
case POWER:
if (command.equals(OnOffType.ON)) {
squeezeServer.powerOn(playerId);
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.powerOff(playerId);
}
break;
case MUTE:
if (command.equals(OnOffType.ON)) {
squeezeServer.mute(playerId);
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.unMute(playerId);
}
break;
case VOLUME:
if (command.equals(IncreaseDecreaseType.INCREASE)) {
squeezeServer.volumeUp(playerId);
} else if (command.equals(IncreaseDecreaseType.DECREASE)) {
squeezeServer.volumeDown(playerId);
} else if (command.equals(UpDownType.UP)) {
squeezeServer.volumeUp(playerId);
} else if (command.equals(UpDownType.DOWN)) {
squeezeServer.volumeDown(playerId);
} else if (command instanceof DecimalType) {
squeezeServer.setVolume(playerId, ((DecimalType) command).intValue());
}
break;
case PLAY:
if (command.equals(OnOffType.ON)) {
squeezeServer.play(playerId);
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.stop(playerId);
}
break;
case PAUSE:
if (command.equals(OnOffType.ON)) {
squeezeServer.pause(playerId);
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.unPause(playerId);
}
break;
case STOP:
if (command.equals(OnOffType.ON)) {
squeezeServer.stop(playerId);
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.play(playerId);
}
break;
case NEXT:
if (command.equals(OnOffType.ON)) {
squeezeServer.next(playerId);
}
break;
case PREV:
if (command.equals(OnOffType.ON)) {
squeezeServer.prev(playerId);
}
break;
case HTTP:
if (command.equals(OnOffType.ON)) {
squeezeServer.playUrl(playerId, "http://" + bindingConfig.getExtra());
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.stop(playerId);
}
break;
case FILE:
if (command.equals(OnOffType.ON)) {
squeezeServer.playUrl(playerId, "file://" + bindingConfig.getExtra());
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.stop(playerId);
}
break;
case SYNC:
if (command.equals(OnOffType.ON)) {
squeezeServer.syncPlayer(playerId, bindingConfig.getExtra());
} else if (command.equals(OnOffType.OFF)) {
squeezeServer.unSyncPlayer(bindingConfig.getExtra());
}
break;
case COMMAND:
if (command instanceof StringType) {
squeezeServer.playerCommand(playerId, command.toString());
} else {
squeezeServer.playerCommand(playerId, bindingConfig.getExtra());
}
break;
default:
logger.warn("Unsupported command type '{}'", bindingConfig.getCommandType());
}
} catch (Exception e) {
logger.warn("Error executing command type '{}'", bindingConfig.getCommandType(), e);
}
}
}
use of org.openhab.binding.squeezebox.SqueezeboxBindingConfig in project openhab1-addons by openhab.
the class SqueezeboxBinding method getItemNames.
private List<String> getItemNames(String playerId, CommandType commandType) {
List<String> itemNames = new ArrayList<String>();
for (SqueezeboxBindingProvider provider : this.providers) {
for (String itemName : provider.getItemNames()) {
SqueezeboxBindingConfig bindingConfig = provider.getSqueezeboxBindingConfig(itemName);
if (!bindingConfig.getPlayerId().equals(playerId)) {
continue;
}
if (!bindingConfig.getCommandType().equals(commandType)) {
continue;
}
itemNames.add(itemName);
}
}
return itemNames;
}
use of org.openhab.binding.squeezebox.SqueezeboxBindingConfig in project openhab1-addons by openhab.
the class SqueezeboxGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
SqueezeboxBindingConfig config = parseBindingConfig(bindingConfig);
addBindingConfig(item, config);
}
Aggregations