2 * Copyright (c) 2010-2023 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.satel.internal.types;
15 import java.util.BitSet;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Base of all kinds of Integra state.
22 * @author Krzysztof Goworek - Initial contribution
25 public interface StateType {
28 * Returns Satel command to get current state for this state type.
30 * @return command identifier
32 byte getRefreshCommand();
35 * Returns number of payload bytes in refresh command.
37 * @param extendedCmd if <code>true</code> return number of bytes for extended command
38 * @return payload length
40 int getPayloadLength(boolean extendedCmd);
43 * Returns object type for this kind of state.
45 * @return Integra object type
47 ObjectType getObjectType();
50 * Returns state's first byte in the response buffer.
52 * @return start byte in the response
57 * Returns number of state bytes in the response buffer.
59 * @param extendedCmd if <code>true</code> return number of bytes for extended command
60 * @return bytes count in the response
62 int getBytesCount(boolean extendedCmd);
65 * Builds bit set based on list of state types. Each bit is addressed by refresh command.
67 * @param states list of states
68 * @return built bit set
70 static BitSet getStatesBitSet(StateType... states) {
71 BitSet stateBits = new BitSet();
72 for (StateType state : states) {
73 stateBits.set(state.getRefreshCommand());
79 * Marker instance for lack of state type.
81 static final StateType NONE = new StateType() {
84 public byte getRefreshCommand() {
85 throw new UnsupportedOperationException("Illegal use of NONE state type");
89 public int getPayloadLength(boolean extendedCmd) {
90 throw new UnsupportedOperationException("Illegal use of NONE state type");
94 public ObjectType getObjectType() {
95 throw new UnsupportedOperationException("Illegal use of NONE state type");
99 public int getStartByte() {
100 throw new UnsupportedOperationException("Illegal use of NONE state type");
104 public int getBytesCount(boolean extendedCmd) {
105 throw new UnsupportedOperationException("Illegal use of NONE state type");