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.paradoxalarm.internal.communication.messages.partition;
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;
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.
30 * @author Konstantin Polihronov - Initial contribution
33 public enum PartitionCommand implements Command {
41 private static final Logger LOGGER = LoggerFactory.getLogger(PartitionCommand.class);
45 PartitionCommand(int command) {
46 this.command = command;
49 public int getCommand() {
53 public static @Nullable PartitionCommand parse(String command) {
55 return PartitionCommand.valueOf(command);
56 } catch (IllegalArgumentException e) {
57 LOGGER.debug("Unable to parse command={}. Fallback to UNKNOWN.", command);
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);