Search in sources :

Example 1 with Action

use of org.openhab.binding.pilight.internal.communication.Action in project openhab1-addons by openhab.

the class PilightBinding method createUpdateCommand.

private Action createUpdateCommand(Command command, PilightBindingConfig config) {
    Action action = new Action(Action.ACTION_CONTROL);
    Code code = new Code();
    code.setDevice(config.getDevice());
    if (command instanceof OnOffType) {
        setOnOffValue((OnOffType) command, code);
    } else if (command instanceof PercentType) {
        setDimmerValue((PercentType) command, code);
    } else {
        logger.error("Only OnOffType and PercentType can be changed by the pilight binding");
        return null;
    }
    action.setCode(code);
    return action;
}
Also used : Action(org.openhab.binding.pilight.internal.communication.Action) OnOffType(org.openhab.core.library.types.OnOffType) PercentType(org.openhab.core.library.types.PercentType) Code(org.openhab.binding.pilight.internal.communication.Code)

Example 2 with Action

use of org.openhab.binding.pilight.internal.communication.Action in project openhab1-addons by openhab.

the class PilightConnector method internalRefreshConfig.

private void internalRefreshConfig() throws JsonGenerationException, JsonMappingException, IOException {
    if (!updatingConfig) {
        updatingConfig = true;
        logger.info("Updating pilight config");
        Socket socket = connection.getSocket();
        outputMapper.writeValue(socket.getOutputStream(), new Action(Action.ACTION_REQUEST_CONFIG));
    }
}
Also used : Action(org.openhab.binding.pilight.internal.communication.Action) Socket(java.net.Socket)

Example 3 with Action

use of org.openhab.binding.pilight.internal.communication.Action in project openhab1-addons by openhab.

the class PilightBinding method internalReceiveCommand.

/**
     * @{inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    PilightBindingProvider provider = findFirstMatchingBindingProvider(itemName);
    PilightBindingConfig config = provider.getBindingConfig(itemName);
    PilightConnection connection = connections.get(config.getInstance());
    Action action = createUpdateCommand(command, config);
    if (action != null) {
        sendUpdate(action, connection);
    }
}
Also used : PilightBindingProvider(org.openhab.binding.pilight.PilightBindingProvider) Action(org.openhab.binding.pilight.internal.communication.Action)

Aggregations

Action (org.openhab.binding.pilight.internal.communication.Action)3 Socket (java.net.Socket)1 PilightBindingProvider (org.openhab.binding.pilight.PilightBindingProvider)1 Code (org.openhab.binding.pilight.internal.communication.Code)1 OnOffType (org.openhab.core.library.types.OnOffType)1 PercentType (org.openhab.core.library.types.PercentType)1