]> git.basschouten.com Git - openhab-addons.git/blob
14acf01667f72efc1ff2ced405d1cacdc7e25177
[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 iris modes available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorIrisMode {
31
32     // Category 1: VW385, VW500, VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885,
33     // VW995, HW60, HW65, HW68
34     CAT1_FULL(1, "Full", new byte[] { 0x00, 0x02 }),
35     CAT1_LIMITED(1, "Limited", new byte[] { 0x00, 0x03 }),
36     CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
37
38     // Category 2: VW40, VW50, VW60
39     CAT2_ON(2, "On", new byte[] { 0x00, 0x01 }),
40     CAT2_AUTO1(2, "Auto1", new byte[] { 0x00, 0x02 }),
41     CAT2_AUTO2(2, "Auto2", new byte[] { 0x00, 0x03 }),
42     CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 }),
43
44     // Category 3: VW70, VW80, VW85, VW90, VW95, VW200, HW10, HW15, HW20, HW30ES
45     CAT3_AUTO1(3, "Auto1", new byte[] { 0x00, 0x02 }),
46     CAT3_AUTO2(3, "Auto2", new byte[] { 0x00, 0x03 }),
47     CAT3_MANUAL(3, "Manual", new byte[] { 0x00, 0x01 }),
48     CAT3_OFF(3, "Off", new byte[] { 0x00, 0x00 }),
49
50     // Category 4: VW100
51     CAT4_ON(4, "On", new byte[] { 0x00, 0x01 }),
52     CAT4_AUTO(4, "Auto", new byte[] { 0x00, 0x02 }),
53     CAT4_OFF(4, "Off", new byte[] { 0x00, 0x00 }),
54
55     // Category 5: VW1000ES, VW1100ES, HW50ES, HW55ES
56     CAT5_AUTO_FULL(5, "AutoFull", new byte[] { 0x00, 0x02 }),
57     CAT5_AUTO_LIMITED(5, "AutoLimited", new byte[] { 0x00, 0x03 }),
58     CAT5_MANUAL(5, "Manual", new byte[] { 0x00, 0x01 }),
59     CAT5_OFF(5, "Off", new byte[] { 0x00, 0x00 });
60
61     private int category;
62     private String name;
63     private byte[] dataCode;
64
65     /**
66      * Constructor
67      *
68      * @param category a category of projector models for which the iris mode is available
69      * @param name the name of the iris mode
70      * @param dataCode the data code identifying the iris mode
71      */
72     private SonyProjectorIrisMode(int category, String name, byte[] dataCode) {
73         this.category = category;
74         this.name = name;
75         this.dataCode = dataCode;
76     }
77
78     /**
79      * Get the category of projector models for the current iris mode
80      *
81      * @return the category of projector models
82      */
83     public int getCategory() {
84         return category;
85     }
86
87     /**
88      * Get the data code identifying the current iris mode
89      *
90      * @return the data code
91      */
92     public byte[] getDataCode() {
93         return dataCode;
94     }
95
96     /**
97      * Get the name of the current iris mode
98      *
99      * @return the name
100      */
101     public String getName() {
102         return name;
103     }
104
105     /**
106      * Get the list of {@link StateOption} associated to the available iris modes for a particular category of projector
107      * models
108      *
109      * @param category a category of projector models
110      *
111      * @return the list of {@link StateOption} associated to the available iris modes for a provided category of
112      *         projector models
113      */
114     public static List<StateOption> getStateOptions(int category) {
115         List<StateOption> options = new ArrayList<>();
116         for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
117             if (value.getCategory() == category) {
118                 options.add(new StateOption(value.getName(), value.getName()));
119             }
120         }
121         return options;
122     }
123
124     /**
125      * Get the iris mode associated to a name for a particular category of projector models
126      *
127      * @param category a category of projector models
128      * @param name the name used to identify the iris mode
129      *
130      * @return the iris mode associated to the searched name for the provided category of projector models
131      *
132      * @throws SonyProjectorException - If no iris mode is associated to the searched name for the provided category
133      */
134     public static SonyProjectorIrisMode getFromName(int category, String name) throws SonyProjectorException {
135         for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
136             if (value.getCategory() == category && value.getName().equals(name)) {
137                 return value;
138             }
139         }
140         throw new SonyProjectorException("Invalid name for an iris mode: " + name);
141     }
142
143     /**
144      * Get the iris mode associated to a data code for a particular category of projector models
145      *
146      * @param category a category of projector models
147      * @param dataCode the data code used to identify the iris mode
148      *
149      * @return the iris mode associated to the searched data code for the provided category of projector models
150      *
151      * @throws SonyProjectorException - If no iris mode is associated to the searched data code for the provided
152      *             category
153      */
154     public static SonyProjectorIrisMode getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
155         for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
156             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
157                 return value;
158             }
159         }
160         throw new SonyProjectorException("Invalid data code for an iris mode: " + HexUtils.bytesToHex(dataCode));
161     }
162 }