]> git.basschouten.com Git - openhab-addons.git/blob
f28a8d1fdd1332fc811a0cbda46feb9a8e2af188
[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.fineoffsetweatherstation.internal.domain;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.BatteryStatus;
23
24 /**
25  * The binding of a sensor to the gateway.
26  *
27  * @author Andreas Berger - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SensorGatewayBinding {
31     /**
32      * wh24 + wh65 share the same id, they are distinguished by user set flag, see also {@link Command#CMD_READ_SSSS}
33      */
34     WH24((byte) 0, Sensor.WH24, null),
35     WH65((byte) 0, Sensor.WH65, null),
36     // also wh69
37     WH68((byte) 1, Sensor.WH68, null),
38     WH80((byte) 2, Sensor.WH80, null),
39     WH40((byte) 3, Sensor.WH40, null),
40     WH25((byte) 4, Sensor.WH25, null),
41     WH26((byte) 5, Sensor.WH26, null),
42     WH31_CH1((byte) 6, Sensor.WH31, 1),
43     WH31_CH2((byte) 7, Sensor.WH31, 2),
44     WH31_CH3((byte) 8, Sensor.WH31, 3),
45     WH31_CH4((byte) 9, Sensor.WH31, 4),
46     WH31_CH5((byte) 10, Sensor.WH31, 5),
47     WH31_CH6((byte) 11, Sensor.WH31, 6),
48     WH31_CH7((byte) 12, Sensor.WH31, 7),
49     WH31_CH8((byte) 13, Sensor.WH31, 8),
50     WH51_CH1((byte) 14, Sensor.WH51, 1),
51     WH51_CH2((byte) 15, Sensor.WH51, 2),
52     WH51_CH3((byte) 16, Sensor.WH51, 3),
53     WH51_CH4((byte) 17, Sensor.WH51, 4),
54     WH51_CH5((byte) 18, Sensor.WH51, 5),
55     WH51_CH6((byte) 19, Sensor.WH51, 6),
56     WH51_CH7((byte) 20, Sensor.WH51, 7),
57     WH51_CH8((byte) 21, Sensor.WH51, 8),
58     WH41_CH1((byte) 22, Sensor.WH41, 1),
59     WH41_CH2((byte) 23, Sensor.WH41, 2),
60     WH41_CH3((byte) 24, Sensor.WH41, 3),
61     WH41_CH4((byte) 25, Sensor.WH41, 4),
62     WH57((byte) 26, Sensor.WH57, null),
63     WH55_CH1((byte) 27, Sensor.WH55, 1),
64     WH55_CH2((byte) 28, Sensor.WH55, 2),
65     WH55_CH3((byte) 29, Sensor.WH55, 3),
66     WH55_CH4((byte) 30, Sensor.WH55, 4),
67     WH34_CH1((byte) 31, Sensor.WH34, 1),
68     WH34_CH2((byte) 32, Sensor.WH34, 2),
69     WH34_CH3((byte) 33, Sensor.WH34, 3),
70     WH34_CH4((byte) 34, Sensor.WH34, 4),
71     WH34_CH5((byte) 35, Sensor.WH34, 5),
72     WH34_CH6((byte) 36, Sensor.WH34, 6),
73     WH34_CH7((byte) 37, Sensor.WH34, 7),
74     WH34_CH8((byte) 38, Sensor.WH34, 8),
75     WH45((byte) 39, Sensor.WH45, null),
76     WH35_CH1((byte) 40, Sensor.WH35, 1),
77     WH35_CH2((byte) 41, Sensor.WH35, 2),
78     WH35_CH3((byte) 42, Sensor.WH35, 3),
79     WH35_CH4((byte) 43, Sensor.WH35, 4),
80     WH35_CH5((byte) 44, Sensor.WH35, 5),
81     WH35_CH6((byte) 45, Sensor.WH35, 6),
82     WH35_CH7((byte) 46, Sensor.WH35, 7),
83     WH35_CH8((byte) 47, Sensor.WH35, 8),
84     WH90((byte) 48, Sensor.WH90, null);
85
86     private static final Map<Byte, List<SensorGatewayBinding>> SENSOR_LOOKUP = new HashMap<>();
87
88     static {
89         for (SensorGatewayBinding sensorGatewayBinding : values()) {
90             List<SensorGatewayBinding> bindings = SENSOR_LOOKUP.computeIfAbsent(sensorGatewayBinding.id,
91                     ArrayList::new);
92             // noinspection ConstantConditions
93             if (bindings != null) {
94                 bindings.add(sensorGatewayBinding);
95             }
96         }
97     }
98
99     private final byte id;
100     private final Sensor sensor;
101     private final @Nullable Integer channel;
102
103     SensorGatewayBinding(byte id, Sensor sensor, @Nullable Integer channel) {
104         this.id = id;
105         this.sensor = sensor;
106         this.channel = channel;
107     }
108
109     public static @Nullable List<SensorGatewayBinding> forIndex(byte idx) {
110         return SENSOR_LOOKUP.get(idx);
111     }
112
113     public BatteryStatus getBatteryStatus(byte data) {
114         return sensor.getBatteryStatus(data);
115     }
116
117     public Sensor getSensor() {
118         return sensor;
119     }
120
121     public @Nullable Integer getChannel() {
122         return channel;
123     }
124 }