Search in sources :

Example 1 with ProtocolRead

use of be.devlaminck.openwebnet.ProtocolRead in project openhab1-addons by openhab.

the class BticinoDevice method receiveCommand.

public void receiveCommand(String itemName, Command command, BticinoBindingConfig itemBindingConfig) {
    try {
        synchronized (m_lock) {
            // A command is received from the openHab system;
            // analyse it and execute it
            logger.debug("Gateway [" + m_gateway_id + "], Command '{}' received for item {}", (Object[]) new String[] { command.toString(), itemName });
            ProtocolRead l_pr = new ProtocolRead(itemBindingConfig.who + "*" + itemBindingConfig.where);
            l_pr.addProperty("who", itemBindingConfig.who);
            l_pr.addProperty("address", itemBindingConfig.where);
            int l_who = Integer.parseInt(itemBindingConfig.who);
            switch(l_who) {
                // Lights
                case 1:
                    {
                        if (command instanceof IncreaseDecreaseType) {
                            if (IncreaseDecreaseType.INCREASE.equals(command)) {
                                logger.debug("Light received INCREASE command.");
                                l_pr.addProperty("what", "30");
                            } else {
                                logger.debug("Light received DECREASE command.");
                                l_pr.addProperty("what", "31");
                            }
                        } else if (command instanceof PercentType) {
                            PercentType pType = (PercentType) command;
                            //take percentage and divide by 10, round 1 (ie 0 to 10 is the result, nothing else)
                            int percentValue = (int) (Math.floor(pType.intValue() / 10F));
                            logger.debug("Set light value to {}", percentValue);
                            l_pr.addProperty("what", String.valueOf(percentValue));
                        } else if (command instanceof OnOffType) {
                            if (OnOffType.ON.equals(command)) {
                                l_pr.addProperty("what", "1");
                            } else {
                                l_pr.addProperty("what", "0");
                            }
                        } else {
                            logger.warn("Received unknown command type for lighting: '{}'", command.getClass().getName());
                        }
                        break;
                    }
                // Shutter
                case 2:
                    {
                        if (UpDownType.UP.equals(command)) {
                            l_pr.addProperty("what", "1");
                        } else if (UpDownType.DOWN.equals(command)) {
                            l_pr.addProperty("what", "2");
                        } else if (StopMoveType.STOP.equals(command)) {
                            l_pr.addProperty("what", "0");
                        }
                        break;
                    }
                // CEN Basic & Evolved
                case 15:
                    {
                        // device
                        if (OnOffType.ON.equals(command)) {
                            l_pr.addProperty("what", itemBindingConfig.what);
                        }
                        break;
                    }
            }
            m_open_web_net.onCommand(l_pr);
        }
    } catch (Exception e) {
        logger.error("Gateway [" + m_gateway_id + "], Error processing receiveCommand '{}'", (Object[]) new String[] { e.getMessage() });
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) ProtocolRead(be.devlaminck.openwebnet.ProtocolRead)

Aggregations

ProtocolRead (be.devlaminck.openwebnet.ProtocolRead)1 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 PercentType (org.openhab.core.library.types.PercentType)1