use of org.openhab.binding.withings.WithingsBindingConfig in project openhab1-addons by openhab.
the class WithingsBinding method updateItemStates.
private void updateItemStates(Map<String, WithingsBindingConfig> withingsBindings) {
try {
WithingsApiClient client = this.withingsApiClients.get(0);
List<MeasureGroup> measures = client.getMeasures(lastUpdate);
if (measures == null || measures.isEmpty()) {
logger.info("No new measures found since the last update.");
return;
}
for (Entry<String, WithingsBindingConfig> withingBinding : withingsBindings.entrySet()) {
WithingsBindingConfig withingsBindingConfig = withingBinding.getValue();
String itemName = withingBinding.getKey();
updateItemState(itemName, withingsBindingConfig, measures);
}
lastUpdate = now();
} catch (Exception ex) {
logger.error("Cannot get Withings measure data: " + ex.getMessage(), ex);
}
}
use of org.openhab.binding.withings.WithingsBindingConfig in project openhab1-addons by openhab.
the class WithingsBinding method getWithingsBindings.
private Map<String, WithingsBindingConfig> getWithingsBindings() {
Map<String, WithingsBindingConfig> bindings = new HashMap<String, WithingsBindingConfig>();
for (WithingsBindingProvider provider : this.providers) {
Collection<String> itemNames = provider.getItemNames();
for (String itemName : itemNames) {
WithingsBindingConfig config = provider.getItemConfig(itemName);
bindings.put(itemName, config);
}
}
return bindings;
}
use of org.openhab.binding.withings.WithingsBindingConfig in project openhab1-addons by openhab.
the class WithingsGenericBindingProvider method processBindingConfiguration.
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] configElements = bindingConfig.split(":");
String accountId = null;
MeasureType measureType = null;
if (configElements.length == 1) {
measureType = MeasureType.valueOf(configElements[0].toUpperCase());
} else if (configElements.length == 2) {
accountId = configElements[0];
measureType = MeasureType.valueOf(configElements[1].toUpperCase());
} else {
throw new BindingConfigParseException("Unknown Binding configuration '{}'. The Binding " + "configuration should consists of either one or two elements.");
}
if (measureType == null) {
throw new BindingConfigParseException("Could not convert string '" + bindingConfig + "' to according measure type.");
}
WithingsBindingConfig config = new WithingsBindingConfig(accountId, measureType);
addBindingConfig(item, config);
}
Aggregations