]> git.basschouten.com Git - openhab-addons.git/blob
2c8c8370d5665d5060ae4b95a4b7f875d324340e
[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.satel.internal.types;
14
15 import java.util.BitSet;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Base of all kinds of Integra state.
21  *
22  * @author Krzysztof Goworek - Initial contribution
23  */
24 @NonNullByDefault
25 public interface StateType {
26
27     /**
28      * Returns Satel command to get current state for this state type.
29      *
30      * @return command identifier
31      */
32     byte getRefreshCommand();
33
34     /**
35      * Returns number of payload bytes in refresh command.
36      *
37      * @param extendedCmd if <code>true</code> return number of bytes for extended command
38      * @return payload length
39      */
40     int getPayloadLength(boolean extendedCmd);
41
42     /**
43      * Returns object type for this kind of state.
44      *
45      * @return Integra object type
46      */
47     ObjectType getObjectType();
48
49     /**
50      * Returns state's first byte in the response buffer.
51      *
52      * @return start byte in the response
53      */
54     int getStartByte();
55
56     /**
57      * Returns number of state bytes in the response buffer.
58      *
59      * @param extendedCmd if <code>true</code> return number of bytes for extended command
60      * @return bytes count in the response
61      */
62     int getBytesCount(boolean extendedCmd);
63
64     /**
65      * Builds bit set based on list of state types. Each bit is addressed by refresh command.
66      *
67      * @param states list of states
68      * @return built bit set
69      */
70     static BitSet getStatesBitSet(StateType... states) {
71         BitSet stateBits = new BitSet();
72         for (StateType state : states) {
73             stateBits.set(state.getRefreshCommand());
74         }
75         return stateBits;
76     }
77
78     /**
79      * Marker instance for lack of state type.
80      */
81     static final StateType NONE = new StateType() {
82
83         @Override
84         public byte getRefreshCommand() {
85             throw new UnsupportedOperationException("Illegal use of NONE state type");
86         }
87
88         @Override
89         public int getPayloadLength(boolean extendedCmd) {
90             throw new UnsupportedOperationException("Illegal use of NONE state type");
91         }
92
93         @Override
94         public ObjectType getObjectType() {
95             throw new UnsupportedOperationException("Illegal use of NONE state type");
96         }
97
98         @Override
99         public int getStartByte() {
100             throw new UnsupportedOperationException("Illegal use of NONE state type");
101         }
102
103         @Override
104         public int getBytesCount(boolean extendedCmd) {
105             throw new UnsupportedOperationException("Illegal use of NONE state type");
106         }
107     };
108 }