Search in sources :

Example 6 with DigitalSTROMBindingConfig

use of org.openhab.binding.digitalstrom.internal.config.DigitalSTROMBindingConfig in project openhab1-addons by openhab.

the class DigitalSTROMBinding method updateItemState.

private void updateItemState(Item item) {
    if (item != null) {
        Device device = deviceMap.get(item.getName());
        if (device != null) {
            State state = null;
            if (item instanceof DimmerItem) {
                state = new PercentType(getPercent(device.getMaxOutPutValue(), device.getOutputValue()));
            } else if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
                state = device.getOutputValue() > 0 ? OnOffType.ON : OnOffType.OFF;
            } else if (item instanceof NumberItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            } else if (item instanceof RollershutterItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.context != null && confItem.context.equals(ContextConfig.slat)) {
                        int output = getPercent(device.getMaxSlatPosition(), device.getSlatPosition());
                        state = new PercentType(100 - output);
                    } else if (confItem.context != null && confItem.context.equals(ContextConfig.awning)) {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(output);
                    } else {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(100 - output);
                    }
                }
            } else if (item instanceof StringItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            eventPublisher.postUpdate(item.getName(), state);
        } else {
            logger.error("couldn't update item state, because device is null: " + item.getName());
        }
    } else {
        logger.error("couldn't update item state, because item is null");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Device(org.openhab.binding.digitalstrom.internal.client.entity.Device) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DigitalSTROMBindingConfig(org.openhab.binding.digitalstrom.internal.config.DigitalSTROMBindingConfig) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

DigitalSTROMBindingConfig (org.openhab.binding.digitalstrom.internal.config.DigitalSTROMBindingConfig)6 Device (org.openhab.binding.digitalstrom.internal.client.entity.Device)5 DigitalSTROMBindingProvider (org.openhab.binding.digitalstrom.DigitalSTROMBindingProvider)3 DecimalType (org.openhab.core.library.types.DecimalType)3 PercentType (org.openhab.core.library.types.PercentType)2 State (org.openhab.core.types.State)2 SensorIndexEnum (org.openhab.binding.digitalstrom.internal.client.constants.SensorIndexEnum)1 CachedMeteringValue (org.openhab.binding.digitalstrom.internal.client.entity.CachedMeteringValue)1 DeviceConsumptionSensorJob (org.openhab.binding.digitalstrom.internal.client.job.DeviceConsumptionSensorJob)1 DeviceSensorValueJob (org.openhab.binding.digitalstrom.internal.client.job.DeviceSensorValueJob)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1 RollershutterItem (org.openhab.core.library.items.RollershutterItem)1 StringItem (org.openhab.core.library.items.StringItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 StopMoveType (org.openhab.core.library.types.StopMoveType)1 StringType (org.openhab.core.library.types.StringType)1 UpDownType (org.openhab.core.library.types.UpDownType)1