Search in sources :

Example 21 with Item

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

the class HttpGenericBindingProviderTest method testParseIncomingBindingConfigWithHTTPHeaders.

@Test
public void testParseIncomingBindingConfigWithHTTPHeaders() throws BindingConfigParseException {
    String bindingConfig = "<[http://www.wetter-vista.de/api/xml.php?q=Berlin{header1=value1&header2=value2}: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/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);
    Assert.assertNotNull(config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers);
    Assert.assertEquals("{header2=value2, header1=value1}", config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers.toString());
    Assert.assertTrue(config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers.containsKey("header1"));
    Assert.assertTrue(config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers.containsKey("header2"));
    Assert.assertTrue(config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers.contains("value1"));
    Assert.assertTrue(config.get(HttpGenericBindingProvider.IN_BINDING_KEY).headers.contains("value2"));
}
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 22 with Item

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

the class OmniLinkBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.
    logger.debug("internalReceiveCommand() is called!!! {} {} ", itemName, command);
    if (omniWorker != null && omniWorker.isConnected()) {
        for (OmniLinkBindingProvider provider : providers) {
            OmniLinkBindingConfig config = provider.getOmniLinkBindingConfig(itemName);
            Item item = provider.getItem(itemName);
            List<OmniLinkControllerCommand> commands = OmniLinkCommandMapper.getCommand(item, config, command);
            /*
                 * send each command we get back
                 */
            for (OmniLinkControllerCommand cmd : commands) {
                try {
                    logger.debug("Sending command {}/{}/{}", new Object[] { cmd.getCommand(), cmd.getParameter1(), cmd.getParameter2() });
                    omniWorker.getOmniConnection().controllerCommand(cmd.getCommand(), cmd.getParameter1(), cmd.getParameter2());
                    // little hack to get audio updates faster.
                    if (config.getObjectType() == OmniLinkItemType.AUDIOZONE_KEY) {
                        audioUpdateLock.notifyAll();
                    }
                } catch (IOException e) {
                    logger.error("Could not send command", e);
                } catch (OmniNotConnectedException e) {
                    logger.error("Could not send command", e);
                } catch (OmniInvalidResponseException e) {
                    logger.error("Could not send command", e);
                } catch (OmniUnknownMessageTypeException e) {
                    logger.error("Could not send command", e);
                }
            }
        }
    } else {
        logger.debug("Could not send message, connection not established {}", omniWorker == null);
    }
// get the
}
Also used : Item(org.openhab.core.items.Item) OmniInvalidResponseException(com.digitaldan.jomnilinkII.OmniInvalidResponseException) OmniLinkBindingProvider(org.openhab.binding.omnilink.OmniLinkBindingProvider) OmniNotConnectedException(com.digitaldan.jomnilinkII.OmniNotConnectedException) IOException(java.io.IOException) OmniUnknownMessageTypeException(com.digitaldan.jomnilinkII.OmniUnknownMessageTypeException)

Example 23 with Item

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

the class OmniLinkBinding method updateItemsForDevice.

/**
     * Update any items linked to a Omni device.
     *
     * @param device
     */
protected void updateItemsForDevice(OmnilinkDevice device) {
    for (OmniLinkBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            OmniLinkBindingConfig bindingConfig = provider.getOmniLinkBindingConfig(itemName);
            OmnilinkDevice itemDevice = bindingConfig.getDevice();
            Item item = provider.getItem(itemName);
            if (itemDevice != null && itemDevice == device) {
                device.updateItem(item, bindingConfig, eventPublisher);
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) OmniLinkBindingProvider(org.openhab.binding.omnilink.OmniLinkBindingProvider) OmnilinkDevice(org.openhab.binding.omnilink.internal.model.OmnilinkDevice)

Example 24 with Item

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

the class NikobusGenericBindingProviderTest method parseChannelConfig.

private void parseChannelConfig(String name, String config, String address, int channel) throws BindingConfigParseException {
    Item item = new SwitchItem(name);
    provider.processBindingConfiguration("context", item, config);
    ModuleChannel c = (ModuleChannel) provider.getItemConfig(name);
    assertEquals(name, c.getName());
    assertEquals(address, c.getAddress());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) ModuleChannel(org.openhab.binding.nikobus.internal.config.ModuleChannel) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 25 with Item

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

the class TinkerforgeBinding method updateItemValues.

/**
     * Triggers an update of state values for all devices.
     *
     * @param provider The {@code TinkerforgeBindingProvider} which is bound to the device as
     *            {@code Item}
     * @param itemName The name of the {@code Item} as String
     * @param only_poll_enabled Fetch only the values of devices which do not support callback
     *            listeners. These devices are marked with poll "true" flag.
     */
protected void updateItemValues(TinkerforgeBindingProvider provider, String itemName, boolean only_poll_enabled) {
    if (tinkerforgeEcosystem == null) {
        logger.warn("tinkerforge ecosystem not yet ready");
        return;
    }
    String deviceUid = provider.getUid(itemName);
    Item item = provider.getItem(itemName);
    String deviceSubId = provider.getSubId(itemName);
    String deviceName = provider.getName(itemName);
    if (deviceName != null) {
        String[] ids = getDeviceIdsForDeviceName(deviceName);
        deviceUid = ids[0];
        deviceSubId = ids[1];
    }
    MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
    if (mDevice != null && mDevice.getEnabledA().get()) {
        if (only_poll_enabled && !mDevice.isPoll()) {
            // do nothing
            logger.debug("{} omitting fetch value for no poll{}:{}", LoggerConstants.ITEMUPDATE, deviceUid, deviceSubId);
        } else {
            if (mDevice instanceof MSensor) {
                ((MSensor<?>) mDevice).fetchSensorValue();
            } else if (mDevice instanceof SwitchSensor && item instanceof SwitchItem) {
                ((SwitchSensor) mDevice).fetchSwitchState();
            } else if (mDevice instanceof DigitalActor) {
                ((DigitalActor) mDevice).fetchDigitalValue();
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) ColorItem(org.openhab.core.library.items.ColorItem) 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) MSensor(org.openhab.binding.tinkerforge.internal.model.MSensor) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) SwitchSensor(org.openhab.binding.tinkerforge.internal.model.SwitchSensor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) SwitchItem(org.openhab.core.library.items.SwitchItem)

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