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