]> git.basschouten.com Git - openhab-addons.git/blob
2e8fefed68d1767de4e3289c30985da7b253c7e7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.sonyprojector.internal.communication;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
19 import org.openhab.core.util.HexUtils;
20
21 /**
22  * Represents the different power status of the projector
23  *
24  * @author Markus Wehrle - Initial contribution
25  * @author Laurent Garnier - Transform into an enum
26  */
27 @NonNullByDefault
28 public enum SonyProjectorStatusPower {
29
30     STANDBY("Standby", new byte[] { 0x00, 0x00 }, false),
31     START_UP("Start Up", new byte[] { 0x00, 0x01 }, true),
32     STARTUP_LAMP("Sartup Lamp", new byte[] { 0x00, 0x02 }, true),
33     POWER_ON("Power On", new byte[] { 0x00, 0x03 }, true),
34     COOLING1("Cooling1", new byte[] { 0x00, 0x04 }, false),
35     COOLING2("Cooling1", new byte[] { 0x00, 0x05 }, false),
36     SAVING_COOLING1("Saving Cooling1", new byte[] { 0x00, 0x06 }, false),
37     SAVING_COOLING2("Saving Cooling2", new byte[] { 0x00, 0x07 }, false),
38     SAVING_STANDBY("Saving Standby", new byte[] { 0x00, 0x08 }, false);
39
40     private String name;
41     private byte[] dataCode;
42     private boolean on;
43
44     /**
45      * Constructor
46      *
47      * @param name the name of the power status
48      * @param dataCode the data code identifying the power status
49      * @param on the associated ON or OFF status of the power status
50      */
51     private SonyProjectorStatusPower(String name, byte[] dataCode, boolean on) {
52         this.name = name;
53         this.dataCode = dataCode;
54         this.on = on;
55     }
56
57     /**
58      * Get the data code identifying the current power status
59      *
60      * @return the data code
61      */
62     public byte[] getDataCode() {
63         return dataCode;
64     }
65
66     /**
67      * Get the name of the current power status
68      *
69      * @return the name
70      */
71     public String getName() {
72         return name;
73     }
74
75     /**
76      * Get the associated ON or OFF status of the current power status
77      *
78      * @return true if the current power status ios associated to an ON status
79      */
80     public boolean isOn() {
81         return on;
82     }
83
84     /**
85      * Get the power status associated to a data code
86      *
87      * @param dataCode the data code used to identify the power status
88      *
89      * @return the power status associated to the searched data code
90      *
91      * @throws SonyProjectorException - If no power status is associated to the searched data code
92      */
93     public static SonyProjectorStatusPower getFromDataCode(byte[] dataCode) throws SonyProjectorException {
94         for (SonyProjectorStatusPower value : SonyProjectorStatusPower.values()) {
95             if (Arrays.equals(dataCode, value.getDataCode())) {
96                 return value;
97             }
98         }
99         throw new SonyProjectorException("Invalid data code for a power status: " + HexUtils.bytesToHex(dataCode));
100     }
101 }