Search in sources :

Example 21 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class AlarmDecoderBinding method parseKeypadMessage.

private void parseKeypadMessage(String msg) throws MessageParseException {
    List<String> parts = splitMsg(msg);
    if (parts.size() != 4) {
        throw new MessageParseException("got invalid keypad msg");
    }
    if (parts.get(0).length() != 22) {
        throw new MessageParseException("bad keypad status length : " + parts.get(0).length());
    }
    try {
        int numeric = 0;
        try {
            numeric = Integer.parseInt(parts.get(1));
        } catch (NumberFormatException e) {
            numeric = Integer.parseInt(parts.get(1), 16);
        }
        int upper = Integer.parseInt(parts.get(0).substring(1, 6), 2);
        int nbeeps = Integer.parseInt(parts.get(0).substring(6, 7));
        int lower = Integer.parseInt(parts.get(0).substring(7, 17), 2);
        int status = ((upper & 0x1F) << 13) | ((nbeeps & 0x3) << 10) | lower;
        ArrayList<AlarmDecoderBindingConfig> bcl = getItems(ADMsgType.KPM, null, null);
        for (AlarmDecoderBindingConfig c : bcl) {
            if (c.hasFeature("zone")) {
                updateItem(c, new DecimalType(numeric));
            } else if (c.hasFeature("text")) {
                updateItem(c, new StringType(parts.get(3)));
            } else if (c.hasFeature("beeps")) {
                updateItem(c, new DecimalType(nbeeps));
            } else if (c.hasFeature("status")) {
                int bit = c.getIntParameter("bit", 0, 17, -1);
                if (bit >= 0) {
                    // only pick a single bit
                    int v = (status >> bit) & 0x1;
                    updateItem(c, new DecimalType(v));
                } else {
                    // pick all bits
                    updateItem(c, new DecimalType(status));
                }
            } else if (c.hasFeature("contact")) {
                int bit = c.getIntParameter("bit", 0, 17, -1);
                if (bit >= 0) {
                    // only pick a single bit
                    int v = (status >> bit) & 0x1;
                    updateItem(c, (v == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
                } else {
                    // pick all bits
                    logger.warn("ignoring item {}: it has contact without bit field", c.getItemName());
                }
            }
        }
        if ((status & (1 << 17)) != 0) {
            // the panel is clear, so we can assume that all contacts that we
            // have not heard from are open
            setUnupdatedItemsToDefault();
        }
    } catch (NumberFormatException e) {
        throw new MessageParseException("keypad msg contains invalid number: " + e.getMessage());
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 22 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class AlarmDecoderBinding method parseLRRMessage.

private void parseLRRMessage(String msg) throws MessageParseException {
    String[] parts = splitMessage(msg);
    if (parts.length != 3) {
        throw new MessageParseException("need 3 comma separated fields in msg");
    }
    ArrayList<AlarmDecoderBindingConfig> bcl = getItems(ADMsgType.LRR, null, null);
    for (AlarmDecoderBindingConfig c : bcl) {
        updateItem(c, new StringType(String.join(",", parts)));
    }
}
Also used : StringType(org.openhab.core.library.types.StringType)

Example 23 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class Iec6205621MeterBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    // the frequently executed code (polling) goes here ...
    Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
    for (Iec6205621MeterBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
                Meter reader = entry.getValue();
                String meterName = provider.getMeterName(itemName);
                if (meterName != null && meterName.equals(entry.getKey())) {
                    Map<String, DataSet> dataSets;
                    if ((dataSets = cache.get(meterName)) == null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
                        }
                        dataSets = reader.read();
                        cache.put(meterName, dataSets);
                    }
                    String obis = provider.getObis(itemName);
                    if (obis != null && dataSets.containsKey(obis)) {
                        DataSet dataSet = dataSets.get(obis);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
                        }
                        Class<? extends Item> itemType = provider.getItemType(itemName);
                        if (itemType.isAssignableFrom(NumberItem.class)) {
                            eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
                        }
                        if (itemType.isAssignableFrom(StringItem.class)) {
                            String value = dataSet.getValue();
                            eventPublisher.postUpdate(itemName, new StringType(value));
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DataSet(org.openmuc.j62056.DataSet) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) HashMap(java.util.HashMap) Map(java.util.Map) Iec6205621MeterBindingProvider(org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider)

Example 24 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class Area method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int setting = 0;
    String str = "";
    switch(config.getObjectType()) {
        case AREA_ENTRY_TIMER:
            setting = properties.getEntryTimer();
            break;
        case AREA_EXIT_TIMER:
            setting = properties.getExitTimer();
            break;
        case AREA_STATUS_ENTRY_DELAY:
            setting = properties.getEntryDelay();
            break;
        case AREA_STATUS_EXIT_DELAY:
            setting = properties.getExitDelay();
            break;
        case AREA_STATUS_MODE:
            setting = properties.getMode();
            str = omni ? (setting < omniText.length ? omniText[setting] : "Unknown") : (setting < luminaText.length ? luminaText[setting] : "Unknown");
            break;
        case AREA_STATUS_ALARM:
            setting = properties.getAlarms();
            for (int i = 0; i < alarms.length; i++) {
                if (((setting >> i) & 1) > 0) {
                    if (str.length() > 0) {
                        str += " | ";
                    }
                    str += alarms[i];
                }
            }
            break;
        default:
            break;
    }
    logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof StringItem) {
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem)

Example 25 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class Thermostat method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int setting = 0;
    String mode = null;
    switch(config.getObjectType()) {
        case THERMO_COOL_POINT:
            setting = celsius ? MessageUtils.omniToC(properties.getCoolSetpoint()) : MessageUtils.omniToF(properties.getCoolSetpoint());
            break;
        case THERMO_TEMP:
            setting = celsius ? MessageUtils.omniToC(properties.getTemperature()) : MessageUtils.omniToF(properties.getTemperature());
            break;
        case THERMO_HEAT_POINT:
            setting = celsius ? MessageUtils.omniToC(properties.getHeatSetpoint()) : MessageUtils.omniToF(properties.getHeatSetpoint());
            break;
        case THERMO_FAN_MODE:
            setting = properties.isFan() ? 1 : 0;
            break;
        case THERMO_HOLD_MODE:
            setting = properties.isHold() ? 1 : 0;
            break;
        case THERMO_SYSTEM_MODE:
            setting = properties.getMode();
            if (setting < MODES.length) {
                mode = MODES[setting];
            }
            break;
        default:
            return;
    }
    logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof SwitchItem) {
        publisher.postUpdate(item.getName(), setting > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem && mode != null) {
        publisher.postUpdate(item.getName(), new StringType(mode));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

StringType (org.openhab.core.library.types.StringType)90 DecimalType (org.openhab.core.library.types.DecimalType)69 State (org.openhab.core.types.State)30 DateTimeType (org.openhab.core.library.types.DateTimeType)28 PercentType (org.openhab.core.library.types.PercentType)27 NumberItem (org.openhab.core.library.items.NumberItem)25 Calendar (java.util.Calendar)23 StringItem (org.openhab.core.library.items.StringItem)18 OnOffType (org.openhab.core.library.types.OnOffType)15 SwitchItem (org.openhab.core.library.items.SwitchItem)12 ContactItem (org.openhab.core.library.items.ContactItem)10 DimmerItem (org.openhab.core.library.items.DimmerItem)10 RollershutterItem (org.openhab.core.library.items.RollershutterItem)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)8 HSBType (org.openhab.core.library.types.HSBType)8 ConfigurationException (org.osgi.service.cm.ConfigurationException)8 IOException (java.io.IOException)7 BigDecimal (java.math.BigDecimal)7