Search in sources :

Example 1 with FatekPLCItem

use of org.openhab.binding.fatekplc.items.FatekPLCItem 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)

Example 2 with FatekPLCItem

use of org.openhab.binding.fatekplc.items.FatekPLCItem in project openhab1-addons by openhab.

the class FatekPLCGenericBindingProvider method processBindingConfiguration.

/**
	 * {@inheritDoc}
	 */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    FatekPLCItem config = FatekPLCItem.parseBindingConfiguration(item, bindingConfig);
    addBindingConfig(item, config);
    super.processBindingConfiguration(context, item, bindingConfig);
}
Also used : FatekPLCItem(org.openhab.binding.fatekplc.items.FatekPLCItem)

Example 3 with FatekPLCItem

use of org.openhab.binding.fatekplc.items.FatekPLCItem in project openhab1-addons by openhab.

the class FatekPLCSlave method updateItems.

/**
	 * Read current data from Fatek PLC and publish new state on OpenHab bus.
	 *
	 * @param items items to updates
	 * @throws FatekIOException
	 * @throws FatekException
	 */
public void updateItems(List<FatekPLCItem> items) throws FatekIOException, FatekException {
    // collect unique register to read from PLC
    Set<Reg> regsToUpdate = new HashSet<>();
    for (FatekPLCItem item : items) {
        regsToUpdate.addAll(item.getRegs());
    }
    Map<Reg, RegValue> response;
    synchronized (fatekPLC) {
        // read register
        response = new FatekReadMixDataCmd(fatekPLC, regsToUpdate).send();
    }
    // distribute read data
    for (FatekPLCItem fatekItem : items) {
        State newState = fatekItem.getState(response);
        if (stateCache.isStateChange(fatekItem, newState)) {
            eventPublisher.postUpdate(fatekItem.getItemName(), newState);
        }
    }
}
Also used : Reg(org.simplify4u.jfatek.registers.Reg) FatekReadMixDataCmd(org.simplify4u.jfatek.FatekReadMixDataCmd) State(org.openhab.core.types.State) FatekPLCItem(org.openhab.binding.fatekplc.items.FatekPLCItem) HashSet(java.util.HashSet) RegValue(org.simplify4u.jfatek.registers.RegValue)

Aggregations

FatekPLCItem (org.openhab.binding.fatekplc.items.FatekPLCItem)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 FatekPLCBindingProvider (org.openhab.binding.fatekplc.FatekPLCBindingProvider)1 State (org.openhab.core.types.State)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1 FatekReadMixDataCmd (org.simplify4u.jfatek.FatekReadMixDataCmd)1 FatekIOException (org.simplify4u.jfatek.io.FatekIOException)1 Reg (org.simplify4u.jfatek.registers.Reg)1 RegValue (org.simplify4u.jfatek.registers.RegValue)1