]> git.basschouten.com Git - openhab-addons.git/blob
fff9ce7d380ecd288d4b1c12913f82507c6212dd
[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.pjlinkdevice.internal.device.command.power;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.pjlinkdevice.internal.device.command.PrefixedResponse;
17 import org.openhab.binding.pjlinkdevice.internal.device.command.ResponseException;
18
19 /**
20  * The response part of {@link PowerQueryCommand}
21  *
22  * @author Nils Schnabel - Initial contribution
23  */
24 @NonNullByDefault
25 public class PowerQueryResponse extends PrefixedResponse<PowerQueryResponse.PowerQueryResponseValue> {
26     public enum PowerQueryResponseValue {
27         STAND_BY("Stand-by", "0"),
28         POWER_ON("Power on", "1"),
29         COOLING_DOWN("Cooling down", "2"),
30         WARMING_UP("Warming up", "3");
31
32         private String text;
33         private String code;
34
35         private PowerQueryResponseValue(String text, String code) {
36             this.text = text;
37             this.code = code;
38         }
39
40         public String getText() {
41             return this.text;
42         }
43
44         public static PowerQueryResponseValue parseString(String code) throws ResponseException {
45             for (PowerQueryResponseValue result : PowerQueryResponseValue.values()) {
46                 if (result.code.equals(code)) {
47                     return result;
48                 }
49             }
50
51             throw new ResponseException("Cannot understand power status: " + code);
52         }
53     }
54
55     public PowerQueryResponse(String response) throws ResponseException {
56         super("POWR=", response);
57     }
58
59     @Override
60     protected PowerQueryResponseValue parseResponseWithoutPrefix(String responseWithoutPrefix)
61             throws ResponseException {
62         return PowerQueryResponseValue.parseString(responseWithoutPrefix);
63     }
64 }