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 java.io.IOException;
17 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
18 import org.openhab.binding.homematic.internal.model.HmChannel;
19 import org.openhab.binding.homematic.internal.model.HmDatapoint;
20 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
21 import org.openhab.binding.homematic.internal.model.HmDevice;
22 import org.openhab.binding.homematic.internal.model.HmParamsetType;
23 import org.openhab.binding.homematic.internal.model.HmValueType;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Abstract base class for all virtual datapoints with common methods.
30 * @author Gerhard Riegler - Initial contribution
32 public abstract class AbstractVirtualDatapointHandler implements VirtualDatapointHandler {
33 private final Logger logger = LoggerFactory.getLogger(AbstractVirtualDatapointHandler.class);
36 public boolean canHandleCommand(HmDatapoint dp, Object value) {
41 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
42 throws IOException, HomematicClientException {
46 public boolean canHandleEvent(HmDatapoint dp) {
51 public void handleEvent(VirtualGateway gateway, HmDatapoint dp) {
55 public HmDatapoint getVirtualDatapoint(HmChannel channel) {
56 return channel.getDatapoint(HmParamsetType.VALUES, getName());
60 * Creates a new datapoint with the given parameters and adds it to the channel.
62 protected HmDatapoint addDatapoint(HmDevice device, Integer channelNumber, String datapointName,
63 HmValueType valueType, Object value, boolean readOnly) {
64 HmChannel channel = device.getChannel(channelNumber);
65 HmDatapoint dp = new HmDatapoint(datapointName, datapointName, valueType, value, readOnly,
66 HmParamsetType.VALUES);
67 return addDatapoint(channel, dp);
71 * Adds a new datapoint to the channel.
73 protected HmDatapoint addDatapoint(HmChannel channel, HmDatapoint dp) {
74 logger.trace("Adding virtual datapoint '{}' to device '{}' ({}) and channel {}", dp.getName(),
75 channel.getDevice().getAddress(), channel.getDevice().getType(), channel.getNumber());
78 channel.addDatapoint(dp);