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 org.openhab.binding.homematic.internal.model.HmChannel;
18 import org.openhab.binding.homematic.internal.model.HmDatapoint;
19 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
20 import org.openhab.binding.homematic.internal.model.HmDevice;
21 import org.openhab.binding.homematic.internal.model.HmParamsetType;
22 import org.openhab.binding.homematic.internal.model.HmValueType;
25 * Adds a STATE, VALUE and CALIBRATION datapoint to the HMW-IO-12-Sw14-DR device.
26 * This device can change its metadata depending on the configuration. This virtual datapoint ensures, that always all
27 * datapoints are available.
29 * @author Gerhard Riegler - Initial contribution
31 public class HmwIoModuleVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
33 public String getName() {
38 public void initialize(HmDevice device) {
39 if (device.getType().startsWith(DEVICE_TYPE_WIRED_IO_MODULE)) {
40 for (HmChannel channel : device.getChannels()) {
41 if (channel.getNumber() >= 7) {
42 HmDatapointInfo dpInfoState = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_STATE);
43 HmDatapointInfo dpInfoValue = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_VALUE);
44 boolean hasStateDatapoint = channel.hasDatapoint(dpInfoState);
45 boolean hasValueDatapoint = channel.hasDatapoint(dpInfoValue);
47 if (hasStateDatapoint && !hasValueDatapoint) {
48 HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_VALUE,
49 HmValueType.FLOAT, 0.0, false);
51 dp.setMaxValue(1000.0);
53 } else if (hasValueDatapoint && !hasStateDatapoint) {
54 HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_STATE,
55 HmValueType.BOOL, false, false);
59 if (channel.getNumber() >= 21) {
60 HmDatapointInfo dpInfoCalibration = new HmDatapointInfo(HmParamsetType.MASTER, channel,
61 DATAPOINT_NAME_CALIBRATION);
62 if (!channel.hasDatapoint(dpInfoCalibration)) {
63 HmDatapoint dp = new HmDatapoint(DATAPOINT_NAME_CALIBRATION, DATAPOINT_NAME_CALIBRATION,
64 HmValueType.INTEGER, 0, false, HmParamsetType.MASTER);
67 addDatapoint(channel, dp);