Search in sources :

Example 11 with StringItem

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

the class JdbcBaseDAO method getItemType.

public String getItemType(Item i) {
    Item item = i;
    String def = "STRINGITEM";
    if (i instanceof GroupItem) {
        item = ((GroupItem) i).getBaseItem();
        if (item == null) {
            // if GroupItem:<ItemType> is not defined in
            // *.items using StringType
            // logger.debug("JDBC: BaseItem GroupItem:<ItemType> is not
            // defined in *.items searching for first Member and try to use
            // as ItemType");
            logger.debug("JDBC::getItemType: Cannot detect ItemType for {} because the GroupItems' base type isn't set in *.items File.", i.getName());
            item = ((GroupItem) i).getMembers().get(0);
            if (item == null) {
                logger.debug("JDBC::getItemType: No ItemType found for first Child-Member of GroupItem {}, use ItemType for STRINGITEM as Fallback", i.getName());
                return def;
            }
        }
    }
    String itemType = item.getClass().getSimpleName().toUpperCase();
    logger.debug("JDBC::getItemType: Try to use ItemType {} for Item {}", itemType, i.getName());
    if (sqlTypes.get(itemType) == null) {
        logger.warn("JDBC::getItemType: No sqlType found for ItemType {}, use ItemType for STRINGITEM as Fallback for {}", itemType, i.getName());
        return def;
    }
    return itemType;
}
Also used : DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) JdbcItem(org.openhab.persistence.jdbc.model.JdbcItem) ColorItem(org.openhab.core.library.items.ColorItem) DateTimeItem(org.openhab.core.library.items.DateTimeItem) HistoricItem(org.openhab.core.persistence.HistoricItem) NumberItem(org.openhab.core.library.items.NumberItem) GroupItem(org.openhab.core.items.GroupItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ContactItem(org.openhab.core.library.items.ContactItem) GroupItem(org.openhab.core.items.GroupItem)

Example 12 with StringItem

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

the class LightwaveRfBindingFunctionalTest method testWifiLinkStatusReceived.

@Test
public void testWifiLinkStatusReceived() throws Exception {
    String message = "*!{\"trans\":452,\"mac\":\"ab:cd:ef\",\"time\":1447712274,\"type\":\"hub\",\"prod\":\"wfl\",\"fw\":\"U2.91Y\"," + "\"uptime\":1386309,\"timeZone\":0,\"lat\":52.48,\"long\":-87.89,\"duskTime\":1447690400," + "\"dawnTime\":1447659083,\"tmrs\":0,\"evns\":1,\"run\":0,\"macs\":8,\"ip\":\"192.168.0.1\",\"devs\":0}";
    List<ItemConfigAndExpectedState> itemConfigAndExpectedStates = new LinkedList<ItemConfigAndExpectedState>();
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_IP"), "serial=wifilink,type=WIFILINK_IP", new StringType("192.168.0.1")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_FIRMWARE"), "serial=wifilink,type=WIFILINK_FIRMWARE", new StringType("U2.91Y")));
    Calendar duskCal = Calendar.getInstance();
    duskCal.setTime(new Date(1447690400000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DUSK_TIME"), "serial=wifilink,type=WIFILINK_DUSK_TIME", new DateTimeType(duskCal)));
    Calendar dawnCal = Calendar.getInstance();
    dawnCal.setTime(new Date(1447659083000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DAWN_TIME"), "serial=wifilink,type=WIFILINK_DAWN_TIME", new DateTimeType(dawnCal)));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("WIFILINK_UPTIME"), "serial=wifilink,type=WIFILINK_UPTIME", new DecimalType("1386309")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LONGITUDE"), "serial=wifilink,type=WIFILINK_LONGITUDE", new StringType("-87.89")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LATITUDE"), "serial=wifilink,type=WIFILINK_LATITUDE", new StringType("52.48")));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(1447712274000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("TIME"), "serial=wifilink,type=UPDATETIME", new DateTimeType(cal)));
    testReceivingACommandAndVerify(itemConfigAndExpectedStates, message);
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Example 13 with StringItem

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

the class LcnGenericBindingProvider method processBindingConfiguration.

/**
     * Item processing for the LCN bindings.
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    Matcher matcher = PATTERN_BINDING_GENERAL.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException(bindingConfig + "' contains no valid binding!");
    }
    matcher.reset();
    LcnBindingConfig bc = new LcnBindingConfig(item);
    while (matcher.find()) {
        String binding = matcher.group(1);
        if (binding != null && !binding.trim().isEmpty()) {
            String openHabCmd = null;
            String connId, lcnTarget;
            Matcher openHabMatcher = PATTERN_BINDING_WITH_OPENHAB.matcher(binding);
            Matcher pureMatcher = PATTERN_BINDING_PURE.matcher(binding);
            if (openHabMatcher.matches()) {
                openHabCmd = openHabMatcher.group(1);
                connId = openHabMatcher.group(2);
                lcnTarget = openHabMatcher.group(3);
            } else if (pureMatcher.matches()) {
                connId = pureMatcher.group(1);
                lcnTarget = pureMatcher.group(2);
            } else {
                throw new BindingConfigParseException("Invalid binding configuration for " + binding + "!");
            }
            String lcnShort = resolveMappings(lcnTarget, openHabCmd);
            if (lcnShort == null || lcnShort.equals(openHabCmd)) {
                lcnShort = lcnTarget;
            }
            Command cmd = openHabCmd == null ? TypeParser.parseCommand(new StringItem("").getAcceptedCommandTypes(), "") : openHabCmd.equals("%i") ? new StringType("%i") : TypeParser.parseCommand(item.getAcceptedCommandTypes(), openHabCmd);
            bc.add(new LcnBindingConfig.Mapping(cmd, connId, lcnShort));
        }
    }
    // Finished
    this.addBindingConfig(item, bc);
    for (LcnAddrMod addr : bc.getRelatedModules()) {
        HashSet<String> l = this.itemNamesByModulCache.get(addr);
        if (l == null) {
            l = new HashSet<String>();
            this.itemNamesByModulCache.put(addr, l);
        }
        l.add(item.getName());
    }
}
Also used : Matcher(java.util.regex.Matcher) Command(org.openhab.core.types.Command) StringType(org.openhab.core.library.types.StringType) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) StringItem(org.openhab.core.library.items.StringItem) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 14 with StringItem

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

the class AudioZone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int num = 0;
    String str = "";
    int source = new Integer(properties.getSource());
    switch(config.getObjectType()) {
        case AUDIOZONE_MUTE:
            num = properties.isMute() ? 1 : 0;
            break;
        case AUDIOZONE_POWER:
            num = properties.isOn() ? 1 : 0;
            break;
        case AUDIOZONE_SOURCE:
            num = properties.getSource();
            break;
        case AUDIOZONE_VOLUME:
            num = properties.getVolume();
            break;
        case AUDIOZONE_TEXT:
            if (sourceValid(source)) {
                str = audioSources.get(source).formatAudioText();
            }
            break;
        case AUDIOZONE_TEXT_FIELD1:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(0);
            }
            break;
        case AUDIOZONE_TEXT_FIELD2:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(1);
            }
            break;
        case AUDIOZONE_TEXT_FIELD3:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(2);
            }
            break;
        case AUDIOZONE_KEY:
            num = -1;
            break;
        default:
            return;
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", num);
        publisher.postUpdate(item.getName(), new PercentType(num));
    } else if (item instanceof NumberItem) {
        logger.debug("updating number type {}", num);
        publisher.postUpdate(item.getName(), new DecimalType(num));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", num > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), num > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", str);
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 15 with StringItem

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

the class PulseaudioGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    PulseaudioBindingConfig config = new PulseaudioBindingConfig();
    String[] configParts = bindingConfig.split(":");
    if (item instanceof StringItem) {
        if (configParts.length != 1 && configParts.length != 3) {
            throw new BindingConfigParseException("Pulseaudio binding configuration for StringItems must consist of one or three part [config=" + configParts + "]");
        }
        config.serverId = StringUtils.trim(configParts[0]);
        config.itemType = item.getClass();
        addBindingConfig(item, config);
        return;
    } else if (configParts.length < 2 || configParts.length > 3) {
        throw new BindingConfigParseException("Pulseaudio binding configuration must consist of two or three parts [config=" + configParts + "]");
    }
    config.serverId = StringUtils.trim(configParts[0]);
    config.itemName = StringUtils.trim(configParts[1]);
    if (configParts.length == 3) {
        config.command = StringUtils.trim(configParts[2]);
    }
    config.itemType = item.getClass();
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) StringItem(org.openhab.core.library.items.StringItem)

Aggregations

StringItem (org.openhab.core.library.items.StringItem)27 NumberItem (org.openhab.core.library.items.NumberItem)16 StringType (org.openhab.core.library.types.StringType)16 DecimalType (org.openhab.core.library.types.DecimalType)14 SwitchItem (org.openhab.core.library.items.SwitchItem)12 DimmerItem (org.openhab.core.library.items.DimmerItem)8 DateTimeType (org.openhab.core.library.types.DateTimeType)8 Test (org.junit.Test)7 ContactItem (org.openhab.core.library.items.ContactItem)7 Calendar (java.util.Calendar)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)5 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 PercentType (org.openhab.core.library.types.PercentType)5 BigDecimal (java.math.BigDecimal)4 ColorItem (org.openhab.core.library.items.ColorItem)4 Date (java.util.Date)3 Item (org.openhab.core.items.Item)3 State (org.openhab.core.types.State)3 LinkedList (java.util.LinkedList)2 JSONException (org.json.JSONException)2