Search in sources :

Example 1 with HmDatapoint

use of org.openhab.binding.homematic.internal.model.HmDatapoint in project openhab1-addons by openhab.

the class CcuClient method addRssiDatapoint.

/**
     * Generates a missing RSSI datapoint, workaround for a CCU bug.
     */
private void addRssiDatapoint(HmChannel channel, String name, Object value, HmValueItemIteratorCallback callback) {
    HmDatapoint dp = new HmDatapoint();
    dp.setName(name);
    dp.setValueType(8);
    dp.setWriteable(false);
    dp.setValue(value);
    channel.addDatapoint(dp);
    DatapointConfig bindingConfig = new DatapointConfig(channel.getDevice().getAddress(), channel.getNumber(), dp.getName());
    callback.iterate(bindingConfig, dp);
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 2 with HmDatapoint

use of org.openhab.binding.homematic.internal.model.HmDatapoint in project openhab1-addons by openhab.

the class HomegearClient method parseDatapoint.

/**
     * Parses the datapoint informations into the binding model.
     */
private HmDatapoint parseDatapoint(HmChannel channel, String name, Map<String, ?> dpData) throws IllegalAccessException {
    HmDatapoint dp = new HmDatapoint();
    dp.setName(name);
    FieldUtils.writeField(dp, "channel", channel, true);
    FieldUtils.writeField(dp, "writeable", dpData.get("WRITEABLE"), true);
    Object valueList = dpData.get("VALUE_LIST");
    if (valueList != null && valueList instanceof Object[]) {
        Object[] vl = (Object[]) valueList;
        String[] stringArray = new String[vl.length];
        for (int i = 0; i < vl.length; i++) {
            stringArray[i] = vl[i].toString();
        }
        FieldUtils.writeField(dp, "valueList", stringArray, true);
    }
    Object value = dpData.get("VALUE");
    String type = (String) dpData.get("TYPE");
    boolean isString = StringUtils.equals("STRING", type);
    if (isString && value != null && !(value instanceof String)) {
        value = ObjectUtils.toString(value);
    }
    setValueType(dp, type, value);
    if (dp.isNumberValueType()) {
        FieldUtils.writeField(dp, "minValue", dpData.get("MIN"), true);
        FieldUtils.writeField(dp, "maxValue", dpData.get("MAX"), true);
    }
    dp.setValue(value);
    return dp;
}
Also used : HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 3 with HmDatapoint

use of org.openhab.binding.homematic.internal.model.HmDatapoint in project openhab1-addons by openhab.

the class RemoteControlOptionParser method getSymbols.

/**
     * Returns all possible symbols from the remote control.
     */
private String[] getSymbols() throws HomematicClientException {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", "SUBMIT");
    HmDatapoint rcDatapoint = (HmDatapoint) context.getStateHolder().getState(dpConfig);
    if (rcDatapoint == null) {
        throw new HomematicClientException("Address " + remoteControlAddress + " is not a Homematic remote control with a display");
    }
    List<String> symbols = new ArrayList<String>();
    for (HmDatapoint datapoint : rcDatapoint.getChannel().getDatapoints()) {
        if (datapoint.isWriteable() && datapoint.getValueType() == 2 && !"SUBMIT".equals(datapoint.getName())) {
            symbols.add(datapoint.getName());
        }
    }
    return symbols.toArray(new String[0]);
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException) ArrayList(java.util.ArrayList) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 4 with HmDatapoint

use of org.openhab.binding.homematic.internal.model.HmDatapoint in project openhab1-addons by openhab.

the class BaseHomematicClient method addBatteryInfo.

/**
     * Adds the battery info datapoint to the specified device if the device has
     * batteries.
     */
protected void addBatteryInfo(HmDevice device) throws HomematicClientException {
    HmBattery battery = HmBatteryTypeProvider.getBatteryType(device.getType());
    if (battery != null) {
        for (HmChannel channel : device.getChannels()) {
            if ("0".equals(channel.getNumber())) {
                try {
                    logger.debug("Adding battery type to device {}: {}", device.getType(), battery.getInfo());
                    HmDatapoint dp = new HmDatapoint();
                    FieldUtils.writeField(dp, "name", "BATTERY_TYPE", true);
                    FieldUtils.writeField(dp, "writeable", Boolean.FALSE, true);
                    FieldUtils.writeField(dp, "valueType", 20, true);
                    dp.setValue(battery.getInfo());
                    channel.addDatapoint(dp);
                } catch (IllegalAccessException ex) {
                    throw new HomematicClientException(ex.getMessage(), ex);
                }
            }
        }
    }
}
Also used : HmBattery(org.openhab.binding.homematic.internal.model.HmBattery) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 5 with HmDatapoint

use of org.openhab.binding.homematic.internal.model.HmDatapoint in project openhab1-addons by openhab.

the class CcuClient method iterateAllDatapoints.

/**
     * {@inheritDoc}
     */
@Override
public void iterateAllDatapoints(HmValueItemIteratorCallback callback) throws HomematicClientException {
    List<HmDevice> devices = sendScriptByName("getAllDevices", HmDeviceList.class).getDevices();
    Map<String, HmRssiInfo> rssiList = rpcClient.getRssiInfo(HmInterface.RF);
    for (HmDevice device : devices) {
        addBatteryInfo(device);
        boolean deviceHasRssiDatapoint = false;
        for (HmChannel channel : device.getChannels()) {
            boolean isChannelZero = "0".equals(channel.getNumber());
            for (HmDatapoint dp : channel.getDatapoints()) {
                DatapointConfig bindingConfig = new DatapointConfig(device.getAddress(), channel.getNumber(), dp.getName());
                HmRssiInfo rssiInfo = rssiList.get(bindingConfig.getAddress());
                if (rssiInfo != null) {
                    if ("RSSI_DEVICE".equals(bindingConfig.getParameter())) {
                        dp.setValue(rssiInfo.getDevice());
                        deviceHasRssiDatapoint = true;
                    } else if ("RSSI_PEER".equals(bindingConfig.getParameter())) {
                        dp.setValue(rssiInfo.getPeer());
                        deviceHasRssiDatapoint = true;
                    }
                }
                callback.iterate(bindingConfig, dp);
            }
            if (isChannelZero && !deviceHasRssiDatapoint) {
                HmRssiInfo rssiInfo = rssiList.get(device.getAddress());
                if (rssiInfo != null) {
                    logger.debug("Adding missing RSSI datapoints to device {} with address {}", device.getType(), device.getAddress());
                    addRssiDatapoint(channel, "RSSI_DEVICE", rssiInfo.getDevice(), callback);
                    addRssiDatapoint(channel, "RSSI_PEER", rssiInfo.getPeer(), callback);
                }
            }
        }
    }
}
Also used : HmDevice(org.openhab.binding.homematic.internal.model.HmDevice) HmRssiInfo(org.openhab.binding.homematic.internal.model.HmRssiInfo) DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HmDeviceList(org.openhab.binding.homematic.internal.model.HmDeviceList) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Aggregations

HmDatapoint (org.openhab.binding.homematic.internal.model.HmDatapoint)7 DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)4 HmChannel (org.openhab.binding.homematic.internal.model.HmChannel)4 HmDevice (org.openhab.binding.homematic.internal.model.HmDevice)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HomematicClientException (org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)1 HmBattery (org.openhab.binding.homematic.internal.model.HmBattery)1 HmDeviceList (org.openhab.binding.homematic.internal.model.HmDeviceList)1 HmRssiInfo (org.openhab.binding.homematic.internal.model.HmRssiInfo)1 TypeGuessAdapter (org.openhab.binding.homematic.internal.model.adapter.TypeGuessAdapter)1