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"));
}
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
}
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);
}
}
}
}
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());
}
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();
}
}
}
}
Aggregations