Search in sources :

Example 6 with ContactItem

use of org.openhab.core.library.items.ContactItem 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 7 with ContactItem

use of org.openhab.core.library.items.ContactItem in project openhab1-addons by openhab.

the class OneWireBindingConfigFactory method createOneWireDeviceProperty.

/**
     * @param pvItem
     * @param pvBindingConfig
     * @return a new BindingConfig, corresponding to the given
     *         <code><pvItem/code> and <code><pvBindingConfig/code>
     * @throws BindingConfigParseException
     */
public static OneWireBindingConfig createOneWireDeviceProperty(Item pvItem, String pvBindingConfig) throws BindingConfigParseException {
    logger.debug("createOneWireDeviceProperty: {} - bindingConfig:{}", pvItem.getName(), pvBindingConfig);
    OneWireBindingConfig lvNewBindingConfig = null;
    if (OneWireClearCacheControlBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireClearCacheControlBindingConfig(pvBindingConfig);
    } else if (OneWireDevicePropertyPushButtonBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireDevicePropertyPushButtonBindingConfig(pvBindingConfig);
    } else if (OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof NumberItem) {
        lvNewBindingConfig = new OneWireDevicePropertyNumberBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof ContactItem) {
        lvNewBindingConfig = new OneWireDevicePropertyContactBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof SwitchItem) {
        lvNewBindingConfig = new OneWireDevicePropertySwitchBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof StringItem) {
        lvNewBindingConfig = new OneWireDevicePropertyStringBindingConfig(pvBindingConfig);
    } else {
        throw new UnsupportedOperationException("the item-type " + pvItem.getClass() + " cannot be a onewire device");
    }
    logger.debug("created newBindingConfig: {}", lvNewBindingConfig.toString());
    return lvNewBindingConfig;
}
Also used : OneWireDevicePropertyPushButtonBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyPushButtonBindingConfig) OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig) OneWireDevicePropertySwitchBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchBindingConfig) OneWireDevicePropertyStringBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyStringBindingConfig) ContactItem(org.openhab.core.library.items.ContactItem) OneWireClearCacheControlBindingConfig(org.openhab.binding.onewire.internal.control.OneWireClearCacheControlBindingConfig) StringItem(org.openhab.core.library.items.StringItem) OneWireDevicePropertyNumberBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyNumberBindingConfig) NumberItem(org.openhab.core.library.items.NumberItem) OneWireDevicePropertyContactBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyContactBindingConfig) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 8 with ContactItem

use of org.openhab.core.library.items.ContactItem in project openhab1-addons by openhab.

the class GPIOGenericBindingProvider method processBindingConfiguration.

@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    /* Not sure when must be called, other bindings seems to call it at the beginning */
    super.processBindingConfiguration(context, item, bindingConfig);
    GPIOPinBindingConfig config = new GPIOPinBindingConfig();
    /* Configuration string should be in the form "pin:NUMBER [debounse:NUMBER] [activelow:yes|no]" */
    String[] properties = bindingConfig.split(" ");
    if (properties.length > 3) {
        logger.error("Wrong number of arguments (" + properties.length + ") in configuration string '" + bindingConfig + "'");
        throw new BindingConfigParseException("Wrong number of agruments (" + properties.length + ") in configuration string '" + bindingConfig + "'");
    }
    for (String property : properties) {
        String[] keyValueStructure = property.split(":");
        if (keyValueStructure.length != 2) {
            logger.error("Incorrect key:value structure (" + property + ") in configuration string '" + bindingConfig + "'");
            throw new BindingConfigParseException("Incorrect key:value structure (" + property + ") in configuration string '" + bindingConfig + "'");
        }
        String key = keyValueStructure[0];
        String value = keyValueStructure[1];
        if (key.compareToIgnoreCase("pin") == 0) {
            try {
                config.pinNumber = Integer.parseInt(value);
                if (config.pinNumber < 0) {
                    logger.error("Unsupported, negative value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                    throw new BindingConfigParseException("Unsupported, negative value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                }
            } catch (NumberFormatException e) {
                logger.error("Unsupported, not numeric value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported, not numeric value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("force") == 0) {
            config.pinForce = false;
            if (value.compareToIgnoreCase("yes") == 0 || value.compareToIgnoreCase("true") == 0) {
                config.pinForce = true;
            } else if (value.compareToIgnoreCase("no") != 0 && value.compareToIgnoreCase("false") != 0) {
                logger.error("Unsupported value for force (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported value for force (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("debounce") == 0) {
            try {
                config.debounceInterval = Long.parseLong(value);
                if (config.debounceInterval < 0) {
                    logger.error("Unsupported, negative value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                    throw new BindingConfigParseException("Unsupported, negative value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                }
            } catch (NumberFormatException e) {
                logger.error("Unsupported, not numeric value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported, not numeric value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("activelow") == 0) {
            if (value.compareToIgnoreCase("yes") == 0) {
                config.activeLow = GPIOPin.ACTIVELOW_ENABLED;
            } else if (value.compareToIgnoreCase("no") != 0) {
                logger.error("Unsupported value for activelow (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported value for activelow (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else {
            logger.error("Unsupported key (" + key + ") in configuration string '" + bindingConfig + "'");
            throw new BindingConfigParseException("Unsupported key (" + key + ") in configuration string '" + bindingConfig + "'");
        }
    }
    /* Pin number wasn't configured */
    if (config.pinNumber == GPIOBindingProvider.PINNUMBER_UNDEFINED) {
        logger.error("Mandatory parameter (pin) is missing in configuration string '" + bindingConfig + "'");
        throw new BindingConfigParseException("Mandatory parameter (pin) is missing in configuration string '" + bindingConfig + "'");
    }
    if (item instanceof ContactItem) {
        config.direction = GPIOPin.DIRECTION_IN;
    } else {
        /* Item type 'Switch' */
        config.direction = GPIOPin.DIRECTION_OUT;
    }
    addBindingConfig(item, config);
}
Also used : ContactItem(org.openhab.core.library.items.ContactItem) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 9 with ContactItem

use of org.openhab.core.library.items.ContactItem in project openhab1-addons by openhab.

the class IhcDataConverter method convertResourceValueToState.

/**
     * Convert IHC data type to openHAB data type.
     *
     * @param itemType
     *            OpenHAB data type class
     * @param value
     *            IHC data value
     *
     * @return openHAB {@link State}
     */
public static State convertResourceValueToState(Class<? extends Item> itemType, WSResourceValue value) throws NumberFormatException {
    org.openhab.core.types.State state = UnDefType.UNDEF;
    if (itemType == NumberItem.class) {
        if (value.getClass() == WSFloatingPointValue.class) {
            // state = new
            // DecimalType(((WSFloatingPointValue)value).getFloatingPointValue());
            // Controller might send floating point value with >10 decimals
            // (22.299999237060546875), so round value to have max 2
            // decimals
            double d = ((WSFloatingPointValue) value).getFloatingPointValue();
            BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN);
            state = new DecimalType(bd);
        } else if (value.getClass() == WSBooleanValue.class) {
            state = new DecimalType(((WSBooleanValue) value).isValue() ? 1 : 0);
        } else if (value.getClass() == WSIntegerValue.class) {
            state = new DecimalType(((WSIntegerValue) value).getInteger());
        } else if (value.getClass() == WSTimerValue.class) {
            state = new DecimalType(((WSTimerValue) value).getMilliseconds());
        } else if (value.getClass() == WSEnumValue.class) {
            state = new DecimalType(((WSEnumValue) value).getEnumValueID());
        } else if (value.getClass() == WSWeekdayValue.class) {
            state = new DecimalType(((WSWeekdayValue) value).getWeekdayNumber());
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to NumberItem");
        }
    } else if (itemType == DimmerItem.class) {
        if (value.getClass() == WSIntegerValue.class) {
            state = new PercentType(((WSIntegerValue) value).getInteger());
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to NumberItem");
        }
    } else if (itemType == SwitchItem.class) {
        if (value.getClass() == WSBooleanValue.class) {
            if (((WSBooleanValue) value).isValue()) {
                state = OnOffType.ON;
            } else {
                state = OnOffType.OFF;
            }
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to SwitchItem");
        }
    } else if (itemType == ContactItem.class) {
        if (value.getClass() == WSBooleanValue.class) {
            if (((WSBooleanValue) value).isValue()) {
                state = OpenClosedType.OPEN;
            } else {
                state = OpenClosedType.CLOSED;
            }
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to ContactItem");
        }
    } else if (itemType == DateTimeItem.class) {
        if (value.getClass() == WSDateValue.class) {
            Calendar cal = WSDateTimeToCalendar((WSDateValue) value, null);
            state = new DateTimeType(cal);
        } else if (value.getClass() == WSTimeValue.class) {
            Calendar cal = WSDateTimeToCalendar(null, (WSTimeValue) value);
            state = new DateTimeType(cal);
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to DateTimeItem");
        }
    } else if (itemType == StringItem.class) {
        if (value.getClass() == WSEnumValue.class) {
            state = new StringType(((WSEnumValue) value).getEnumName());
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to StringItem");
        }
    } else if (itemType == RollershutterItem.class) {
        if (value.getClass() == WSIntegerValue.class) {
            state = new PercentType(((WSIntegerValue) value).getInteger());
        } else {
            throw new NumberFormatException("Can't convert " + value.getClass().toString() + " to NumberItem");
        }
    }
    return state;
}
Also used : WSIntegerValue(org.openhab.binding.ihc.ws.datatypes.WSIntegerValue) WSFloatingPointValue(org.openhab.binding.ihc.ws.datatypes.WSFloatingPointValue) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) ContactItem(org.openhab.core.library.items.ContactItem) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) WSEnumValue(org.openhab.binding.ihc.ws.datatypes.WSEnumValue) WSTimeValue(org.openhab.binding.ihc.ws.datatypes.WSTimeValue) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) BigDecimal(java.math.BigDecimal) DateTimeType(org.openhab.core.library.types.DateTimeType) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) WSWeekdayValue(org.openhab.binding.ihc.ws.datatypes.WSWeekdayValue) WSBooleanValue(org.openhab.binding.ihc.ws.datatypes.WSBooleanValue) WSTimerValue(org.openhab.binding.ihc.ws.datatypes.WSTimerValue)

Example 10 with ContactItem

use of org.openhab.core.library.items.ContactItem in project openhab1-addons by openhab.

the class Zone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int current = ((properties.getStatus() >> 0) & 0x03);
    int latched = ((properties.getStatus() >> 2) & 0x03);
    int arming = ((properties.getStatus() >> 4) & 0x03);
    String latchedTxt = (latched < LATCHED_TEXT.length ? LATCHED_TEXT[latched] : "?");
    String armingTxt = (arming < ARMING_TEXT.length ? ARMING_TEXT[arming] : "?");
    String currentTxt = (current < CURRENT_TEXT.length ? CURRENT_TEXT[current] : "?");
    int setting = 0;
    String str = "";
    switch(config.getObjectType()) {
        case ZONE_STATUS_ARMING:
            setting = arming;
            str = armingTxt;
            break;
        case ZONE_STATUS_CURRENT:
            setting = current;
            str = currentTxt;
            break;
        case ZONE_STATUS_LATCHED:
            setting = latched;
            str = latchedTxt;
            break;
        case ZONE_STATUS_ALL:
            str = currentTxt + " | " + latchedTxt + " | " + armingTxt;
            break;
        default:
            break;
    }
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof StringItem) {
        publisher.postUpdate(item.getName(), new StringType(str));
    } else if (item instanceof ContactItem) {
        publisher.postUpdate(item.getName(), current == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) ContactItem(org.openhab.core.library.items.ContactItem) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem)

Aggregations

ContactItem (org.openhab.core.library.items.ContactItem)19 NumberItem (org.openhab.core.library.items.NumberItem)15 SwitchItem (org.openhab.core.library.items.SwitchItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)11 DecimalType (org.openhab.core.library.types.DecimalType)11 RollershutterItem (org.openhab.core.library.items.RollershutterItem)10 StringType (org.openhab.core.library.types.StringType)9 Item (org.openhab.core.items.Item)8 Calendar (java.util.Calendar)7 ColorItem (org.openhab.core.library.items.ColorItem)7 DateTimeItem (org.openhab.core.library.items.DateTimeItem)7 DateTimeType (org.openhab.core.library.types.DateTimeType)7 PercentType (org.openhab.core.library.types.PercentType)7 State (org.openhab.core.types.State)7 StringItem (org.openhab.core.library.items.StringItem)6 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)5 HSBType (org.openhab.core.library.types.HSBType)5 BigDecimal (java.math.BigDecimal)3 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)3 SappBindingConfigDimmerItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem)3