Search in sources :

Example 1 with MpdBindingProvider

use of org.openhab.binding.mpd.MpdBindingProvider 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);
    }
}
Also used : DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) MpdBindingProvider(org.openhab.binding.mpd.MpdBindingProvider)

Example 2 with MpdBindingProvider

use of org.openhab.binding.mpd.MpdBindingProvider in project openhab1-addons by openhab.

the class MpdBinding method getItemsByPlayerCommandAndOutput.

private String[] getItemsByPlayerCommandAndOutput(String playerId, PlayerCommandTypeMapping playerCommand, MPDOutput output) {
    Set<String> itemNames = new HashSet<String>();
    // internally mpd uses 0-based indexes
    int outputId = output.getId() + 1;
    for (MpdBindingProvider provider : this.providers) {
        itemNames.addAll(Arrays.asList(provider.getItemNamesByPlayerOutputCommand(playerId, playerCommand, outputId)));
    }
    return itemNames.toArray(new String[itemNames.size()]);
}
Also used : HashSet(java.util.HashSet) MpdBindingProvider(org.openhab.binding.mpd.MpdBindingProvider)

Aggregations

MpdBindingProvider (org.openhab.binding.mpd.MpdBindingProvider)2 HashSet (java.util.HashSet)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1