Search in sources :

Example 1 with FritzahaDevice

use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice in project openhab1-addons by openhab.

the class FritzahaBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("internalReceiveCommand() is called!");
    FritzahaBindingProvider commandProvider = null;
    FritzahaSwitchedOutlet switchDevice = null;
    for (FritzahaBindingProvider currentProvider : providers) {
        if (!currentProvider.getItemNames().contains(itemName)) {
            continue;
        }
        FritzahaDevice device = currentProvider.getDeviceConfig(itemName);
        if (!(device instanceof FritzahaSwitchedOutlet)) {
            continue;
        }
        switchDevice = (FritzahaSwitchedOutlet) device;
        commandProvider = currentProvider;
        break;
    }
    if (commandProvider == null || switchDevice == null) {
        logger.error("No provider found for item " + itemName);
        return;
    }
    if (command instanceof OnOffType) {
        String deviceHostID = switchDevice.getHost();
        Host host = hostCache.get(deviceHostID);
        if (host != null) {
            FritzahaWebInterface deviceHost = host.getConnection();
            boolean valueToSet = (command == OnOffType.ON);
            switchDevice.setSwitchState(valueToSet, itemName, deviceHost);
        }
    } else {
        logger.debug("Unsupported command type for item " + itemName);
    }
}
Also used : FritzahaBindingProvider(org.openhab.binding.fritzaha.FritzahaBindingProvider) OnOffType(org.openhab.core.library.types.OnOffType) FritzahaDevice(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice) FritzahaSwitchedOutlet(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet) FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Example 2 with FritzahaDevice

use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice 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)

Example 3 with FritzahaDevice

use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice in project openhab1-addons by openhab.

the class FritzahaBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    logger.debug("execute() method is called!");
    for (FritzahaBindingProvider currentProvider : providers) {
        for (String currentItem : currentProvider.getItemNames()) {
            FritzahaDevice currentDevice = currentProvider.getDeviceConfig(currentItem);
            String currentHostId = currentDevice.getHost();
            if (!hostCache.containsKey(currentHostId)) {
                continue;
            }
            FritzahaWebInterface currentHost = hostCache.get(currentHostId).getConnection();
            if (currentDevice instanceof FritzahaSwitchedOutlet) {
                FritzahaSwitchedOutlet currentSwitch = (FritzahaSwitchedOutlet) currentDevice;
                currentSwitch.updateSwitchState(currentItem, currentHost);
            } else if (currentDevice instanceof FritzahaOutletMeter) {
                FritzahaOutletMeter currentMeter = (FritzahaOutletMeter) currentDevice;
                currentMeter.updateMeterValue(currentItem, currentHost);
            }
        }
    }
}
Also used : FritzahaBindingProvider(org.openhab.binding.fritzaha.FritzahaBindingProvider) FritzahaOutletMeter(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter) FritzahaDevice(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice) FritzahaSwitchedOutlet(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet) FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Aggregations

FritzahaDevice (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice)3 FritzahaBindingProvider (org.openhab.binding.fritzaha.FritzahaBindingProvider)2 FritzahaWebInterface (org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)2 FritzahaSwitchedOutlet (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet)2 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 FritzahaOutletMeter (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter)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 OnOffType (org.openhab.core.library.types.OnOffType)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1