use of org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider in project openhab1-addons by openhab.
the class Iec6205621MeterBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
// the frequently executed code (polling) goes here ...
Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
for (Iec6205621MeterBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
Meter reader = entry.getValue();
String meterName = provider.getMeterName(itemName);
if (meterName != null && meterName.equals(entry.getKey())) {
Map<String, DataSet> dataSets;
if ((dataSets = cache.get(meterName)) == null) {
if (logger.isDebugEnabled()) {
logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
}
dataSets = reader.read();
cache.put(meterName, dataSets);
}
String obis = provider.getObis(itemName);
if (obis != null && dataSets.containsKey(obis)) {
DataSet dataSet = dataSets.get(obis);
if (logger.isDebugEnabled()) {
logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
}
Class<? extends Item> itemType = provider.getItemType(itemName);
if (itemType.isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
}
if (itemType.isAssignableFrom(StringItem.class)) {
String value = dataSet.getValue();
eventPublisher.postUpdate(itemName, new StringType(value));
}
}
}
}
}
}
}
Aggregations