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);
}
}
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));
}
}
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;
}
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;
}
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);
}
Aggregations