Search in sources :

Example 36 with Item

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

the class NikobusGenericBindingProviderTest method parseButton.

private void parseButton(String name, String config, Button.PressType type, String address) throws BindingConfigParseException {
    Item item = new SwitchItem(name);
    provider.processBindingConfiguration("context", item, config);
    Button button = (Button) provider.getItemConfig(name);
    assertEquals(name, button.getName());
    assertEquals(address, button.getAddress());
    assertEquals(type, button.getType());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) Button(org.openhab.binding.nikobus.internal.config.Button) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 37 with Item

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

the class UCPRelayBoardBinding method readAndDecodeResponse.

private void readAndDecodeResponse(SerialDevice serialDevice) {
    byte[] response = serialDevice.readBytes(new byte[5]);
    if (validateResponse(response)) {
        for (int relay = 0; relay < 8; relay++) {
            Item item = getItemForRelay(serialDevice, relay);
            if (item != null) {
                UCPRelayConfig config = getRelayConfigForItem(item.getName());
                State state = getRelayState(response, relay, config);
                eventPublisher.postUpdate(item.getName(), state);
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) State(org.openhab.core.types.State)

Example 38 with Item

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

the class DSCAlarmActiveBinding method processUpdateMap.

/**
     * Processes the Update Items Map
     */
private void processUpdateMap() {
    if (dscAlarmUpdateMap.size() == 0) {
        logger.debug("processUpdateMap(): Nothing to update.");
        return;
    }
    Map<String, DSCAlarmBindingConfig> itemsMap = new HashMap<String, DSCAlarmBindingConfig>(dscAlarmUpdateMap);
    for (String itemName : itemsMap.keySet()) {
        DSCAlarmBindingConfig dscAlarmBindingConfig = itemsMap.get(itemName);
        dscAlarmUpdateMap.remove(itemName);
        Item item = null;
        for (DSCAlarmBindingProvider provider : providers) {
            item = provider.getItem(itemName);
        }
        if (dscAlarmBindingConfig.getDSCAlarmItemType().equals(DSCAlarmItemType.PANEL_COMMAND)) {
            dscAlarmItemUpdate.updateDeviceItem(item, dscAlarmBindingConfig, eventPublisher, null, -1, "");
        } else {
            dscAlarmItemUpdate.updateDeviceItem(item, dscAlarmBindingConfig, eventPublisher, null, 0, "");
        }
        logger.debug("processUpdateMap(): Updated item: {}", itemName);
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) HashMap(java.util.HashMap) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 39 with Item

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

the class HttpGenericBindingProviderTest method testParseBindingConfigWithXPATH.

@Test
public void testParseBindingConfigWithXPATH() throws BindingConfigParseException {
    String bindingConfig = "<[http://www.wetter-vista.de:7970/api/xml.php?q=Berlin:60000:XPATH(/wettervorhersage/tag[1]/tmax)]";
    Item testItem = new DecimalTestItem();
    // method under test
    HttpBindingConfig config = provider.parseBindingConfig(testItem, bindingConfig);
    // asserts
    Assert.assertEquals(true, config.containsKey(HttpGenericBindingProvider.IN_BINDING_KEY));
    Assert.assertEquals(null, config.get(HttpGenericBindingProvider.IN_BINDING_KEY).httpMethod);
    Assert.assertEquals("http://www.wetter-vista.de:7970/api/xml.php?q=Berlin", config.get(HttpGenericBindingProvider.IN_BINDING_KEY).url);
    Assert.assertEquals(60000, config.get(HttpGenericBindingProvider.IN_BINDING_KEY).refreshInterval);
    Assert.assertEquals("XPATH(/wettervorhersage/tag[1]/tmax)", config.get(HttpGenericBindingProvider.IN_BINDING_KEY).transformation);
}
Also used : Item(org.openhab.core.items.Item) GenericItem(org.openhab.core.items.GenericItem) HttpBindingConfig(org.openhab.binding.http.internal.HttpGenericBindingProvider.HttpBindingConfig) Test(org.junit.Test)

Example 40 with Item

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

the class HttpGenericBindingProviderTest method testParseBindingConfigWithNumbers.

@Test
public void testParseBindingConfigWithNumbers() throws BindingConfigParseException {
    String bindingConfig = ">[1:POST:http://www.domain.org:1234/home/lights/23871/?status=on&type=\"text\"] >[0:GET:http://www.domain.org:1234/home/lights/23871/?status=off]";
    Item testItem = new DecimalTestItem();
    // method under test
    HttpBindingConfig config = provider.parseBindingConfig(testItem, bindingConfig);
    // asserts
    Assert.assertEquals(true, config.containsKey(DecimalType.valueOf("1")));
    Assert.assertEquals("POST", config.get(DecimalType.valueOf("1")).httpMethod);
    Assert.assertEquals("http://www.domain.org:1234/home/lights/23871/?status=on&type=\"text\"", config.get(DecimalType.valueOf("1")).url);
    Assert.assertEquals(true, config.containsKey(DecimalType.valueOf("0")));
    Assert.assertEquals("GET", config.get(DecimalType.valueOf("0")).httpMethod);
    Assert.assertEquals("http://www.domain.org:1234/home/lights/23871/?status=off", config.get(DecimalType.valueOf("0")).url);
}
Also used : Item(org.openhab.core.items.Item) GenericItem(org.openhab.core.items.GenericItem) HttpBindingConfig(org.openhab.binding.http.internal.HttpGenericBindingProvider.HttpBindingConfig) Test(org.junit.Test)

Aggregations

Item (org.openhab.core.items.Item)59 SwitchItem (org.openhab.core.library.items.SwitchItem)23 NumberItem (org.openhab.core.library.items.NumberItem)20 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)16 State (org.openhab.core.types.State)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ContactItem (org.openhab.core.library.items.ContactItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)14 DecimalType (org.openhab.core.library.types.DecimalType)9 HistoricItem (org.openhab.core.persistence.HistoricItem)9 ArrayList (java.util.ArrayList)7 ColorItem (org.openhab.core.library.items.ColorItem)7 StringItem (org.openhab.core.library.items.StringItem)7 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6 Test (org.junit.Test)5 GenericItem (org.openhab.core.items.GenericItem)5 GroupItem (org.openhab.core.items.GroupItem)5 ItemRegistry (org.openhab.core.items.ItemRegistry)5 Calendar (java.util.Calendar)3