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.command;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.satel.internal.event.EventDispatcher;
19 import org.openhab.binding.satel.internal.event.IntegraStateEvent;
20 import org.openhab.binding.satel.internal.protocol.SatelMessage;
21 import org.openhab.binding.satel.internal.types.StateType;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Command class for commands that return state of Integra objects, like
27 * partitions (armed, alarm, entry time), zones (violation, tamper, alarm),
28 * outputs and doors (opened, opened long).
30 * @author Krzysztof Goworek - Initial contribution
33 public class IntegraStateCommand extends SatelCommandBase {
35 private final Logger logger = LoggerFactory.getLogger(IntegraStateCommand.class);
37 private StateType stateType;
40 * Constructs new command instance for specified type of state.
42 * @param stateType type of state
43 * @param extended if <code>true</code> command will be sent as extended (256 zones or outputs)
45 public IntegraStateCommand(StateType stateType, boolean extended) {
46 super(stateType.getRefreshCommand(), extended);
47 this.stateType = stateType;
51 * @return <code>true</code> if current command is extended (256 zones/outputs)
53 public boolean isExtended() {
54 return Arrays.equals(EXTENDED_CMD_PAYLOAD, this.getPayload());
58 protected boolean isResponseValid(SatelMessage response) {
60 if (response.getPayload().length != this.stateType.getPayloadLength(isExtended())) {
61 logger.debug("Invalid payload length for state type {}: {}", this.stateType, response.getPayload().length);
68 protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
70 eventDispatcher.dispatchEvent(
71 new IntegraStateEvent(getResponse().getCommand(), getResponse().getPayload(), isExtended()));