Search in sources :

Example 1 with FritzahaQueryscriptMeter

use of org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaQueryscriptMeter in project openhab1-addons by openhab.

the class FritzahaGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    FritzahaDevice config = null;
    TimeDef timedef = null;
    String[] configParts = bindingConfig.trim().split(",");
    if (configParts.length < 2) {
        throw new BindingConfigParseException("FritzAHA items must start with <hostID>,<deviceID/AIN>");
    }
    if (item instanceof SwitchItem) {
        if (configParts.length != 2) {
            throw new BindingConfigParseException("FritzAHA switches must be of format <hostID>,<deviceID/AIN>");
        }
        if (configParts[1].length() > 8) {
            config = new FritzahaWebserviceSwitch(configParts[0], configParts[1]);
        } else {
            config = new FritzahaQueryscriptSwitch(configParts[0], configParts[1]);
        }
    } else if (item instanceof NumberItem) {
        if (configParts.length < 3 || configParts.length > 4) {
            throw new BindingConfigParseException("FritzAHA meters must be of format <hostID>,<deviceID/AIN>,<valueToMeasure>[,timespec]");
        } else if (configParts.length == 4 && !"energy".equalsIgnoreCase(configParts[2])) {
            throw new BindingConfigParseException("FritzAHA non-energy meters must be of format <hostID>,<deviceID/AIN>,<valueToMeasure>");
        } else if (configParts[1].length() > 8) {
            if ("power".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.POWER);
            } else if ("energy".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.ENERGY);
            } else if ("temperature".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.TEMPERATURE);
            } else {
                logger.warn("Could not configure item " + item + " - Unsupported meter type for webservice");
                return;
            }
        } else {
            if ("voltage".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.VOLTAGE);
            } else if ("current".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.CURRENT);
            } else if ("power".equalsIgnoreCase(configParts[2])) {
                config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.POWER);
            } else if ("energy".equalsIgnoreCase(configParts[2])) {
                if (configParts.length > 3) {
                    if ("mins".equalsIgnoreCase(configParts[3])) {
                        timedef = TimeDef.MINUTES;
                    } else if ("day".equalsIgnoreCase(configParts[3])) {
                        timedef = TimeDef.DAY;
                    } else if ("month".equalsIgnoreCase(configParts[3])) {
                        timedef = TimeDef.MONTH;
                    } else if ("year".equalsIgnoreCase(configParts[3])) {
                        timedef = TimeDef.YEAR;
                    } else {
                        timedef = TimeDef.YEAR;
                        logger.warn("Timedef of item " + item + "is set to default YEAR. " + "Please check your syntax. Shall be year, month, day or mins.");
                    }
                } else {
                    timedef = TimeDef.YEAR;
                    logger.debug("Timedef of item " + item + "is set to default YEAR because no timespec was given.");
                }
                config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.ENERGY, timedef);
            } else {
                logger.warn("Could not configure item " + item + " - Unsupported meter type for query script");
                return;
            }
        }
    } else {
        logger.warn("Could not configure item " + item + " - Unsupported item type");
    }
    if (config != null) {
        addBindingConfig(item, config);
    } else {
        logger.error("Could not configure item " + item + " - An error occurred");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) FritzahaQueryscriptMeter(org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaQueryscriptMeter) FritzahaQueryscriptSwitch(org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaQueryscriptSwitch) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) FritzahaWebserviceSwitch(org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaWebserviceSwitch) FritzahaWebserviceMeter(org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaWebserviceMeter) FritzahaDevice(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice) SwitchItem(org.openhab.core.library.items.SwitchItem) TimeDef(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter.TimeDef)

Aggregations

FritzahaQueryscriptMeter (org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaQueryscriptMeter)1 FritzahaQueryscriptSwitch (org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaQueryscriptSwitch)1 FritzahaWebserviceMeter (org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaWebserviceMeter)1 FritzahaWebserviceSwitch (org.openhab.binding.fritzaha.internal.hardware.devices.FritzahaWebserviceSwitch)1 FritzahaDevice (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice)1 TimeDef (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter.TimeDef)1 NumberItem (org.openhab.core.library.items.NumberItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1