]> git.basschouten.com Git - openhab-addons.git/blob
04d7bb7d0f2dc6d415799b9576ddb82476d9e12f
[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.heos.internal.json.dto;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Tuple to contain a command group and command enum, this represents the full command send to / received by the HEOS
22  * cli
23  *
24  * @author Martin van Wingerden - Initial contribution
25  */
26 @NonNullByDefault
27 public class HeosCommandTuple {
28     private static final Logger LOGGER = LoggerFactory.getLogger(HeosCommandTuple.class);
29
30     public final HeosCommandGroup commandGroup;
31     public final HeosCommand command;
32
33     public HeosCommandTuple(HeosCommandGroup commandGroup, HeosCommand command) {
34         this.commandGroup = commandGroup;
35         this.command = command;
36     }
37
38     @Nullable
39     public static HeosCommandTuple valueOf(String commandString) {
40         String[] split = commandString.split("/");
41
42         if (split.length != 2) {
43             return null;
44         }
45
46         try {
47             HeosCommandGroup group = HeosCommandGroup.valueOf(split[0].toUpperCase());
48             HeosCommand cmd = HeosCommand.valueOf(split[1].toUpperCase());
49             return new HeosCommandTuple(group, cmd);
50         } catch (IllegalArgumentException e) {
51             LOGGER.debug("Unsupported command {}", commandString);
52             return null;
53         }
54     }
55
56     @Override
57     public String toString() {
58         return commandGroup + "/" + command;
59     }
60 }