Search in sources :

Example 1 with HmDevice

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

Example 2 with HmDevice

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

the class HomegearClient method iterateAllDatapoints.

/**
     * {@inheritDoc}
     */
@Override
public void iterateAllDatapoints(HmValueItemIteratorCallback callback) throws HomematicClientException {
    Object[] result = rpcClient.getAllValues(getDefaultInterface());
    try {
        for (int i = 0; i < result.length; i++) {
            @SuppressWarnings("unchecked") Map<String, ?> entryMap = (Map<String, ?>) result[i];
            HmDevice device = parseDevice(entryMap);
            addBatteryInfo(device);
            logger.trace("{}", device);
            for (HmChannel channel : device.getChannels()) {
                for (HmDatapoint dp : channel.getDatapoints()) {
                    logger.trace("  {}", dp.toDumpString());
                    DatapointConfig bindingConfig = new DatapointConfig(device.getAddress(), channel.getNumber(), dp.getName());
                    callback.iterate(bindingConfig, dp);
                }
            }
        }
    } catch (Exception ex) {
        throw new HomematicClientException(ex.getMessage(), ex);
    }
}
Also used : HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) HmDevice(org.openhab.binding.homematic.internal.model.HmDevice) DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HashMap(java.util.HashMap) Map(java.util.Map) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel)

Example 3 with HmDevice

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

the class HomegearClient method parseDevice.

/**
     * Parses the device informations into the binding model.
     */
@SuppressWarnings("unchecked")
private HmDevice parseDevice(Map<String, ?> deviceData) throws IllegalAccessException {
    HmDevice device = new HmDevice();
    FieldUtils.writeField(device, "address", deviceData.get("ADDRESS"), true);
    FieldUtils.writeField(device, "type", deviceData.get("TYPE"), true);
    FieldUtils.writeField(device, "hmInterface", HmInterface.HOMEGEAR, true);
    Object[] channelList = (Object[]) deviceData.get("CHANNELS");
    for (int i = 0; i < channelList.length; i++) {
        Map<String, ?> channelData = (Map<String, ?>) channelList[i];
        device.addChannel(parseChannel(device, channelData));
    }
    return device;
}
Also used : HmDevice(org.openhab.binding.homematic.internal.model.HmDevice) HashMap(java.util.HashMap) Map(java.util.Map) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 4 with HmDevice

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

the class ConverterTest method getDatapoint.

private HmDatapoint getDatapoint(String name, Object value, Number min, Number max, String channelNumber, String deviceType) throws Exception {
    HmDatapoint dp = new HmDatapoint();
    FieldUtils.writeField(dp, "name", name, true);
    FieldUtils.writeField(dp, "minValue", min, true);
    FieldUtils.writeField(dp, "maxValue", max, true);
    Object convertedValue = new TypeGuessAdapter().unmarshal(value == null ? null : value.toString());
    if (convertedValue instanceof Boolean) {
        FieldUtils.writeField(dp, "valueType", 2, true);
    } else if (convertedValue instanceof Integer) {
        FieldUtils.writeField(dp, "valueType", 8, true);
    } else if (convertedValue instanceof Double) {
        FieldUtils.writeField(dp, "valueType", 4, true);
    } else {
        FieldUtils.writeField(dp, "valueType", -1, true);
    }
    dp.setValue(convertedValue);
    HmChannel channel = new HmChannel();
    FieldUtils.writeField(dp, "channel", channel, true);
    FieldUtils.writeField(channel, "number", channelNumber, true);
    HmDevice device = new HmDevice();
    FieldUtils.writeField(device, "type", StringUtils.defaultString(deviceType, ""), true);
    FieldUtils.writeField(channel, "device", device, true);
    return dp;
}
Also used : HmDevice(org.openhab.binding.homematic.internal.model.HmDevice) TypeGuessAdapter(org.openhab.binding.homematic.internal.model.adapter.TypeGuessAdapter) 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)4 HmDevice (org.openhab.binding.homematic.internal.model.HmDevice)4 HmChannel (org.openhab.binding.homematic.internal.model.HmChannel)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)2 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