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.handler;
15 import static org.openhab.binding.satel.internal.SatelBindingConstants.THING_TYPE_PARTITION;
17 import java.util.Optional;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.satel.internal.command.ControlObjectCommand;
22 import org.openhab.binding.satel.internal.command.SatelCommand;
23 import org.openhab.binding.satel.internal.types.PartitionControl;
24 import org.openhab.binding.satel.internal.types.PartitionState;
25 import org.openhab.binding.satel.internal.types.StateType;
26 import org.openhab.core.library.types.OnOffType;
27 import org.openhab.core.thing.ChannelUID;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.types.Command;
33 * The {@link SatelPartitionHandler} is responsible for handling commands, which are
34 * sent to one of the channels of a partition device.
36 * @author Krzysztof Goworek - Initial contribution
39 public class SatelPartitionHandler extends SatelStateThingHandler {
41 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_PARTITION);
43 public SatelPartitionHandler(Thing thing) {
48 protected StateType getStateType(String channelId) {
49 return PartitionState.valueOf(channelId.toUpperCase());
53 protected Optional<SatelCommand> convertCommand(ChannelUID channel, Command command) {
54 if (command instanceof OnOffType) {
55 boolean switchOn = (command == OnOffType.ON);
56 StateType stateType = getStateType(channel.getId());
57 byte[] partitions = getObjectBitset(4, getThingConfig().getId());
58 boolean forceArm = getThingConfig().isForceArmingEnabled();
59 PartitionControl action = null;
60 switch ((PartitionState) stateType) {
61 // clear alarms on OFF command
65 case FIRE_ALARM_MEMORY:
68 action = switchOn ? null : PartitionControl.CLEAR_ALARM;
71 // arm or disarm, depending on command
74 action = switchOn ? (forceArm ? PartitionControl.FORCE_ARM_MODE_0 : PartitionControl.ARM_MODE_0)
75 : PartitionControl.DISARM;
78 action = switchOn ? (forceArm ? PartitionControl.FORCE_ARM_MODE_1 : PartitionControl.ARM_MODE_1)
79 : PartitionControl.DISARM;
82 action = switchOn ? (forceArm ? PartitionControl.FORCE_ARM_MODE_2 : PartitionControl.ARM_MODE_2)
83 : PartitionControl.DISARM;
86 action = switchOn ? (forceArm ? PartitionControl.FORCE_ARM_MODE_3 : PartitionControl.ARM_MODE_3)
87 : PartitionControl.DISARM;
90 // do nothing for other types of state
97 .of(new ControlObjectCommand(action, partitions, getBridgeHandler().getUserCode(), scheduler));
101 return Optional.empty();