]> git.basschouten.com Git - openhab-addons.git/blob
aaf82b5b517cecc671c3bc6f9234732ecdef0434
[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.tacmi.internal.coe;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.tacmi.internal.message.AnalogMessage;
17 import org.openhab.binding.tacmi.internal.message.DigitalMessage;
18 import org.openhab.binding.tacmi.internal.message.MessageType;
19 import org.openhab.core.thing.ChannelUID;
20
21 /**
22  * This class carries all relevant data for the POD
23  *
24  * @author Christian Niessner - Initial contribution
25  */
26 @NonNullByDefault
27 public class PodDataOutgoing extends PodData {
28
29     protected long lastSent;
30     protected final ChannelUID[] channeUIDs;
31     protected final boolean[] initialized;
32     private boolean allValuesInitialized;
33
34     /**
35      * Create new AnalogValue with specified value and type
36      */
37     public PodDataOutgoing(PodIdentifier pi, byte node) {
38         super(pi, node);
39         boolean analog = pi.messageType == MessageType.ANALOG;
40         int valueCount = analog ? 4 : 16;
41         this.channeUIDs = new ChannelUID[valueCount];
42         this.initialized = new boolean[valueCount];
43         this.allValuesInitialized = false;
44         this.message = analog ? new AnalogMessage(node, pi.podId) : new DigitalMessage(node, pi.podId);
45         this.lastSent = System.currentTimeMillis();
46     }
47
48     /**
49      * checks if all (in use) values have been set to a value - used to prevent sending of unintended values via CoE
50      */
51     public boolean isAllValuesInitialized() {
52         if (this.allValuesInitialized) {
53             return true;
54         }
55         boolean allInitialized = true;
56         for (int idx = 0; idx < this.initialized.length; idx++) {
57             if (this.channeUIDs[idx] != null && !this.initialized[idx]) {
58                 return false;
59             }
60         }
61         if (!allInitialized) {
62             return false;
63         }
64         this.allValuesInitialized = true;
65         return true;
66     }
67
68     public String getUninitializedChannelNames() {
69         if (this.allValuesInitialized) {
70             return "";
71         }
72
73         StringBuilder sb = new StringBuilder();
74         for (int idx = 0; idx < this.initialized.length; idx++) {
75             ChannelUID ct = this.channeUIDs[idx];
76             if (ct != null && !this.initialized[idx]) {
77                 if (sb.length() > 0) {
78                     sb.append(", ");
79                 }
80                 sb.append(ct.getId());
81             }
82         }
83         return sb.toString();
84     }
85 }