Search in sources :

Example 1 with XplBindingProvider

use of org.openhab.binding.xpl.XplBindingProvider in project openhab1-addons by openhab.

the class XplBinding method handleXPLMessage.

@Override
public void handleXPLMessage(xPL_MessageI theMessage) {
    for (XplBindingProvider provider : providers) {
        List<String> matchingItems = provider.hasMessage(theMessage);
        for (String itemName : matchingItems) {
            XplBindingConfig config = provider.getConfig(itemName);
            if (config == null) {
                continue;
            }
            String current = theMessage.getNamedValue(config.NamedParameter);
            Item item = provider.getItem(itemName);
            if (item != null) {
                if (item instanceof SwitchItem) {
                    OnOffType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OnOffType.ON : OnOffType.OFF;
                    synchronized (item) {
                        if (!item.getState().equals(status)) {
                            eventPublisher.postUpdate(itemName, status);
                            ((SwitchItem) item).setState(status);
                        }
                    }
                } else if (item instanceof ContactItem) {
                    OpenClosedType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
                    synchronized (item) {
                        if (!item.getState().equals(status)) {
                            eventPublisher.postUpdate(itemName, status);
                            ((ContactItem) item).setState(status);
                        }
                    }
                } else if (item instanceof NumberItem) {
                    DecimalType value = new DecimalType(current);
                    synchronized (item) {
                        if (!item.getState().equals(value)) {
                            eventPublisher.postUpdate(itemName, value);
                            ((NumberItem) item).setState(value);
                        }
                    }
                } else if (item instanceof StringItem) {
                    StringType value = new StringType(current);
                    synchronized (item) {
                        if (!item.getState().equals(value)) {
                            eventPublisher.postUpdate(itemName, value);
                            ((StringItem) item).setState(value);
                        }
                    }
                }
            }
        }
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) ContactItem(org.openhab.core.library.items.ContactItem) StringItem(org.openhab.core.library.items.StringItem) NumberItem(org.openhab.core.library.items.NumberItem) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ContactItem(org.openhab.core.library.items.ContactItem) NumberItem(org.openhab.core.library.items.NumberItem) XplBindingConfig(org.openhab.binding.xpl.XplBindingConfig) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) SwitchItem(org.openhab.core.library.items.SwitchItem) XplBindingProvider(org.openhab.binding.xpl.XplBindingProvider)

Example 2 with XplBindingProvider

use of org.openhab.binding.xpl.XplBindingProvider in project openhab1-addons by openhab.

the class XplBinding method internalReceiveCommand.

/**
     * Sends an xPL message upon command received by an Item
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    for (XplBindingProvider provider : providers) {
        XplBindingConfig config = provider.getConfig(itemName);
        if ((config == null) || (config.NamedParameter == null)) {
            continue;
        }
        if (config.Message.getSource() == null) {
            config.Message.setSource(xplTransportService.getSourceIdentifier());
        }
        config.Message.setNamedValue(config.NamedParameter, command.toString().toLowerCase());
        xplTransportService.sendMessage(config.Message);
    }
}
Also used : XplBindingConfig(org.openhab.binding.xpl.XplBindingConfig) XplBindingProvider(org.openhab.binding.xpl.XplBindingProvider)

Aggregations

XplBindingConfig (org.openhab.binding.xpl.XplBindingConfig)2 XplBindingProvider (org.openhab.binding.xpl.XplBindingProvider)2 Item (org.openhab.core.items.Item)1 ContactItem (org.openhab.core.library.items.ContactItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1 StringItem (org.openhab.core.library.items.StringItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 DecimalType (org.openhab.core.library.types.DecimalType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 OpenClosedType (org.openhab.core.library.types.OpenClosedType)1 StringType (org.openhab.core.library.types.StringType)1