use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class ProviderItemIterator method iterate.
/**
* Iterate through all providers and their items, creates a converter and
* calls the callback.
*/
public void iterate(HomematicBindingConfig bindingConfig, ProviderItemIteratorCallback callback) {
for (HomematicBindingProvider provider : context.getProviders()) {
List<Item> items = provider.getItemsFor(bindingConfig);
for (Item item : items) {
HomematicBindingConfig providerBindingConfig = provider.getBindingFor(item.getName());
Converter<?> converter = context.getConverterFactory().createConverter(item, providerBindingConfig);
if (converter != null) {
callback.next(providerBindingConfig, item, converter);
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testValidateItemType_nullItem.
@Test(expected = BindingConfigParseException.class)
public void testValidateItemType_nullItem() throws BindingConfigParseException {
Item s = null;
provider.validateItemType(s, "?");
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testValidateItemType_itemNotNumOrStr.
@Test(expected = BindingConfigParseException.class)
public void testValidateItemType_itemNotNumOrStr() throws BindingConfigParseException {
Item newItem = new DummyItem();
provider.validateItemType(newItem, "?");
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class PLCLogoBinding method execute.
@Override
protected void execute() {
if (!bindingsExist()) {
logger.debug("There is no existing plclogo binding configuration => refresh cycle aborted!");
return;
}
Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, PLCLogoConfig> thisEntry = entries.next();
String controller = thisEntry.getKey();
PLCLogoConfig logoConfig = thisEntry.getValue();
S7Client LogoS7Client = logoConfig.getS7Client();
if (LogoS7Client == null) {
logger.debug("No S7client for {} found", controller);
} else {
lock.lock();
int result = ReadLogoDBArea(LogoS7Client, logoConfig.getMemorySize());
lock.unlock();
if (result != 0) {
logger.warn("Failed to read memory: {}. Reconnecting...", S7Client.ErrorText(result));
ReconnectLogo(LogoS7Client);
return;
}
// Now have the LOGO! memory (note: not suitable for S7) - more efficient than multiple reads (test
// shows <14mS to read all)
// iterate through bindings to see what has changed - this approach assumes a small number (< 100)of
// bindings
// otherwise might see what has changed in memory and map to binding
}
for (PLCLogoBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
PLCLogoBindingConfig config = provider.getBindingConfig(itemName);
if (config.getController().equals(controller)) {
// it is for our currently selected controller
PLCLogoMemoryConfig rd = config.getRD();
int address = -1;
try {
address = rd.getAddress(logoConfig.getModel());
} catch (BindingConfigParseException exception) {
logger.error("Invalid address for block {} on {}", rd.getBlockName(), controller);
continue;
}
int currentValue;
if (rd.isDigital()) {
int bit = -1;
try {
bit = rd.getBit(logoConfig.getModel());
} catch (BindingConfigParseException exception) {
logger.error("Invalid bit for block {} on {}", rd.getBlockName(), controller);
continue;
}
currentValue = S7.GetBitAt(data, address, bit) ? 1 : 0;
} else {
/*
* After the data transfer from a LOGO! Base Module to LOGO!Soft Comfort,
* you can view only analog values within the range of -32768 to 32767 on LOGO!Soft Comfort.
* If an analog value exceeds the value range,
* then only the nearest upper limit (32767) or lower limit (-32768) can be displayed.
*/
currentValue = S7.GetShortAt(data, address);
}
if (config.isSet()) {
if (currentValue == config.getLastValue()) {
continue;
}
int delta = Math.abs(config.getLastValue() - currentValue);
if (!rd.isDigital() && (delta < config.getAnalogDelta())) {
continue;
}
}
boolean isValid = false;
Item item = provider.getItem(itemName);
switch(rd.getKind()) {
case I:
case NI:
{
isValid = item instanceof ContactItem;
break;
}
case Q:
case NQ:
{
isValid = item instanceof SwitchItem;
break;
}
case M:
case VB:
case VW:
{
isValid = item instanceof ContactItem || item instanceof SwitchItem;
break;
}
default:
{
break;
}
}
if (item instanceof NumberItem || isValid) {
eventPublisher.postUpdate(itemName, createState(item, currentValue));
config.setLastValue(currentValue);
} else {
String block = rd.getBlockName();
logger.warn("Block {} is incompatible with item {} on {}", block, item.getName(), controller);
}
}
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class XplBinding method handleXPLMessage.
@Override
public void handleXPLMessage(xPL_MessageI theMessage) {
for (XplBindingProvider provider : providers) {
List<String> matchingItems = provider.hasMessage(theMessage);
for (String itemName : matchingItems) {
XplBindingConfig config = provider.getConfig(itemName);
if (config == null) {
continue;
}
String current = theMessage.getNamedValue(config.NamedParameter);
Item item = provider.getItem(itemName);
if (item != null) {
if (item instanceof SwitchItem) {
OnOffType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OnOffType.ON : OnOffType.OFF;
synchronized (item) {
if (!item.getState().equals(status)) {
eventPublisher.postUpdate(itemName, status);
((SwitchItem) item).setState(status);
}
}
} else if (item instanceof ContactItem) {
OpenClosedType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
synchronized (item) {
if (!item.getState().equals(status)) {
eventPublisher.postUpdate(itemName, status);
((ContactItem) item).setState(status);
}
}
} else if (item instanceof NumberItem) {
DecimalType value = new DecimalType(current);
synchronized (item) {
if (!item.getState().equals(value)) {
eventPublisher.postUpdate(itemName, value);
((NumberItem) item).setState(value);
}
}
} else if (item instanceof StringItem) {
StringType value = new StringType(current);
synchronized (item) {
if (!item.getState().equals(value)) {
eventPublisher.postUpdate(itemName, value);
((StringItem) item).setState(value);
}
}
}
}
}
}
}
Aggregations