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