]> git.basschouten.com Git - openhab-addons.git/blob
67110732d908aa3ebe3b46f6a9b43c6a8838fbf0
[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.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
21 import org.openhab.core.types.StateOption;
22 import org.openhab.core.util.HexUtils;
23
24 /**
25  * Represents the different MPEG noise reduction modes available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorMpegNr {
31
32     // Category 1: VW260, VW270, VW285, VW295, VW315, VW320, VW328, VW365, VW>385, VW500, VW515, VW520, VW528, VW550,
33     // VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW60, HW65, HW68
34     CAT1_AUTO(1, "Auto", new byte[] { 0x00, 0x04 }),
35     CAT1_HIGH(1, "High", new byte[] { 0x00, 0x03 }),
36     CAT1_MIDDLE(1, "Middle", new byte[] { 0x00, 0x02 }),
37     CAT1_LOW(1, "Low", new byte[] { 0x00, 0x01 }),
38     CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
39
40     // Category 2: HW35ES, HW40ES, HW45ES, HW50ES, HW55ES, HW58ES
41     CAT2_HIGH(2, "High", new byte[] { 0x00, 0x03 }),
42     CAT2_MIDDLE(2, "Middle", new byte[] { 0x00, 0x02 }),
43     CAT2_LOW(2, "Low", new byte[] { 0x00, 0x01 }),
44     CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 });
45
46     private int category;
47     private String name;
48     private byte[] dataCode;
49
50     /**
51      * Constructor
52      *
53      * @param category a category of projector models for which the MPEG noise reduction mode is available
54      * @param name the name of the MPEG noise reduction mode
55      * @param dataCode the data code identifying the MPEG noise reduction mode
56      */
57     private SonyProjectorMpegNr(int category, String name, byte[] dataCode) {
58         this.category = category;
59         this.name = name;
60         this.dataCode = dataCode;
61     }
62
63     /**
64      * Get the category of projector models for the current MPEG noise reduction mode
65      *
66      * @return the category of projector models
67      */
68     public int getCategory() {
69         return category;
70     }
71
72     /**
73      * Get the data code identifying the current MPEG noise reduction mode
74      *
75      * @return the data code
76      */
77     public byte[] getDataCode() {
78         return dataCode;
79     }
80
81     /**
82      * Get the name of the current MPEG noise reduction mode
83      *
84      * @return the name
85      */
86     public String getName() {
87         return name;
88     }
89
90     /**
91      * Get the list of {@link StateOption} associated to the available MPEG noise reduction modes for a particular
92      * category of projector models
93      *
94      * @param category a category of projector models
95      *
96      * @return the list of {@link StateOption} associated to the available MPEG noise reduction modes for a provided
97      *         category of projector models
98      */
99     public static List<StateOption> getStateOptions(int category) {
100         List<StateOption> options = new ArrayList<>();
101         for (SonyProjectorMpegNr value : SonyProjectorMpegNr.values()) {
102             if (value.getCategory() == category) {
103                 options.add(new StateOption(value.getName(), value.getName()));
104             }
105         }
106         return options;
107     }
108
109     /**
110      * Get the MPEG noise reduction mode associated to a name for a particular category of projector models
111      *
112      * @param category a category of projector models
113      * @param name the name used to identify the MPEG noise reduction mode
114      *
115      * @return the MPEG noise reduction mode associated to the searched name for the provided category of projector
116      *         models
117      *
118      * @throws SonyProjectorException - If no MPEG noise reduction mode is associated to the searched name for the
119      *             provided category
120      */
121     public static SonyProjectorMpegNr getFromName(int category, String name) throws SonyProjectorException {
122         for (SonyProjectorMpegNr value : SonyProjectorMpegNr.values()) {
123             if (value.getCategory() == category && value.getName().equals(name)) {
124                 return value;
125             }
126         }
127         throw new SonyProjectorException("Invalid name for a MPEG noise reduction mode: " + name);
128     }
129
130     /**
131      * Get the MPEG noise reduction mode associated to a data code for a particular category of projector models
132      *
133      * @param category a category of projector models
134      * @param dataCode the data code used to identify the MPEG noise reduction mode
135      *
136      * @return the MPEG noise reduction mode associated to the searched data code for the provided category of projector
137      *         models
138      *
139      * @throws SonyProjectorException - If no MPEG noise reduction mode is associated to the searched data code for the
140      *             provided category
141      */
142     public static SonyProjectorMpegNr getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
143         for (SonyProjectorMpegNr value : SonyProjectorMpegNr.values()) {
144             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
145                 return value;
146             }
147         }
148         throw new SonyProjectorException(
149                 "Invalid data code for a MPEG noise reduction mode: " + HexUtils.bytesToHex(dataCode));
150     }
151 }