]> git.basschouten.com Git - openhab-addons.git/blob
8167e31c004db344ad5a61735ba26c729a7b0c45
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.homematic.internal.communicator.virtual;
14
15 import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
16
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;
23
24 /**
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.
28  *
29  * @author Gerhard Riegler - Initial contribution
30  */
31 public class HmwIoModuleVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
32     @Override
33     public String getName() {
34         return null;
35     }
36
37     @Override
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);
46
47                     if (hasStateDatapoint && !hasValueDatapoint) {
48                         HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_VALUE,
49                                 HmValueType.FLOAT, 0.0, false);
50                         dp.setMinValue(0.0);
51                         dp.setMaxValue(1000.0);
52                         dp.setVirtual(false);
53                     } else if (hasValueDatapoint && !hasStateDatapoint) {
54                         HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_STATE,
55                                 HmValueType.BOOL, false, false);
56                         dp.setVirtual(false);
57                     }
58                 }
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);
65                         dp.setMinValue(-127);
66                         dp.setMaxValue(127);
67                         addDatapoint(channel, dp);
68                         dp.setVirtual(false);
69                     }
70                 }
71             }
72         }
73     }
74 }