]> git.basschouten.com Git - openhab-addons.git/blob
204ff5254e88383e037519add1df087d846ace6c
[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.digitalstrom.internal.lib.structure.devices.deviceparameters.constants;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * The {@link SensorEnum} lists all available digitalSTROM sensor types.
20  *
21  * @author Michael Ochel - Initial contribution
22  * @author Matthias Siegele - Initial contribution
23  * @see <a href="http://developer.digitalstrom.org/Architecture/ds-basics.pdf">ds-basics.pdf, Table 40: Sensor Types
24  *      from ds-basic.pdf from 19.08.2015</a>
25  */
26 public enum SensorEnum {
27     /*
28      * | Sensor Type | Description | Unit | Min | 12 Bit Max | 12 Bit Resolution |
29      * -----------------------------------------------------------------------------------------------------------------
30      * -------------------------------------------------------------
31      * | 4 | Active power | Watts (W) | 0 | 4095 | 1 |
32      * | 5 | Output current | Ampere (mA) | 0 | 4095 | 1 |
33      * | 6 | Electric meter | Kilowatt hours (kWh) | 0 | 40,95 | 0,01 |
34      * | 9 | Temperature indoors | Kelvin (K) | 230 | 332,375 | 0,25 | (not correct)
35      * | 10 | Temperature outdoors | Kelvin (K) | 230 | 332,375 | 0,25 | (not correct)
36      * | 11 | Brightness indoors | Lux (Lx) | 1 | 131446,795 | logarithmic: lx = 10 * (x/800), x = 800 * log(lx) |
37      * | 12 | Brightness outdoors | Lux (Lx) | 1 | 131446,795 | logarithmic: lx = 10 * (x/800), x = 800 * log(lx) |
38      * | 13 | Relative humidity indoors | Percent (%) | 0 | 102,375 | 0,025 |
39      * | 14 | Relative humidity outdoors | Percent (%) | 0 | 102,375 | 0,025 |
40      * | 15 | Air pressure | Pascal (hPa) | 200 | 1223,75 | 0,25 |
41      * | 18 | Wind speed | Meters per second (m/s) | 0 | 102,375 | 0,025 |
42      * | 19 | Wind direction | degrees | 0 | 511,875 | 0,54 |
43      * | 20 | Precipitation | Milliliter per square meter (ml/m2) | 0 | 102,375 | 0,025 |
44      * | 21 | Carbon Dioxide | Parts per million (ppm) | 1 | 131446,795 | logarithmic: ppm = 10 * (x/800), x = 800 * log
45      * (ppm) |
46      * | 25 | Sound pressure level | Decibel (dB) | 0 | 255,938 | 0,25/4 |
47      * | 50 | Room temperature set point | Kelvin (K) | 230 | 332,375 | 0,025 | (not correct)
48      * | 51 | Room temperature control variable | Percent (%) | 0 | 102,375 | 0,025 |
49      * | 64 | Output current (H) | Ampere (mA) | 0 | 16380 | 4 |
50      * | 65 | Power consumption | Volt-Ampere (VA) | 0 | 4095 | 1 |
51      *
52      * Note: Point 20 precipitation, mm/m2 doesn't exist as unit, so it's liter or milliliter per square meter (ml/m2 or
53      * l/m2)
54      * otherwise it's only mm what is the same as l/m2)
55      *
56      */
57     ACTIVE_POWER((short) 4, "watt", "W", 0, 4095, 1, "%d"),
58     OUTPUT_CURRENT((short) 5, "ampere", "mA", 0, 4095, 1, "%d"),
59     ELECTRIC_METER((short) 6, "kilowatt_hours", "kWh", 0, (float) 40.95, (float) 0.01, "%.3f"),
60     TEMPERATURE_INDOORS((short) 9, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
61     TEMPERATURE_OUTDOORS((short) 10, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
62     BRIGHTNESS_INDOORS((short) 11, "lux", "Lx", 1, (float) 131446.795, 800, "%.3f"),
63     BRIGHTNESS_OUTDOORS((short) 12, "lux", "Lx", 1, (float) 131446.795, 800, "%.3f"),
64     RELATIVE_HUMIDITY_INDOORS((short) 13, "percent", "%", 0, (float) 102.375, (float) 0.025, "%.2f"),
65     RELATIVE_HUMIDITY_OUTDOORS((short) 14, "percent", "%", 0, (float) 102.375, (float) 0.025, "%.2f"),
66     AIR_PRESSURE((short) 15, "pascal", "hPa", 0, (float) 1223.75, (float) 0.25, "%.2f"),
67     WIND_SPEED((short) 18, "meters_per_second", "m/s", 0, (float) 102.375, (float) 0.025, "%.2f"),
68     WIND_DIRECTION((short) 19, "degrees", "°", 0, (float) 511.875, (float) 0.54, "%.2f"),
69     PRECIPITATION((short) 20, "millimeter_per_square_meter", "mm/m2", 0, (float) 102.375, (float) 0.025, "%.3f"),
70     CARBON_DIOXIDE((short) 21, "parts_per_million", "ppm", 1, (float) 131446.795, 800, "%.3f"),
71     SOUND_PRESSURE_LEVEL((short) 25, "decibel", "dB", 0, (float) 255.938, (float) 0.0625, "%.2f"),
72     ROOM_TEMPERATURE_SET_POINT((short) 50, "kelvin", "K", 230, (float) 332.375, (float) 0.025, "%.2f"),
73     ROOM_TEMPERATURE_CONTROL_VARIABLE((short) 51, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
74     OUTPUT_CURRENT_H((short) 64, "ampere", "mA", 0, 16380, 4, "%d"),
75     POWER_CONSUMPTION((short) 65, "volt_ampere", "VA", 0, 4095, 1, "%d");
76
77     private final Short sensorType;
78     private final String unit;
79     private final String unitShortcut;
80     private final String pattern;
81     private final Integer min;
82     private final Float max;
83     private final Float resolution;
84
85     static final Map<Short, SensorEnum> SENSOR_ENUMS = new HashMap<>();
86
87     SensorEnum(Short sensorType, String unit, String unitShortcut, int min, float max, float resolution,
88             String plattern) {
89         this.sensorType = sensorType;
90         this.unit = unit;
91         this.unitShortcut = unitShortcut;
92         this.min = min;
93         this.max = max;
94         this.resolution = resolution;
95         this.pattern = plattern;
96     }
97
98     static {
99         for (SensorEnum sensor : SensorEnum.values()) {
100             SENSOR_ENUMS.put(sensor.getSensorType(), sensor);
101         }
102     }
103
104     /**
105      * Returns true, if the given typeIndex contains in digitalSTROM, otherwise false.
106      *
107      * @param typeIndex to be checked
108      * @return true, if contains otherwise false
109      */
110     public static boolean containsSensor(Short typeIndex) {
111         return SENSOR_ENUMS.keySet().contains(typeIndex);
112     }
113
114     /**
115      * Return true, if the given {@link SensorEnum} is a climate sensor, otherwise false.
116      *
117      * @param sensorType to check
118      * @return true, if {@link SensorEnum} is climate sensor, otherwise false.
119      */
120     public static boolean isClimateSensor(SensorEnum sensorType) {
121         if (sensorType != null) {
122             switch (sensorType) {
123                 case TEMPERATURE_INDOORS:
124                 case TEMPERATURE_OUTDOORS:
125                 case BRIGHTNESS_INDOORS:
126                 case BRIGHTNESS_OUTDOORS:
127                 case RELATIVE_HUMIDITY_INDOORS:
128                 case RELATIVE_HUMIDITY_OUTDOORS:
129                 case AIR_PRESSURE:
130                 case WIND_SPEED:
131                 case WIND_DIRECTION:
132                 case PRECIPITATION:
133                 case CARBON_DIOXIDE:
134                 case SOUND_PRESSURE_LEVEL:
135                 case ROOM_TEMPERATURE_SET_POINT:
136                 case ROOM_TEMPERATURE_CONTROL_VARIABLE:
137                     return true;
138                 default:
139                     return false;
140             }
141         }
142         return false;
143     }
144
145     /**
146      * Return true, if the given {@link SensorEnum} is a power sensor, otherwise false.<br>
147      * <b>Power sensors are:</b><br>
148      * - {@link #ACTIVE_POWER}<br>
149      * - {@link #OUTPUT_CURRENT}<br>
150      * - {@link #ELECTRIC_METER}<br>
151      * - {@link #OUTPUT_CURRENT_H}<br>
152      * - {@link #POWER_CONSUMPTION}
153      *
154      * @param sensorType to check
155      * @return true, if {@link SensorEnum} is power sensor, otherwise false.
156      */
157     public static boolean isPowerSensor(SensorEnum sensorType) {
158         if (sensorType != null) {
159             switch (sensorType) {
160                 case ACTIVE_POWER:
161                 case OUTPUT_CURRENT:
162                 case ELECTRIC_METER:
163                 case OUTPUT_CURRENT_H:
164                 case POWER_CONSUMPTION:
165                     return true;
166                 default:
167                     return false;
168             }
169         }
170         return false;
171     }
172
173     /**
174      * Returns the {@link SensorEnum} for the given typeIndex, otherwise null.
175      *
176      * @param typeIndex of the {@link SensorEnum}
177      * @return SensorEnum or null
178      */
179     public static SensorEnum getSensor(Short typeIndex) {
180         return SENSOR_ENUMS.get(typeIndex);
181     }
182
183     /**
184      * Returns the typeIndex of this {@link SensorEnum} object.
185      *
186      * @return typeIndex
187      */
188     public Short getSensorType() {
189         return this.sensorType;
190     }
191
192     /**
193      * Returns the unit of this {@link SensorEnum} object.
194      *
195      * @return unit
196      */
197     public String getUnit() {
198         return this.unit;
199     }
200
201     /**
202      * Returns the unit shortcut of this {@link SensorEnum} object.
203      *
204      * @return unit shortcut
205      */
206     public String getUnitShortcut() {
207         return this.unitShortcut;
208     }
209
210     /**
211      * Returns the pattern of this {@link SensorEnum} object for display.
212      *
213      * @return pattern
214      */
215     public String getPattern() {
216         return this.pattern;
217     }
218
219     /**
220      * Returns the minimum sensor value.
221      *
222      * @return the min value
223      */
224     public Integer getMin() {
225         return min;
226     }
227
228     /**
229      * Returns the maximum sensor value.
230      *
231      * @return the max value
232      */
233     public Float getMax() {
234         return max;
235     }
236
237     /**
238      * Returns resolution for this sensor to get the float value of the dS-value (e.g. dSsensorValue * getResolution()).
239      * <br>
240      * <br>
241      * <b>Note:</b><br>
242      * If the resolution is 800, than you have to calculate "10 * (dSsensorValue/800)".
243      *
244      * @return the resolution
245      */
246     public Float getResolution() {
247         return resolution;
248     }
249 }