Search in sources :

Example 41 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class SignalStrengthVirtualDatapointHandler method handleEvent.

@Override
public void handleEvent(VirtualGateway gateway, HmDatapoint dp) {
    HmChannel channel = dp.getChannel();
    Integer value = getRssiValue(channel);
    if (value != null) {
        Integer strength = Math.max(Math.abs(value), RSSI_START);
        strength = strength > RSSI_START + RSSI_STEP * RSSI_UNITS ? 0 : RSSI_UNITS - ((strength - RSSI_START) / RSSI_STEP);
        HmDatapoint vdpRssi = getVirtualDatapoint(channel);
        vdpRssi.setValue(strength);
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 42 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class CommonRpcParser method adjustRssiValue.

/**
 * Adjust uninitialized rssi values to zero.
 */
protected void adjustRssiValue(HmDatapoint dp) {
    if (dp.getValue() != null && dp.getName().startsWith("RSSI_") && dp.isIntegerType()) {
        int rssiValue = ((Number) dp.getValue()).intValue();
        dp.setValue(getAdjustedRssiValue(rssiValue));
    }
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 43 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class CommonRpcParser method assembleDatapoint.

/**
 * Assembles a datapoint with the given parameters.
 */
protected HmDatapoint assembleDatapoint(String name, String unit, String type, String[] options, Object min, Object max, Integer operations, Object defaultValue, HmParamsetType paramsetType, boolean isHmIpDevice) throws IOException {
    HmDatapoint dp = new HmDatapoint();
    dp.setName(name);
    dp.setDescription(name);
    dp.setUnit(StringUtils.replace(StringUtils.trimToNull(unit), "\ufffd", "°"));
    if (dp.getUnit() == null && StringUtils.startsWith(dp.getName(), "RSSI_")) {
        dp.setUnit("dBm");
    }
    HmValueType valueType = HmValueType.parse(type);
    if (valueType == null || valueType == HmValueType.UNKNOWN) {
        throw new IOException("Unknown datapoint type: " + type);
    }
    dp.setType(valueType);
    dp.setOptions(options);
    if (dp.isNumberType() || dp.isEnumType()) {
        if (isHmIpDevice && dp.isEnumType()) {
            dp.setMinValue(dp.getOptionIndex(toString(min)));
            dp.setMaxValue(dp.getOptionIndex(toString(max)));
        } else {
            dp.setMinValue(toNumber(min));
            dp.setMaxValue(toNumber(max));
        }
    }
    dp.setReadOnly((operations & 2) != 2);
    dp.setReadable((operations & 1) == 1);
    dp.setParamsetType(paramsetType);
    if (isHmIpDevice && dp.isEnumType()) {
        dp.setDefaultValue(dp.getOptionIndex(toString(defaultValue)));
    } else {
        dp.setDefaultValue(convertToType(dp, defaultValue));
    }
    dp.setValue(dp.getDefaultValue());
    return dp;
}
Also used : HmValueType(org.eclipse.smarthome.binding.homematic.internal.model.HmValueType) IOException(java.io.IOException) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 44 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class GetAllSystemVariablesParser method parse.

@Override
@SuppressWarnings("unchecked")
public Void parse(Object[] message) throws IOException {
    Map<String, ?> mapMessage = (Map<String, ?>) message[0];
    for (String variableName : mapMessage.keySet()) {
        Object value = mapMessage.get(variableName);
        HmDatapoint dp = channel.getDatapoint(HmParamsetType.VALUES, variableName);
        if (dp != null) {
            dp.setValue(value);
        } else {
            HmDatapoint dpVariable = new HmDatapoint(variableName, variableName, guessType(value), value, false, HmParamsetType.VALUES);
            dpVariable.setInfo(variableName);
            channel.addDatapoint(dpVariable);
        }
    }
    return null;
}
Also used : Map(java.util.Map) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 45 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class HomematicThingHandler method updateChannelState.

/**
 * Evaluates the channel and datapoint for this channelUID and updates the state of the channel.
 */
private void updateChannelState(ChannelUID channelUID) throws GatewayNotAvailableException, HomematicClientException, IOException, ConverterException {
    HomematicGateway gateway = getHomematicGateway();
    HmDatapointInfo dpInfo = UidUtils.createHmDatapointInfo(channelUID);
    HmDatapoint dp = gateway.getDatapoint(dpInfo);
    Channel channel = getThing().getChannel(channelUID.getId());
    updateChannelState(dp, channel);
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Aggregations

HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)55 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)21 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)12 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)7 HmDevice (org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)7 Test (org.junit.Test)6 IOException (java.io.IOException)5 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)5 ArrayList (java.util.ArrayList)4 HomematicGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway)4 Channel (org.eclipse.smarthome.core.thing.Channel)4 JavaTest (org.eclipse.smarthome.test.java.JavaTest)4 Map (java.util.Map)3 TclScriptDataEntry (org.eclipse.smarthome.binding.homematic.internal.model.TclScriptDataEntry)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 HashMap (java.util.HashMap)2 BatteryTypeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler)2 ButtonVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler)2 DeleteDeviceModeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler)2 DeleteDeviceVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler)2