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.BitSet;
16 import java.util.concurrent.ScheduledExecutorService;
17 import java.util.concurrent.TimeUnit;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.satel.internal.event.EventDispatcher;
21 import org.openhab.binding.satel.internal.event.NewStatesEvent;
22 import org.openhab.binding.satel.internal.types.ControlType;
25 * Command class for commands that control (change) state of Integra objects,
26 * like partitions (arm, disarm), zones (bypass, unbypass) outputs (on, off,
29 * @author Krzysztof Goworek - Initial contribution
32 public class ControlObjectCommand extends ControlCommand {
34 private static final long REFRESH_DELAY = 1000;
36 private ControlType controlType;
37 private ScheduledExecutorService scheduler;
40 * Creates new command class instance for specified type of control.
42 * @param controlType type of controlled objects
43 * @param objects bits that represents objects to control
44 * @param userCode code of the user on behalf the control is made
45 * @param scheduler scheduler object for scheduling refreshes
47 public ControlObjectCommand(ControlType controlType, byte[] objects, String userCode,
48 ScheduledExecutorService scheduler) {
49 super(controlType.getControlCommand(), objects, userCode);
50 this.controlType = controlType;
51 this.scheduler = scheduler;
55 protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
56 // force refresh states that might have changed
57 final BitSet newStates = controlType.getControlledStates();
58 if (!newStates.isEmpty()) {
59 // add delay to give a chance to process sent command
60 scheduler.schedule(() -> eventDispatcher.dispatchEvent(new NewStatesEvent(newStates)), REFRESH_DELAY,
61 TimeUnit.MILLISECONDS);