2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.homematic.internal.communicator.virtual;
15 import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
17 import java.io.IOException;
19 import org.apache.commons.lang.StringUtils;
20 import org.openhab.binding.homematic.internal.communicator.parser.DisplayOptionsParser;
21 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
22 import org.openhab.binding.homematic.internal.model.HmChannel;
23 import org.openhab.binding.homematic.internal.model.HmDatapoint;
24 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
25 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
26 import org.openhab.binding.homematic.internal.model.HmDevice;
27 import org.openhab.binding.homematic.internal.model.HmInterface;
28 import org.openhab.binding.homematic.internal.model.HmValueType;
31 * A virtual String datapoint to control the display of a 19 button remote control. You can send a text and/or show
32 * symbols, turn on the backlight and let the remote control beep.
34 * @author Gerhard Riegler - Initial contribution
36 public class DisplayOptionsVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
38 public String getName() {
39 return VIRTUAL_DATAPOINT_NAME_DISPLAY_OPTIONS;
43 public void initialize(HmDevice device) {
44 if (device.getType().startsWith(DEVICE_TYPE_19_REMOTE_CONTROL)
45 && !(device.getHmInterface() == HmInterface.CUXD)) {
46 addDatapoint(device, 18, getName(), HmValueType.STRING, null, false);
51 public boolean canHandleCommand(HmDatapoint dp, Object value) {
52 return getName().equals(dp.getName());
56 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
57 throws IOException, HomematicClientException {
58 HmChannel channel = dp.getChannel();
60 DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel);
61 rcOptionsParser.parse(value);
63 if (StringUtils.isNotBlank(rcOptionsParser.getText())) {
64 sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, rcOptionsParser.getText());
67 sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep());
68 sendDatapoint(gateway, channel, DATAPOINT_NAME_UNIT, rcOptionsParser.getUnit());
69 sendDatapoint(gateway, channel, DATAPOINT_NAME_BACKLIGHT, rcOptionsParser.getBacklight());
71 for (String symbol : rcOptionsParser.getSymbols()) {
72 sendDatapoint(gateway, channel, symbol, Boolean.TRUE);
75 sendDatapoint(gateway, channel, DATAPOINT_NAME_SUBMIT, Boolean.TRUE);
79 private void sendDatapoint(VirtualGateway gateway, HmChannel channel, String dpName, Object newValue)
80 throws IOException, HomematicClientException {
81 HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, dpName);
82 HmDatapoint dp = gateway.getDatapoint(dpInfo);
83 gateway.sendDatapoint(dp, new HmDatapointConfig(), newValue, null);