Search in sources :

Example 1 with FatekPLCBindingProvider

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);
        }
    }
}
Also used : FatekPLCBindingProvider(org.openhab.binding.fatekplc.FatekPLCBindingProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) FatekPLCItem(org.openhab.binding.fatekplc.items.FatekPLCItem) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FatekPLCBindingProvider (org.openhab.binding.fatekplc.FatekPLCBindingProvider)1 FatekPLCItem (org.openhab.binding.fatekplc.items.FatekPLCItem)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1 FatekIOException (org.simplify4u.jfatek.io.FatekIOException)1