2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.fineoffsetweatherstation.internal.domain;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.BatteryStatus;
25 * The binding of a sensor to the gateway.
27 * @author Andreas Berger - Initial contribution
30 public enum SensorGatewayBinding {
32 * wh24 + wh65 share the same id, they are distinguished by user set flag, see also {@link Command#CMD_READ_SSSS}
34 WH24((byte) 0, Sensor.WH24, null),
35 WH65((byte) 0, Sensor.WH65, null),
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);
86 private static final Map<Byte, List<SensorGatewayBinding>> SENSOR_LOOKUP = new HashMap<>();
89 for (SensorGatewayBinding sensorGatewayBinding : values()) {
90 List<SensorGatewayBinding> bindings = SENSOR_LOOKUP.computeIfAbsent(sensorGatewayBinding.id,
92 // noinspection ConstantConditions
93 if (bindings != null) {
94 bindings.add(sensorGatewayBinding);
99 private final byte id;
100 private final Sensor sensor;
101 private final @Nullable Integer channel;
103 SensorGatewayBinding(byte id, Sensor sensor, @Nullable Integer channel) {
105 this.sensor = sensor;
106 this.channel = channel;
109 public static @Nullable List<SensorGatewayBinding> forIndex(byte idx) {
110 return SENSOR_LOOKUP.get(idx);
113 public BatteryStatus getBatteryStatus(byte data) {
114 return sensor.getBatteryStatus(data);
117 public Sensor getSensor() {
121 public @Nullable Integer getChannel() {