]> git.basschouten.com Git - openhab-addons.git/blob
5739e34fc22bd76464c2fe49e7b9edc242b0bba5
[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 picture positions available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorPicturePosition {
31
32     // Category 1: VW385, VW500, VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885,
33     // VW995, VW1000ES, VW1100ES
34     CAT1_185(1, "185", new byte[] { 0x00, 0x00 }),
35     CAT1_235(1, "235", new byte[] { 0x00, 0x01 }),
36     CAT1_CUSTOM1(1, "Custom1", new byte[] { 0x00, 0x02 }),
37     CAT1_CUSTOM2(1, "Custom2", new byte[] { 0x00, 0x03 }),
38     CAT1_CUSTOM3(1, "Custom3", new byte[] { 0x00, 0x04 }),
39
40     // Category 2: VW95
41     CAT2_POSITION1(2, "Position1", new byte[] { 0x00, 0x00 }),
42     CAT2_POSITION2(2, "Position2", new byte[] { 0x00, 0x01 }),
43     CAT2_POSITION3(2, "Position3", new byte[] { 0x00, 0x02 }),
44     CAT2_POSITION4(2, "Position4", new byte[] { 0x00, 0x03 }),
45     CAT2_POSITION5(2, "Position5", new byte[] { 0x00, 0x04 });
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 picture position is available
55      * @param name the name of the picture position
56      * @param dataCode the data code identifying the picture position
57      */
58     private SonyProjectorPicturePosition(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 picture position
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 picture position
75      *
76      * @return the data code
77      */
78     public byte[] getDataCode() {
79         return dataCode;
80     }
81
82     /**
83      * Get the name of the current picture position
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 picture positions for a particular category of
93      * projector models
94      *
95      * @param category a category of projector models
96      *
97      * @return the list of {@link StateOption} associated to the available picture positions 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 (SonyProjectorPicturePosition value : SonyProjectorPicturePosition.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 picture position 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 picture position
115      *
116      * @return the picture position associated to the searched name for the provided category of projector models
117      *
118      * @throws SonyProjectorException - If no picture position is associated to the searched name for the provided
119      *             category
120      */
121     public static SonyProjectorPicturePosition getFromName(int category, String name) throws SonyProjectorException {
122         for (SonyProjectorPicturePosition value : SonyProjectorPicturePosition.values()) {
123             if (value.getCategory() == category && value.getName().equals(name)) {
124                 return value;
125             }
126         }
127         throw new SonyProjectorException("Invalid name for a picture position: " + name);
128     }
129
130     /**
131      * Get the picture position 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 picture position
135      *
136      * @return the picture position associated to the searched data code for the provided category of projector models
137      *
138      * @throws SonyProjectorException - If no picture position is associated to the searched data code for the provided
139      *             category
140      */
141     public static SonyProjectorPicturePosition getFromDataCode(int category, byte[] dataCode)
142             throws SonyProjectorException {
143         for (SonyProjectorPicturePosition value : SonyProjectorPicturePosition.values()) {
144             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
145                 return value;
146             }
147         }
148         throw new SonyProjectorException("Invalid data code for a picture position: " + HexUtils.bytesToHex(dataCode));
149     }
150 }