use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig in project smarthome by eclipse.
the class DisplayOptionsVirtualDatapointHandler method sendDatapoint.
private void sendDatapoint(VirtualGateway gateway, HmChannel channel, String dpName, Object newValue) throws IOException, HomematicClientException {
HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, dpName);
HmDatapoint dp = gateway.getDatapoint(dpInfo);
gateway.sendDatapoint(dp, new HmDatapointConfig(), newValue, null);
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig in project smarthome by eclipse.
the class DisplayTextVirtualDatapoint method handleCommand.
@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
dp.setValue(value);
if (DATAPOINT_NAME_DISPLAY_SUBMIT.equals(dp.getName()) && MiscUtils.isTrueValue(dp.getValue())) {
HmChannel channel = dp.getChannel();
boolean isEp = isEpDisplay(channel.getDevice());
List<String> message = new ArrayList<String>();
message.add(START);
if (isEp) {
message.add(LF);
}
for (int i = 1; i <= getLineCount(channel.getDevice()); i++) {
String line = ObjectUtils.toString(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue());
if (StringUtils.isEmpty(line)) {
line = " ";
}
message.add(LINE);
message.add(encodeText(line));
if (!isEp) {
String color = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_COLOR + i).getOptionValue();
message.add(COLOR);
String colorCode = Color.getCode(color);
message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode);
}
String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i).getOptionValue();
String iconCode = Icon.getCode(icon);
if (StringUtils.isNotBlank(iconCode)) {
message.add(ICON);
message.add(iconCode);
}
message.add(LF);
}
if (isEp) {
String beeper = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPER).getOptionValue();
message.add(BEEPER_START);
message.add(Beeper.getCode(beeper));
message.add(BEEPER_END);
// set number of beeps
message.add(encodeBeepCount(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPCOUNT)));
message.add(BEEPCOUNT_END);
// set interval between two beeps
message.add(encodeBeepInterval(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPINTERVAL)));
message.add(BEEPINTERVAL_END);
// LED value must always set (same as beeps)
String led = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LED).getOptionValue();
message.add(Led.getCode(led));
}
message.add(STOP);
gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT), new HmDatapointConfig(), StringUtils.join(message, ","), null);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig in project smarthome by eclipse.
the class HomematicThingHandler method getChannelConfig.
/**
* Returns the channel config for the given datapoint.
*/
protected HmDatapointConfig getChannelConfig(HmDatapoint dp) {
ChannelUID channelUid = UidUtils.generateChannelUID(dp, getThing().getUID());
Channel channel = getThing().getChannel(channelUid.getId());
return channel != null ? getChannelConfig(channel, dp) : new HmDatapointConfig();
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig in project smarthome by eclipse.
the class HomematicThingHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) throws ConfigValidationException {
super.handleConfigurationUpdate(configurationParameters);
try {
HomematicGateway gateway = getHomematicGateway();
HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
String key = configurationParameter.getKey();
Object newValue = configurationParameter.getValue();
if (key.startsWith("HMP_")) {
key = StringUtils.removeStart(key, "HMP_");
Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
String dpName = StringUtils.substringAfter(key, "_");
HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName);
HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);
if (dp != null) {
try {
if (newValue != null) {
if (newValue instanceof BigDecimal) {
final BigDecimal decimal = (BigDecimal) newValue;
if (dp.isIntegerType()) {
newValue = decimal.intValue();
} else if (dp.isFloatType()) {
newValue = decimal.doubleValue();
}
}
if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
sendDatapoint(dp, new HmDatapointConfig(), newValue);
}
}
} catch (IOException ex) {
logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
}
} else {
logger.error("Can't find datapoint for thing property {}", dpInfo);
}
}
}
gateway.triggerDeviceValuesReload(device);
} catch (HomematicClientException | GatewayNotAvailableException ex) {
logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig in project smarthome by eclipse.
the class AbstractHomematicGateway method setInstallMode.
@Override
public void setInstallMode(boolean enable, int seconds) throws IOException {
HmDevice gwExtrasHm = devices.get(HmDevice.ADDRESS_GATEWAY_EXTRAS);
if (gwExtrasHm != null) {
// since the homematic virtual device exist: try setting install mode via its dataPoints
HmDatapoint installModeDataPoint = null;
HmDatapoint installModeDurationDataPoint = null;
// collect virtual datapoints to be accessed
HmChannel hmChannel = gwExtrasHm.getChannel(HmChannel.CHANNEL_NUMBER_EXTRAS);
HmDatapointInfo installModeDurationDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE_DURATION);
if (enable) {
installModeDurationDataPoint = hmChannel.getDatapoint(installModeDurationDataPointInfo);
}
HmDatapointInfo installModeDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE);
installModeDataPoint = hmChannel.getDatapoint(installModeDataPointInfo);
// first set duration on the datapoint
if (installModeDurationDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDurationDataPoint, null);
handler.handleCommand(this, installModeDurationDataPoint, new HmDatapointConfig(), seconds);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDurationDataPoint);
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDurationDataPoint, ex);
}
}
// now that the duration is set, we can enable / disable
if (installModeDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDataPoint, null);
handler.handleCommand(this, installModeDataPoint, new HmDatapointConfig(), enable);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDataPoint);
return;
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDataPoint, ex);
}
}
}
// no gwExtrasHm available (or previous approach failed), therefore use rpc client directly
for (HmInterface hmInterface : availableInterfaces.keySet()) {
if (hmInterface == HmInterface.RF || hmInterface == HmInterface.CUXD) {
getRpcClient(hmInterface).setInstallMode(hmInterface, enable, seconds);
}
}
}
Aggregations