]> git.basschouten.com Git - openhab-addons.git/blob
7433ae854233c98d2b03a08d4385cc84617ded18
[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.zone;
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.RequestType;
19 import org.openhab.binding.paradoxalarm.internal.communication.ZoneCommandRequest;
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  * @author Konstantin Polihronov - Initial contribution
28  */
29 @NonNullByDefault
30 public enum ZoneCommand implements Command {
31     CLEAR_BYPASS(0),
32     BYPASS(8);
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(ZoneCommand.class);
35
36     private byte command;
37
38     ZoneCommand(int command) {
39         this.command = (byte) command;
40     }
41
42     public byte getCommand() {
43         return command;
44     }
45
46     public static @Nullable ZoneCommand parse(@Nullable String command) {
47         if (command == null) {
48             return null;
49         }
50
51         try {
52             return ZoneCommand.valueOf(command);
53         } catch (IllegalArgumentException e) {
54             LOGGER.debug("Unable to parse command={}. Fallback to UNKNOWN.", command);
55             return null;
56         }
57     }
58
59     @Override
60     public IRequest getRequest(int zoneId) {
61         ZoneCommandPayload payload = new ZoneCommandPayload(zoneId, this);
62         ParadoxIPPacket packet = new ParadoxIPPacket(payload.getBytes(), false)
63                 .setMessageType(HeaderMessageType.SERIAL_PASSTHRU_REQUEST);
64         return new ZoneCommandRequest(RequestType.ZONE_COMMAND, packet, null);
65     }
66 }