]> git.basschouten.com Git - openhab-addons.git/blob
1a4dfb32432e6e2ec6b6dcc9c649f89d32786723
[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.velux.internal.things;
14
15 import java.util.Map;
16 import java.util.function.Function;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.velux.internal.VeluxBindingConstants;
22
23 /**
24  * <B>Velux</B> product characteristics: Product Type.
25  * <P>
26  * See <a href=
27  * "https://velcdn.azureedge.net/~/media/com/api/klf200/technical%20specification%20for%20klf%20200%20api.pdf#page=112">KLF200
28  * List of actuator types and their use of Main Parameter and Functional Parameters</a>
29  * <P>
30  * Methods in handle this type of information:
31  * <UL>
32  * <LI>{@link #get(int)} to convert a value into the VeluxProductType.</LI>
33  * <LI>{@link #toString(int)} to convert a value into the description of the VeluxProductType.</LI>
34  * </UL>
35  *
36  * @see VeluxKLFAPI
37  *
38  * @author Guenther Schreiner - initial contribution.
39  */
40 @NonNullByDefault
41 public enum VeluxProductType {
42     SLIDER_SHUTTER,
43     SLIDER_WINDOW,
44     SWITCH,
45     UNDEFTYPE;
46
47     public enum ActuatorType {
48         UNDEFTYPE((short) 0xffff, VeluxBindingConstants.UNKNOWN, VeluxProductType.SWITCH),
49         BLIND_1_0((short) 0x0040, "Interior Venetian Blind", VeluxProductType.SLIDER_SHUTTER),
50         ROLLERSHUTTER_2_0((short) 0x0080, "Roller Shutter", VeluxProductType.SLIDER_SHUTTER),
51         ROLLERSHUTTER_2_1((short) 0x0081, "Roller Shutter", VeluxProductType.SLIDER_SHUTTER),
52         ROLLERSHUTTER_2_2((short) 0x0082, "Roller Shutter", VeluxProductType.SLIDER_SHUTTER),
53         AWNING_3_0((short) 0x00C0, "Vertical Exterior Awning", VeluxProductType.SLIDER_SHUTTER),
54         WINDOW_4_0((short) 0x0100, "Window opener", VeluxProductType.SLIDER_WINDOW),
55         WINDOW_4_1((short) 0x0101, "Window opener", VeluxProductType.SLIDER_WINDOW),
56         OPENER_5_0((short) 0x0140, "Garage door opener", VeluxProductType.SLIDER_SHUTTER),
57         OPENER_5_8((short) 0x017A, "Garage door opener", VeluxProductType.SLIDER_SHUTTER),
58         LIGHT_6_0((short) 0x0180, "Light", VeluxProductType.SLIDER_SHUTTER),
59         LIGHT_6_5((short) 0x01BA, "Light", VeluxProductType.SLIDER_SHUTTER),
60         OPENER_7_0((short) 0x01C0, "Gate opener", VeluxProductType.SLIDER_SHUTTER),
61         OPENER_7_5((short) 0x01FA, "Gate opener", VeluxProductType.SLIDER_SHUTTER),
62         LOCK_9_0((short) 0x0240, "Door lock", VeluxProductType.SLIDER_SHUTTER),
63         LOCK_9_1((short) 0x0241, "Window lock", VeluxProductType.SLIDER_SHUTTER),
64         BLIND_10((short) 0x0280, "Vertical Interior Blinds", VeluxProductType.SLIDER_SHUTTER),
65         SHUTTER_13((short) 0x0340, "Dual Roller Shutter", VeluxProductType.SLIDER_SHUTTER),
66         SWITCH_15((short) 0x03C0, "On/Off switch", VeluxProductType.SWITCH),
67         AWNING_16((short) 0x0400, "Horizontal awning", VeluxProductType.SLIDER_SHUTTER),
68         BLIND_17((short) 0x0440, "Exterior Venetian blind", VeluxProductType.SLIDER_SHUTTER),
69         BLIND_18((short) 0x0480, "Louver blind", VeluxProductType.SLIDER_SHUTTER),
70         TRACK_19((short) 0x04C0, "Curtain track", VeluxProductType.SLIDER_SHUTTER),
71         POINT_20((short) 0x0500, "Ventilation point", VeluxProductType.SLIDER_SHUTTER),
72         POINT_20_1((short) 0x0501, "Ventilation point", VeluxProductType.SLIDER_SHUTTER),
73         POINT_20_2((short) 0x0502, "Ventilation point", VeluxProductType.SLIDER_SHUTTER),
74         POINT_20_3((short) 0x0503, "Ventilation point", VeluxProductType.SLIDER_SHUTTER),
75         HEATING_21((short) 0x0540, "Exterior heating", VeluxProductType.SLIDER_SHUTTER),
76         HEATING_21_5((short) 0x57A, "Exterior heating", VeluxProductType.SLIDER_SHUTTER),
77         SHUTTER_24_0((short) 0x0600, "Swinging Shutters", VeluxProductType.SLIDER_SHUTTER),
78         SHUTTER_24_1((short) 0x0601, "Swinging Shutters", VeluxProductType.SLIDER_SHUTTER),;
79
80         // Class internal
81
82         private short nodeType;
83         private String description;
84         private VeluxProductType typeClass;
85
86         // Reverse-lookup map for getting an ActuatorType from a TypeId
87         private static final Map<Integer, ActuatorType> LOOKUPTYPEID2ENUM = Stream.of(ActuatorType.values())
88                 .collect(Collectors.toMap(ActuatorType::getNodeType, Function.identity()));
89
90         // Constructor
91
92         private ActuatorType(short nodeType, String description, VeluxProductType typeClass) {
93             this.nodeType = nodeType;
94             this.description = description;
95             this.typeClass = typeClass;
96         }
97
98         // Class access methods
99
100         public int getNodeType() {
101             return nodeType;
102         }
103
104         public String getDescription() {
105             return description;
106         }
107
108         public VeluxProductType getTypeClass() {
109             return typeClass;
110         }
111
112         public static ActuatorType get(int nodeType) {
113             return LOOKUPTYPEID2ENUM.getOrDefault(nodeType, ActuatorType.UNDEFTYPE);
114         }
115     }
116
117     // Class access methods
118
119     public static VeluxProductType get(int nodeType) {
120         if (ActuatorType.get(nodeType) != ActuatorType.UNDEFTYPE) {
121             return ActuatorType.get(nodeType).typeClass;
122         } else {
123             return VeluxProductType.UNDEFTYPE;
124         }
125     }
126
127     public static String toString(int nodeType) {
128         return ActuatorType.get(nodeType).getDescription();
129     }
130 }