2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sonyprojector.internal.communication;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
19 import org.openhab.core.util.HexUtils;
22 * Represents the different power status of the projector
24 * @author Markus Wehrle - Initial contribution
25 * @author Laurent Garnier - Transform into an enum
28 public enum SonyProjectorStatusPower {
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);
41 private byte[] dataCode;
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
51 private SonyProjectorStatusPower(String name, byte[] dataCode, boolean on) {
53 this.dataCode = dataCode;
58 * Get the data code identifying the current power status
60 * @return the data code
62 public byte[] getDataCode() {
67 * Get the name of the current power status
71 public String getName() {
76 * Get the associated ON or OFF status of the current power status
78 * @return true if the current power status ios associated to an ON status
80 public boolean isOn() {
85 * Get the power status associated to a data code
87 * @param dataCode the data code used to identify the power status
89 * @return the power status associated to the searched data code
91 * @throws SonyProjectorException - If no power status is associated to the searched data code
93 public static SonyProjectorStatusPower getFromDataCode(byte[] dataCode) throws SonyProjectorException {
94 for (SonyProjectorStatusPower value : SonyProjectorStatusPower.values()) {
95 if (Arrays.equals(dataCode, value.getDataCode())) {
99 throw new SonyProjectorException("Invalid data code for a power status: " + HexUtils.bytesToHex(dataCode));