]> git.basschouten.com Git - openhab-addons.git/blob
ed1797912115d622f64766ac1ea834d2b70d37f8
[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.anthem.internal.handler;
14
15 import static org.openhab.binding.anthem.internal.AnthemBindingConstants.COMMAND_TERMINATION_CHAR;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link AnthemCommend} is responsible for creating commands to be sent to the
21  * Anthem processor.
22  *
23  * @author Mark Hilbush - Initial contribution
24  */
25 @NonNullByDefault
26 public class AnthemCommand {
27     private static final String COMMAND_TERMINATOR = String.valueOf(COMMAND_TERMINATION_CHAR);
28
29     private String command = "";
30
31     public AnthemCommand(String command) {
32         this.command = command;
33     }
34
35     public static AnthemCommand powerOn(Zone zone) {
36         return new AnthemCommand(String.format("Z%sPOW1", zone.getValue()));
37     }
38
39     public static AnthemCommand powerOff(Zone zone) {
40         return new AnthemCommand(String.format("Z%sPOW0", zone.getValue()));
41     }
42
43     public static AnthemCommand volumeUp(Zone zone, int amount) {
44         return new AnthemCommand(String.format("Z%sVUP%02d", zone.getValue(), amount));
45     }
46
47     public static AnthemCommand volumeDown(Zone zone, int amount) {
48         return new AnthemCommand(String.format("Z%sVDN%02d", zone.getValue(), amount));
49     }
50
51     public static AnthemCommand volume(Zone zone, int level) {
52         return new AnthemCommand(String.format("Z%sVOL%02d", zone.getValue(), level));
53     }
54
55     public static AnthemCommand muteOn(Zone zone) {
56         return new AnthemCommand(String.format("Z%sMUT1", zone.getValue()));
57     }
58
59     public static AnthemCommand muteOff(Zone zone) {
60         return new AnthemCommand(String.format("Z%sMUT0", zone.getValue()));
61     }
62
63     public static AnthemCommand activeInput(Zone zone, int input) {
64         return new AnthemCommand(String.format("Z%sINP%02d", zone.getValue(), input));
65     }
66
67     public static AnthemCommand queryPower(Zone zone) {
68         return new AnthemCommand(String.format("Z%sPOW?", zone.getValue()));
69     }
70
71     public static AnthemCommand queryVolume(Zone zone) {
72         return new AnthemCommand(String.format("Z%sVOL?", zone.getValue()));
73     }
74
75     public static AnthemCommand queryMute(Zone zone) {
76         return new AnthemCommand(String.format("Z%sMUT?", zone.getValue()));
77     }
78
79     public static AnthemCommand queryActiveInput(Zone zone) {
80         return new AnthemCommand(String.format("Z%sINP?", zone.getValue()));
81     }
82
83     public static AnthemCommand queryNumAvailableInputs() {
84         return new AnthemCommand(String.format("ICN?"));
85     }
86
87     public static AnthemCommand queryInputShortName(int input) {
88         return new AnthemCommand(String.format("ISN%02d?", input));
89     }
90
91     public static AnthemCommand queryInputLongName(int input) {
92         return new AnthemCommand(String.format("ILN%02d?", input));
93     }
94
95     public static AnthemCommand queryModel() {
96         return new AnthemCommand("IDM?");
97     }
98
99     public static AnthemCommand queryRegion() {
100         return new AnthemCommand("IDR?");
101     }
102
103     public static AnthemCommand querySoftwareVersion() {
104         return new AnthemCommand("IDS?");
105     }
106
107     public static AnthemCommand querySoftwareBuildDate() {
108         return new AnthemCommand("IDB?");
109     }
110
111     public static AnthemCommand queryHardwareVersion() {
112         return new AnthemCommand("IDH?");
113     }
114
115     public static AnthemCommand queryMacAddress() {
116         return new AnthemCommand("IDN?");
117     }
118
119     public String getCommand() {
120         return command + COMMAND_TERMINATOR;
121     }
122
123     @Override
124     public String toString() {
125         return getCommand();
126     }
127 }