use of org.openhab.binding.fatekplc.FatekPLCBindingProvider in project openhab1-addons by openhab.
the class FatekPLCBinding method execute.
/**
* {@inheritDoc}
*/
@Override
protected void execute() {
Map<String, List<FatekPLCItem>> toUpdate = new HashMap<>();
// collect items by slave PLC
for (FatekPLCBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
FatekPLCItem item = provider.geFatektItem(itemName);
if (item.isToRefresh()) {
List<FatekPLCItem> itemsList = toUpdate.get(item.getSlaveName());
if (itemsList == null) {
itemsList = new ArrayList<>();
toUpdate.put(item.getSlaveName(), itemsList);
}
itemsList.add(item);
}
}
}
logger.debug("toUpdate={}", toUpdate);
// process list to update
for (String slaveName : toUpdate.keySet()) {
FatekPLCSlave slave = slaves.get(slaveName);
List<FatekPLCItem> items = toUpdate.get(slaveName);
if (slave != null) {
try {
slave.updateItems(items);
} catch (Exception e) {
logger.error("update items error", e);
}
} else {
logger.warn("Unknown slave: {} to process update: {}", slaveName, items);
}
}
}
Aggregations