2 * Copyright (c) 2010-2023 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.openhab.binding.homematic.internal.communicator.parser.DisplayOptionsParser;
20 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
21 import org.openhab.binding.homematic.internal.model.HmChannel;
22 import org.openhab.binding.homematic.internal.model.HmDatapoint;
23 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
24 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
25 import org.openhab.binding.homematic.internal.model.HmDevice;
26 import org.openhab.binding.homematic.internal.model.HmInterface;
27 import org.openhab.binding.homematic.internal.model.HmValueType;
30 * A virtual String datapoint to control the display of a 19 button remote control. You can send a text and/or show
31 * symbols, turn on the backlight and let the remote control beep.
33 * @author Gerhard Riegler - Initial contribution
35 public class DisplayOptionsVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
37 public String getName() {
38 return VIRTUAL_DATAPOINT_NAME_DISPLAY_OPTIONS;
42 public void initialize(HmDevice device) {
43 if (device.getType().startsWith(DEVICE_TYPE_19_REMOTE_CONTROL) && device.getHmInterface() != HmInterface.CUXD) {
44 addDatapoint(device, 18, getName(), HmValueType.STRING, null, false);
49 public boolean canHandleCommand(HmDatapoint dp, Object value) {
50 return getName().equals(dp.getName());
54 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
55 throws IOException, HomematicClientException {
56 HmChannel channel = dp.getChannel();
58 DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel);
59 rcOptionsParser.parse(value);
61 String dpNameText = rcOptionsParser.getText();
62 if (dpNameText != null && !dpNameText.isBlank()) {
63 sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, dpNameText);
66 sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep());
67 sendDatapoint(gateway, channel, DATAPOINT_NAME_UNIT, rcOptionsParser.getUnit());
68 sendDatapoint(gateway, channel, DATAPOINT_NAME_BACKLIGHT, rcOptionsParser.getBacklight());
70 for (String symbol : rcOptionsParser.getSymbols()) {
71 sendDatapoint(gateway, channel, symbol, Boolean.TRUE);
74 sendDatapoint(gateway, channel, DATAPOINT_NAME_SUBMIT, Boolean.TRUE);
78 private void sendDatapoint(VirtualGateway gateway, HmChannel channel, String dpName, Object newValue)
79 throws IOException, HomematicClientException {
80 HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, dpName);
81 HmDatapoint dp = gateway.getDatapoint(dpInfo);
82 gateway.sendDatapoint(dp, new HmDatapointConfig(), newValue, null);