]> git.basschouten.com Git - openhab-addons.git/blob
e9a776cb996fdd580c0d36f43364c652f17c76b0
[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.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(new byte[] { 0x00, 0x00 }, false),
31     START_UP(new byte[] { 0x00, 0x01 }, true),
32     STARTUP_LAMP(new byte[] { 0x00, 0x02 }, true),
33     POWER_ON(new byte[] { 0x00, 0x03 }, true),
34     COOLING1(new byte[] { 0x00, 0x04 }, false),
35     COOLING2(new byte[] { 0x00, 0x05 }, false),
36     SAVING_COOLING1(new byte[] { 0x00, 0x06 }, false),
37     SAVING_COOLING2(new byte[] { 0x00, 0x07 }, false),
38     SAVING_STANDBY(new byte[] { 0x00, 0x08 }, false);
39
40     private byte[] dataCode;
41     private boolean on;
42
43     /**
44      * Constructor
45      *
46      * @param dataCode the data code identifying the power status
47      * @param on the associated ON or OFF status of the power status
48      */
49     private SonyProjectorStatusPower(byte[] dataCode, boolean on) {
50         this.dataCode = dataCode;
51         this.on = on;
52     }
53
54     /**
55      * Get the data code identifying the current power status
56      *
57      * @return the data code
58      */
59     public byte[] getDataCode() {
60         return dataCode;
61     }
62
63     /**
64      * Get the associated ON or OFF status of the current power status
65      *
66      * @return true if the current power status ios associated to an ON status
67      */
68     public boolean isOn() {
69         return on;
70     }
71
72     /**
73      * Get the power status associated to a data code
74      *
75      * @param dataCode the data code used to identify the power status
76      *
77      * @return the power status associated to the searched data code
78      *
79      * @throws SonyProjectorException - If no power status is associated to the searched data code
80      */
81     public static SonyProjectorStatusPower getFromDataCode(byte[] dataCode) throws SonyProjectorException {
82         for (SonyProjectorStatusPower value : SonyProjectorStatusPower.values()) {
83             if (Arrays.equals(dataCode, value.getDataCode())) {
84                 return value;
85             }
86         }
87         throw new SonyProjectorException("Invalid data code for a power status: " + HexUtils.bytesToHex(dataCode));
88     }
89 }