Search in sources :

Example 1 with MeasureType

use of org.openhab.binding.withings.internal.model.MeasureType 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)

Example 2 with MeasureType

use of org.openhab.binding.withings.internal.model.MeasureType in project openhab1-addons by openhab.

the class WithingsBinding method updateItemState.

private void updateItemState(String itemName, WithingsBindingConfig withingsBindingConfig, List<MeasureGroup> measures) {
    MeasureType measureType = withingsBindingConfig.measureType;
    Float lastMeasureValue = findLastMeasureValue(measures, measureType);
    if (lastMeasureValue != null) {
        eventPublisher.postUpdate(itemName, new DecimalType(lastMeasureValue));
    }
}
Also used : MeasureType(org.openhab.binding.withings.internal.model.MeasureType) DecimalType(org.openhab.core.library.types.DecimalType)

Aggregations

MeasureType (org.openhab.binding.withings.internal.model.MeasureType)2 WithingsBindingConfig (org.openhab.binding.withings.WithingsBindingConfig)1 DecimalType (org.openhab.core.library.types.DecimalType)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1