]> git.basschouten.com Git - openhab-addons.git/blob
129662f107855860089cd30a8d7685e400d31b50
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.insteon.internal.driver;
14
15 import java.util.ArrayList;
16 import java.util.Collections;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.insteon.internal.device.InsteonAddress;
21 import org.openhab.binding.insteon.internal.message.Msg;
22 import org.openhab.binding.insteon.internal.utils.Utils;
23
24 /**
25  * The ModemDBEntry class holds a modem device type record
26  * an xml file.
27  *
28  * @author Bernd Pfrommer - Initial contribution
29  * @author Rob Nielsen - Port to openHAB 2 insteon binding
30  */
31 @NonNullByDefault
32 public class ModemDBEntry {
33     private @Nullable InsteonAddress address = null;
34     private boolean isModem;
35     private @Nullable Port port = null;
36     private ArrayList<Msg> linkRecords = new ArrayList<>();
37     private ArrayList<Byte> controls = new ArrayList<>();
38     private ArrayList<Byte> respondsTo = new ArrayList<>();
39
40     public ModemDBEntry(InsteonAddress aAddr, boolean isModem) {
41         this.address = aAddr;
42         this.isModem = isModem;
43     }
44
45     public boolean isModem() {
46         return isModem;
47     }
48
49     public ArrayList<Msg> getLinkRecords() {
50         return linkRecords;
51     }
52
53     public void addLinkRecord(Msg m) {
54         linkRecords.add(m);
55     }
56
57     public void addControls(byte c) {
58         controls.add(c);
59     }
60
61     public ArrayList<Byte> getControls() {
62         return controls;
63     }
64
65     public void addRespondsTo(byte r) {
66         respondsTo.add(r);
67     }
68
69     public ArrayList<Byte> getRespondsTo() {
70         return respondsTo;
71     }
72
73     public void setPort(Port p) {
74         port = p;
75     }
76
77     public @Nullable Port getPort() {
78         return port;
79     }
80
81     @Override
82     public String toString() {
83         String s = "addr:" + address + "|controls:[" + toGroupString(controls) + "]|responds_to:["
84                 + toGroupString(respondsTo) + "]|link_recors";
85         for (Msg m : linkRecords) {
86             s += ":(" + m + ")";
87         }
88         return s;
89     }
90
91     private String toGroupString(ArrayList<Byte> group) {
92         ArrayList<Byte> sorted = new ArrayList<>(group);
93         Collections.sort(sorted);
94
95         StringBuilder buf = new StringBuilder();
96         for (Byte b : sorted) {
97             if (buf.length() > 0) {
98                 buf.append(",");
99             }
100             buf.append("0x");
101             buf.append(Utils.getHexString(b));
102         }
103
104         return buf.toString();
105     }
106 }