2 * Copyright (c) 2010-2023 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(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);
40 private byte[] dataCode;
46 * @param dataCode the data code identifying the power status
47 * @param on the associated ON or OFF status of the power status
49 private SonyProjectorStatusPower(byte[] dataCode, boolean on) {
50 this.dataCode = dataCode;
55 * Get the data code identifying the current power status
57 * @return the data code
59 public byte[] getDataCode() {
64 * Get the associated ON or OFF status of the current power status
66 * @return true if the current power status ios associated to an ON status
68 public boolean isOn() {
73 * Get the power status associated to a data code
75 * @param dataCode the data code used to identify the power status
77 * @return the power status associated to the searched data code
79 * @throws SonyProjectorException - If no power status is associated to the searched data code
81 public static SonyProjectorStatusPower getFromDataCode(byte[] dataCode) throws SonyProjectorException {
82 for (SonyProjectorStatusPower value : SonyProjectorStatusPower.values()) {
83 if (Arrays.equals(dataCode, value.getDataCode())) {
87 throw new SonyProjectorException("Invalid data code for a power status: " + HexUtils.bytesToHex(dataCode));