]> git.basschouten.com Git - openhab-addons.git/blob
d440af63fa3e468e616a9cbb0e1e38707f947673
[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 video inputs available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorInput {
31
32     // Category 1: VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515, VW520,
33     // VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW45ES, HW60, HW65, HW68
34     CAT1_HDMI1(1, "HDMI1", new byte[] { 0x00, 0x02 }),
35     CAT1_HDMI2(1, "HDMI2", new byte[] { 0x00, 0x03 }),
36
37     // Category 2: VW40, VW50, VW60, VW70, VW80, VW85, VW200, HW10, HW15, HW20
38     CAT2_VIDEO(2, "Video", new byte[] { 0x00, 0x00 }),
39     CAT2_SVIDEO(2, "SVideo", new byte[] { 0x00, 0x01 }),
40     CAT2_INPUT_A(2, "InputA", new byte[] { 0x00, 0x02 }),
41     CAT2_COMPONENT(2, "Component", new byte[] { 0x00, 0x03 }),
42     CAT2_HDMI1(2, "HDMI1", new byte[] { 0x00, 0x04 }),
43     CAT2_HDMI2(2, "HDMI2", new byte[] { 0x00, 0x05 }),
44
45     // Category 3: VW95, VW1000ES, VW1100ES, HW30ES, HW40ES, HW50ES, HW55ES, HW58ES
46     CAT3_INPUT_A(3, "InputA", new byte[] { 0x00, 0x02 }),
47     CAT3_COMPONENT(3, "Component", new byte[] { 0x00, 0x03 }),
48     CAT3_HDMI1(3, "HDMI1", new byte[] { 0x00, 0x04 }),
49     CAT3_HDMI2(3, "HDMI2", new byte[] { 0x00, 0x05 }),
50
51     // Category 4: VW100
52     CAT4_VIDEO(4, "Video", new byte[] { 0x00, 0x00 }),
53     CAT4_SVIDEO(4, "SVideo", new byte[] { 0x00, 0x01 }),
54     CAT4_INPUT_A(4, "InputA", new byte[] { 0x00, 0x02 }),
55     CAT4_COMPONENT(4, "Component", new byte[] { 0x00, 0x03 }),
56     CAT4_HDMI(4, "HDMI", new byte[] { 0x00, 0x04 }),
57     CAT4_DVI(4, "DVI", new byte[] { 0x00, 0x05 }),
58
59     // Category 5: VW90
60     CAT5_VIDEO(5, "Video", new byte[] { 0x00, 0x00 }),
61     CAT5_INPUT_A(5, "InputA", new byte[] { 0x00, 0x02 }),
62     CAT5_COMPONENT(5, "Component", new byte[] { 0x00, 0x03 }),
63     CAT5_HDMI1(5, "HDMI1", new byte[] { 0x00, 0x04 }),
64     CAT5_HDMI2(5, "HDMI2", new byte[] { 0x00, 0x05 });
65
66     private int category;
67     private String name;
68     private byte[] dataCode;
69
70     /**
71      * Constructor
72      *
73      * @param category a category of projector models for which the video input is available
74      * @param name the name of the video input
75      * @param dataCode the data code identifying the video input
76      */
77     private SonyProjectorInput(int category, String name, byte[] dataCode) {
78         this.category = category;
79         this.name = name;
80         this.dataCode = dataCode;
81     }
82
83     /**
84      * Get the category of projector models for the current video input
85      *
86      * @return the category of projector models
87      */
88     public int getCategory() {
89         return category;
90     }
91
92     /**
93      * Get the data code identifying the current video input
94      *
95      * @return the data code
96      */
97     public byte[] getDataCode() {
98         return dataCode;
99     }
100
101     /**
102      * Get the name of the current video input
103      *
104      * @return the name
105      */
106     public String getName() {
107         return name;
108     }
109
110     /**
111      * Get the list of {@link StateOption} associated to the available video inputs for a particular category of
112      * projector models
113      *
114      * @param category a category of projector models
115      *
116      * @return the list of {@link StateOption} associated to the available video inputs for a provided category of
117      *         projector models
118      */
119     public static List<StateOption> getStateOptions(int category) {
120         List<StateOption> options = new ArrayList<>();
121         for (SonyProjectorInput value : SonyProjectorInput.values()) {
122             if (value.getCategory() == category) {
123                 options.add(new StateOption(value.getName(), value.getName()));
124             }
125         }
126         return options;
127     }
128
129     /**
130      * Get the video input associated to a name for a particular category of projector models
131      *
132      * @param category a category of projector models
133      * @param name the name used to identify the video input
134      *
135      * @return the video input associated to the searched name for the provided category of projector models
136      *
137      * @throws SonyProjectorException - If no video input is associated to the searched name for the provided category
138      */
139     public static SonyProjectorInput getFromName(int category, String name) throws SonyProjectorException {
140         for (SonyProjectorInput value : SonyProjectorInput.values()) {
141             if (value.getCategory() == category && value.getName().equals(name)) {
142                 return value;
143             }
144         }
145         throw new SonyProjectorException("Invalid name for a video input: " + name);
146     }
147
148     /**
149      * Get the video input associated to a data code for a particular category of projector models
150      *
151      * @param category a category of projector models
152      * @param dataCode the data code used to identify the video input
153      *
154      * @return the video input associated to the searched data code for the provided category of projector models
155      *
156      * @throws SonyProjectorException - If no video input is associated to the searched data code for the provided
157      *             category
158      */
159     public static SonyProjectorInput getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
160         for (SonyProjectorInput value : SonyProjectorInput.values()) {
161             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
162                 return value;
163             }
164         }
165         throw new SonyProjectorException("Invalid data code for a video input: " + HexUtils.bytesToHex(dataCode));
166     }
167 }