]> git.basschouten.com Git - openhab-addons.git/blob
4b49e476731ae0dbfbe80dade5ab997f74c65f93
[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.paradoxalarm.internal.communication.messages.partition;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.paradoxalarm.internal.communication.IRequest;
18 import org.openhab.binding.paradoxalarm.internal.communication.PartitionCommandRequest;
19 import org.openhab.binding.paradoxalarm.internal.communication.RequestType;
20 import org.openhab.binding.paradoxalarm.internal.communication.messages.Command;
21 import org.openhab.binding.paradoxalarm.internal.communication.messages.HeaderMessageType;
22 import org.openhab.binding.paradoxalarm.internal.communication.messages.ParadoxIPPacket;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * The {@link PartitionCommand} Enum representing the possible commands for a partition with the respective integer
28  * values that are sent as nibbles in the packet.
29  *
30  * @author Konstantin Polihronov - Initial contribution
31  */
32 @NonNullByDefault
33 public enum PartitionCommand implements Command {
34     ARM(2),
35     STAY_ARM(3),
36     INSTANT_ARM(4),
37     FORCE_ARM(5),
38     DISARM(6),
39     BEEP(8);
40
41     private static final Logger LOGGER = LoggerFactory.getLogger(PartitionCommand.class);
42
43     private int command;
44
45     PartitionCommand(int command) {
46         this.command = command;
47     }
48
49     public int getCommand() {
50         return command;
51     }
52
53     public static @Nullable PartitionCommand parse(String command) {
54         try {
55             return PartitionCommand.valueOf(command);
56         } catch (IllegalArgumentException e) {
57             LOGGER.debug("Unable to parse command={}. Fallback to UNKNOWN.", command);
58             return null;
59         }
60     }
61
62     @Override
63     public IRequest getRequest(int partitionId) {
64         PartitionCommandPayload payload = new PartitionCommandPayload(partitionId, this);
65         ParadoxIPPacket packet = new ParadoxIPPacket(payload.getBytes())
66                 .setMessageType(HeaderMessageType.SERIAL_PASSTHRU_REQUEST);
67         return new PartitionCommandRequest(RequestType.PARTITION_COMMAND, packet, null);
68     }
69 }