Search in sources :

Example 1 with HmRssiInfo

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

the class BinRpcClient method getRssiInfo.

/**
     * {@inheritDoc}
     */
@SuppressWarnings("unchecked")
@Override
public Map<String, HmRssiInfo> getRssiInfo(HmInterface hmInterface) throws HomematicClientException {
    BinRpcRequest request = new BinRpcRequest("rssiInfo");
    Map<String, HmRssiInfo> rssiList = new HashMap<String, HmRssiInfo>();
    Object[] result = sendMessage(hmInterface, request);
    if (result != null && result.length > 0 && result[0] instanceof Map) {
        Map<String, ?> devices = (Map<String, ?>) result[0];
        for (String sourceDevice : devices.keySet()) {
            Map<String, Object[]> targetDevices = (Map<String, Object[]>) devices.get(sourceDevice);
            for (String targetDevice : targetDevices.keySet()) {
                if (targetDevice.equals(context.getServerId().getAddress())) {
                    Integer rssiDevice = (Integer) targetDevices.get(targetDevice)[0];
                    Integer rssiPeer = (Integer) targetDevices.get(targetDevice)[1];
                    HmRssiInfo rssiInfo = new HmRssiInfo(sourceDevice, rssiDevice, rssiPeer);
                    rssiList.put(rssiInfo.getAddress(), rssiInfo);
                }
            }
        }
    }
    return rssiList;
}
Also used : HashMap(java.util.HashMap) HmRssiInfo(org.openhab.binding.homematic.internal.model.HmRssiInfo) BinRpcRequest(org.openhab.binding.homematic.internal.binrpc.BinRpcRequest) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with HmRssiInfo

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

HmRssiInfo (org.openhab.binding.homematic.internal.model.HmRssiInfo)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BinRpcRequest (org.openhab.binding.homematic.internal.binrpc.BinRpcRequest)1 DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)1 HmChannel (org.openhab.binding.homematic.internal.model.HmChannel)1 HmDatapoint (org.openhab.binding.homematic.internal.model.HmDatapoint)1 HmDevice (org.openhab.binding.homematic.internal.model.HmDevice)1 HmDeviceList (org.openhab.binding.homematic.internal.model.HmDeviceList)1