2 * Copyright (c) 2010-2024 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.freeathomesystem.internal.datamodel;
15 import java.util.Iterator;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.google.gson.JsonObject;
26 * @author Andras Uhrin - Initial contribution
30 public class FreeAtHomeDatapoint {
32 private final Logger logger = LoggerFactory.getLogger(FreeAtHomeDatapoint.class);
34 enum DatapointDirection {
42 public String channelId = "";
43 private String datapointId = "";
45 DatapointDirection searchForDatapoint(DatapointDirection direction, int neededPairingIDFunction, String channelId,
46 JsonObject jsonObjectOfChannel) {
47 DatapointDirection resultingDirection = DatapointDirection.UNKNOWN;
48 boolean foundId = false;
49 JsonObject localDatapoints = null;
53 localDatapoints = jsonObjectOfChannel.getAsJsonObject("inputs");
54 resultingDirection = DatapointDirection.INPUT;
57 case INPUT_AS_OUTPUT: {
58 localDatapoints = jsonObjectOfChannel.getAsJsonObject("inputs");
59 resultingDirection = DatapointDirection.OUTPUT;
63 localDatapoints = jsonObjectOfChannel.getAsJsonObject("outputs");
64 resultingDirection = DatapointDirection.OUTPUT;
68 localDatapoints = jsonObjectOfChannel.getAsJsonObject("outputs");
69 resultingDirection = DatapointDirection.OUTPUT;
74 Set<String> keys = localDatapoints.keySet();
76 Iterator<String> iter = keys.iterator();
78 // Scan datapoints for pairingID IDs
79 while (iter.hasNext() && !foundId) {
80 String datapointId = iter.next();
82 JsonObject datapointJsonObject = localDatapoints.getAsJsonObject(datapointId);
84 int pairingIDFunction = datapointJsonObject.get("pairingID").getAsInt();
86 if (pairingIDFunction == neededPairingIDFunction) {
87 this.channelId = channelId;
88 this.datapointId = datapointId;
90 logger.debug("Datapoint is found - channel {} - datapoint {}", this.channelId, this.datapointId);
96 // id not found, add dummy
99 this.datapointId = "";
100 resultingDirection = DatapointDirection.UNKNOWN;
102 logger.debug("Needed datapoint is not found - channel {} - pairingId {}", channelId,
103 neededPairingIDFunction);
106 return resultingDirection;
109 public String getChannelIdforDatapoint() {
113 public String getDatapointId() {