Search in sources :

Example 1 with WithingsBindingConfig

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);
    }
}
Also used : MeasureGroup(org.openhab.binding.withings.internal.model.MeasureGroup) WithingsBindingConfig(org.openhab.binding.withings.WithingsBindingConfig) WithingsApiClient(org.openhab.binding.withings.internal.api.WithingsApiClient) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 2 with WithingsBindingConfig

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;
}
Also used : HashMap(java.util.HashMap) WithingsBindingConfig(org.openhab.binding.withings.WithingsBindingConfig) WithingsBindingProvider(org.openhab.binding.withings.WithingsBindingProvider)

Example 3 with WithingsBindingConfig

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);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) MeasureType(org.openhab.binding.withings.internal.model.MeasureType) WithingsBindingConfig(org.openhab.binding.withings.WithingsBindingConfig)

Aggregations

WithingsBindingConfig (org.openhab.binding.withings.WithingsBindingConfig)3 HashMap (java.util.HashMap)1 WithingsBindingProvider (org.openhab.binding.withings.WithingsBindingProvider)1 WithingsApiClient (org.openhab.binding.withings.internal.api.WithingsApiClient)1 MeasureGroup (org.openhab.binding.withings.internal.model.MeasureGroup)1 MeasureType (org.openhab.binding.withings.internal.model.MeasureType)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1