]> git.basschouten.com Git - openhab-addons.git/blob
07276274483f4909c01dfdcc3c735042f36ca398
[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.pioneeravr.internal.protocol;
14
15 import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrCommand;
16
17 /**
18  * A simple command without parameters.
19  *
20  * @author Antoine Besnard - Initial contribution
21  * @author Leroy Foerster - Listening Mode, Playing Listening Mode
22  */
23 public class SimpleCommand implements AvrCommand {
24
25     /**
26      * List of the simple command types.
27      */
28     public enum SimpleCommandType implements AvrCommand.CommandType {
29
30         POWER_ON("PO", "APO", "BPO", "ZEO"),
31         POWER_OFF("PF", "APF", "BPF", "ZEF"),
32         POWER_QUERY("?P", "?AP", "?BP", "?ZEP"),
33         VOLUME_UP("VU", "ZU", "YU", "HZU"),
34         VOLUME_DOWN("VD", "ZD", "YD", "HZD"),
35         VOLUME_QUERY("?V", "?ZV", "?YV", "?HZV"),
36         MUTE_ON("MO", "Z2MO", "Z3MO", "HZMO"),
37         MUTE_OFF("MF", "Z2MF", "Z3MF", "HZMF"),
38         MUTE_QUERY("?M", "?Z2M", "?Z3M", "?HZM"),
39         INPUT_CHANGE_CYCLIC("FU"),
40         INPUT_CHANGE_REVERSE("FD"),
41         LISTENING_MODE_CHANGE_CYCLIC("0010SR"),
42         LISTENING_MODE_QUERY("?S"),
43         INPUT_QUERY("?F", "?ZS", "?ZT", "?ZEA"),
44         MCACC_MEMORY_CHANGE_CYCLIC("0MC"),
45         MCACC_MEMORY_QUERY("?MC");
46
47         private String zoneCommands[];
48
49         private SimpleCommandType(String... command) {
50             this.zoneCommands = command;
51         }
52
53         @Override
54         public String getCommand() {
55             return zoneCommands[0];
56         }
57
58         @Override
59         public String getCommand(int zone) {
60             return zoneCommands[zone - 1];
61         }
62     }
63
64     private CommandType commandType;
65     private int zone;
66
67     public SimpleCommand(CommandType commandType, int zone) {
68         this.commandType = commandType;
69         this.zone = zone;
70     }
71
72     public SimpleCommand(CommandType commandType) {
73         this(commandType, 0);
74     }
75
76     @Override
77     public String getCommand() {
78         if (zone == 0) {
79             return commandType.getCommand() + "\r";
80         }
81         return commandType.getCommand(zone) + "\r";
82     }
83
84     @Override
85     public CommandType getCommandType() {
86         return commandType;
87     }
88
89     @Override
90     public int getZone() {
91         return zone;
92     }
93 }