2 * Copyright (c) 2010-2022 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 static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MAX_WIND_SPEED;
16 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MOISTURE;
17 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_UV_INDEX;
19 import java.util.HashMap;
20 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.MeasuredValue;
26 import org.openhab.core.thing.DefaultSystemChannelTypeProvider;
27 import org.openhab.core.thing.type.ChannelTypeUID;
28 import org.openhab.core.types.State;
31 * The measurands of supported by the gateway.
33 * @author Andreas Berger - Initial contribution
36 public enum Measurand {
38 INTEMP("temperature-indoor", (byte) 0x01, "Indoor Temperature", MeasureType.TEMPERATURE,
39 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_INDOOR_TEMPERATURE),
41 OUTTEMP("temperature-outdoor", (byte) 0x02, "Outdoor Temperature", MeasureType.TEMPERATURE,
42 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_OUTDOOR_TEMPERATURE),
44 DEWPOINT("temperature-dew-point", (byte) 0x03, "Dew point", MeasureType.TEMPERATURE),
46 WINDCHILL("temperature-wind-chill", (byte) 0x04, "Wind chill", MeasureType.TEMPERATURE),
48 HEATINDEX("temperature-heat-index", (byte) 0x05, "Heat index", MeasureType.TEMPERATURE),
50 INHUMI("humidity-indoor", (byte) 0x06, "Indoor Humidity", MeasureType.PERCENTAGE),
52 OUTHUMI("humidity-outdoor", (byte) 0x07, "Outdoor Humidity", MeasureType.PERCENTAGE,
53 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_ATMOSPHERIC_HUMIDITY),
55 ABSBARO("pressure-absolute", (byte) 0x08, "Absolutely pressure", MeasureType.PRESSURE),
57 RELBARO("pressure-relative", (byte) 0x09, "Relative pressure", MeasureType.PRESSURE,
58 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_BAROMETRIC_PRESSURE),
60 WINDDIRECTION("direction-wind", (byte) 0x0A, "Wind Direction", MeasureType.DEGREE,
61 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_WIND_DIRECTION),
63 WINDSPEED("speed-wind", (byte) 0x0B, "Wind Speed", MeasureType.SPEED,
64 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_WIND_SPEED),
66 GUSTSPEED("speed-gust", (byte) 0x0C, "Gust Speed", MeasureType.SPEED,
67 DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_WIND_SPEED),
69 RAINEVENT("rain-event", (byte) 0x0D, "Rain Event", MeasureType.HEIGHT),
71 RAINRATE("rain-rate", (byte) 0x0E, "Rain Rate", MeasureType.HEIGHT_PER_HOUR),
73 RAINHOUR("rain-hour", (byte) 0x0F, "Rain hour", MeasureType.HEIGHT),
75 RAINDAY("rain-day", (byte) 0x10, "Rain Day", MeasureType.HEIGHT),
77 RAINWEEK("rain-week", (byte) 0x11, "Rain Week", MeasureType.HEIGHT),
79 RAINMONTH("rain-month", (byte) 0x12, "Rain Month", MeasureType.HEIGHT_BIG),
81 RAINYEAR("rain-year", (byte) 0x13, "Rain Year", MeasureType.HEIGHT_BIG),
83 RAINTOTALS("rain-total", (byte) 0x14, "Rain Totals", MeasureType.HEIGHT_BIG),
85 LIGHT("illumination", (byte) 0x15, "Light", MeasureType.LUX),
87 UV("irradiation-uv", (byte) 0x16, "UV", MeasureType.MICROWATT_PER_SQUARE_CENTIMETRE),
89 UVI("uv-index", (byte) 0x17, "UV index", MeasureType.BYTE, CHANNEL_TYPE_UV_INDEX),
91 TIME("time", (byte) 0x18, "Date and time", MeasureType.DATE_TIME2),
93 DAYLWINDMAX("wind-max-day", (byte) 0X19, "Day max wind", MeasureType.SPEED, CHANNEL_TYPE_MAX_WIND_SPEED),
95 TEMP1("temperature-channel-1", (byte) 0x1A, "Temperature 1", MeasureType.TEMPERATURE),
97 TEMP2("temperature-channel-2", (byte) 0x1B, "Temperature 2", MeasureType.TEMPERATURE),
99 TEMP3("temperature-channel-3", (byte) 0x1C, "Temperature 3", MeasureType.TEMPERATURE),
101 TEMP4("temperature-channel-4", (byte) 0x1D, "Temperature 4", MeasureType.TEMPERATURE),
103 TEMP5("temperature-channel-5", (byte) 0x1E, "Temperature 5", MeasureType.TEMPERATURE),
105 TEMP6("temperature-channel-6", (byte) 0x1F, "Temperature 6", MeasureType.TEMPERATURE),
107 TEMP7("temperature-channel-7", (byte) 0x20, "Temperature 7", MeasureType.TEMPERATURE),
109 TEMP8("temperature-channel-8", (byte) 0x21, "Temperature 8", MeasureType.TEMPERATURE),
111 HUMI1("humidity-channel-1", (byte) 0x22, "Humidity 1", MeasureType.PERCENTAGE),
113 HUMI2("humidity-channel-2", (byte) 0x23, "Humidity 2", MeasureType.PERCENTAGE),
115 HUMI3("humidity-channel-3", (byte) 0x24, "Humidity 3", MeasureType.PERCENTAGE),
117 HUMI4("humidity-channel-4", (byte) 0x25, "Humidity 4", MeasureType.PERCENTAGE),
119 HUMI5("humidity-channel-5", (byte) 0x26, "Humidity 5", MeasureType.PERCENTAGE),
121 HUMI6("humidity-channel-6", (byte) 0x27, "Humidity 6", MeasureType.PERCENTAGE),
123 HUMI7("humidity-channel-7", (byte) 0x28, "Humidity 7", MeasureType.PERCENTAGE),
125 HUMI8("humidity-channel-8", (byte) 0x29, "Humidity 8", MeasureType.PERCENTAGE),
127 SOILTEMP1("temperature-soil-channel-1", (byte) 0x2B, "Soil Temperature 1", MeasureType.TEMPERATURE),
129 SOILTEMP2("temperature-soil-channel-2", (byte) 0x2D, "Soil Temperature 2", MeasureType.TEMPERATURE),
131 SOILTEMP3("temperature-soil-channel-3", (byte) 0x2F, "Soil Temperature 3", MeasureType.TEMPERATURE),
133 SOILTEMP4("temperature-soil-channel-4", (byte) 0x31, "Soil Temperature 4", MeasureType.TEMPERATURE),
135 SOILTEMP5("temperature-soil-channel-5", (byte) 0x33, "Soil Temperature 5", MeasureType.TEMPERATURE),
137 SOILTEMP6("temperature-soil-channel-6", (byte) 0x35, "Soil Temperature 6", MeasureType.TEMPERATURE),
139 SOILTEMP7("temperature-soil-channel-7", (byte) 0x37, "Soil Temperature 7", MeasureType.TEMPERATURE),
141 SOILTEMP8("temperature-soil-channel-8", (byte) 0x39, "Soil Temperature 8", MeasureType.TEMPERATURE),
143 SOILTEMP9("temperature-soil-channel-9", (byte) 0x3B, "Soil Temperature 9", MeasureType.TEMPERATURE),
145 SOILTEMP10("temperature-soil-channel-10", (byte) 0x3D, "Soil Temperature 10", MeasureType.TEMPERATURE),
147 SOILTEMP11("temperature-soil-channel-11", (byte) 0x3F, "Soil Temperature 11", MeasureType.TEMPERATURE),
149 SOILTEMP12("temperature-soil-channel-12", (byte) 0x41, "Soil Temperature 12", MeasureType.TEMPERATURE),
151 SOILTEMP13("temperature-soil-channel-13", (byte) 0x43, "Soil Temperature 13", MeasureType.TEMPERATURE),
153 SOILTEMP14("temperature-soil-channel-14", (byte) 0x45, "Soil Temperature 14", MeasureType.TEMPERATURE),
155 SOILTEMP15("temperature-soil-channel-15", (byte) 0x47, "Soil Temperature 15", MeasureType.TEMPERATURE),
157 SOILTEMP16("temperature-soil-channel-16", (byte) 0x49, "Soil Temperature 16", MeasureType.TEMPERATURE),
159 SOILMOISTURE1("moisture-soil-channel-1", (byte) 0x2C, "Soil Moisture 1", MeasureType.PERCENTAGE,
160 CHANNEL_TYPE_MOISTURE),
162 SOILMOISTURE2("moisture-soil-channel-2", (byte) 0x2E, "Soil Moisture 2", MeasureType.PERCENTAGE,
163 CHANNEL_TYPE_MOISTURE),
165 SOILMOISTURE3("moisture-soil-channel-3", (byte) 0x30, "Soil Moisture 3", MeasureType.PERCENTAGE,
166 CHANNEL_TYPE_MOISTURE),
168 SOILMOISTURE4("moisture-soil-channel-4", (byte) 0x32, "Soil Moisture 4", MeasureType.PERCENTAGE,
169 CHANNEL_TYPE_MOISTURE),
171 SOILMOISTURE5("moisture-soil-channel-5", (byte) 0x34, "Soil Moisture 5", MeasureType.PERCENTAGE,
172 CHANNEL_TYPE_MOISTURE),
174 SOILMOISTURE6("moisture-soil-channel-6", (byte) 0x36, "Soil Moisture 6", MeasureType.PERCENTAGE,
175 CHANNEL_TYPE_MOISTURE),
177 SOILMOISTURE7("moisture-soil-channel-7", (byte) 0x38, "Soil Moisture 7", MeasureType.PERCENTAGE,
178 CHANNEL_TYPE_MOISTURE),
180 SOILMOISTURE8("moisture-soil-channel-8", (byte) 0x3A, "Soil Moisture 8", MeasureType.PERCENTAGE,
181 CHANNEL_TYPE_MOISTURE),
183 SOILMOISTURE9("moisture-soil-channel-9", (byte) 0x3C, "Soil Moisture 9", MeasureType.PERCENTAGE,
184 CHANNEL_TYPE_MOISTURE),
186 SOILMOISTURE10("moisture-soil-channel-10", (byte) 0x3E, "Soil Moisture 10", MeasureType.PERCENTAGE,
187 CHANNEL_TYPE_MOISTURE),
189 SOILMOISTURE11("moisture-soil-channel-11", (byte) 0x40, "Soil Moisture 11", MeasureType.PERCENTAGE,
190 CHANNEL_TYPE_MOISTURE),
192 SOILMOISTURE12("moisture-soil-channel-12", (byte) 0x42, "Soil Moisture 12", MeasureType.PERCENTAGE,
193 CHANNEL_TYPE_MOISTURE),
195 SOILMOISTURE13("moisture-soil-channel-13", (byte) 0x44, "Soil Moisture 13", MeasureType.PERCENTAGE,
196 CHANNEL_TYPE_MOISTURE),
198 SOILMOISTURE14("moisture-soil-channel-14", (byte) 0x46, "Soil Moisture 14", MeasureType.PERCENTAGE,
199 CHANNEL_TYPE_MOISTURE),
201 SOILMOISTURE15("moisture-soil-channel-15", (byte) 0x48, "Soil Moisture 15", MeasureType.PERCENTAGE,
202 CHANNEL_TYPE_MOISTURE),
204 SOILMOISTURE16("moisture-soil-channel-16", (byte) 0x4A, "Soil Moisture 16", MeasureType.PERCENTAGE,
205 CHANNEL_TYPE_MOISTURE),
207 // will no longer be used
208 // skip battery-level, since it is read via Command.CMD_READ_SENSOR_ID_NEW
209 LOWBATT((byte) 0x4C, new Skip(1)),
211 PM25_24HAVG1("air-quality-24-hour-average-channel-1", (byte) 0x4D, "PM2.5 Air Quality 24 hour average channel 1",
214 PM25_24HAVG2("air-quality-24-hour-average-channel-2", (byte) 0x4E, "PM2.5 Air Quality 24 hour average channel 2",
217 PM25_24HAVG3("air-quality-24-hour-average-channel-3", (byte) 0x4F, "PM2.5 Air Quality 24 hour average channel 3",
220 PM25_24HAVG4("air-quality-24-hour-average-channel-4", (byte) 0x50, "PM2.5 Air Quality 24 hour average channel 4",
223 PM25_CH1("air-quality-channel-1", (byte) 0x2A, "PM2.5 Air Quality channel 1", MeasureType.PM25),
225 PM25_CH2("air-quality-channel-2", (byte) 0x51, "PM2.5 Air Quality channel 2", MeasureType.PM25),
227 PM25_CH3("air-quality-channel-3", (byte) 0x52, "PM2.5 Air Quality channel 3", MeasureType.PM25),
229 PM25_CH4("air-quality-channel-4", (byte) 0x53, "PM2.5 Air Quality channel 4", MeasureType.PM25),
231 LEAK_CH1("water-leak-channel-1", (byte) 0x58, "Leak channel 1", MeasureType.WATER_LEAK_DETECTION),
233 LEAK_CH2("water-leak-channel-2", (byte) 0x59, "Leak channel 2", MeasureType.WATER_LEAK_DETECTION),
235 LEAK_CH3("water-leak-channel-3", (byte) 0x5A, "Leak channel 3", MeasureType.WATER_LEAK_DETECTION),
237 LEAK_CH4("water-leak-channel-4", (byte) 0x5B, "Leak channel 4", MeasureType.WATER_LEAK_DETECTION),
239 // `LIGHTNING` is the name in the spec, so we keep it here as it
240 LIGHTNING("lightning-distance", (byte) 0x60, "lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
242 LIGHTNING_TIME("lightning-time", (byte) 0x61, "lightning happened time", MeasureType.LIGHTNING_TIME),
244 // `LIGHTNING_POWER` is the name in the spec, so we keep it here as it
245 LIGHTNING_POWER("lightning-counter", (byte) 0x62, "lightning counter for the day", MeasureType.LIGHTNING_COUNTER),
247 TF_USR1("temperature-external-channel-1", (byte) 0x63, "Soil or Water temperature channel 1",
248 MeasureType.TEMPERATURE),
250 TF_USR2("temperature-external-channel-2", (byte) 0x64, "Soil or Water temperature channel 2",
251 MeasureType.TEMPERATURE),
253 TF_USR3("temperature-external-channel-3", (byte) 0x65, "Soil or Water temperature channel 3",
254 MeasureType.TEMPERATURE),
256 TF_USR4("temperature-external-channel-4", (byte) 0x66, "Soil or Water temperature channel 4",
257 MeasureType.TEMPERATURE),
259 TF_USR5("temperature-external-channel-5", (byte) 0x67, "Soil or Water temperature channel 5",
260 MeasureType.TEMPERATURE),
262 TF_USR6("temperature-external-channel-6", (byte) 0x68, "Soil or Water temperature channel 6",
263 MeasureType.TEMPERATURE),
265 TF_USR7("temperature-external-channel-7", (byte) 0x69, "Soil or Water temperature channel 7",
266 MeasureType.TEMPERATURE),
268 TF_USR8("temperature-external-channel-8", (byte) 0x6A, "Soil or Water temperature channel 8",
269 MeasureType.TEMPERATURE),
271 ITEM_SENSOR_CO2((byte) 0x70,
272 new MeasurandParser("sensor-co2-temperature", "Temperature (CO₂-Sensor)", MeasureType.TEMPERATURE),
273 new MeasurandParser("sensor-co2-humidity", "Humidity (CO₂-Sensor)", MeasureType.PERCENTAGE),
274 new MeasurandParser("sensor-co2-pm10", "PM10 Air Quality (CO₂-Sensor)", MeasureType.PM10),
275 new MeasurandParser("sensor-co2-pm10-24-hour-average", "PM10 Air Quality 24 hour average (CO₂-Sensor)",
277 new MeasurandParser("sensor-co2-pm25", "PM2.5 Air Quality (CO₂-Sensor)", MeasureType.PM25),
278 new MeasurandParser("sensor-co2-pm25-24-hour-average", "PM2.5 Air Quality 24 hour average (CO₂-Sensor)",
280 new MeasurandParser("sensor-co2-co2", "CO₂", MeasureType.CO2),
281 new MeasurandParser("sensor-co2-co2-24-hour-average", "CO₂ 24 hour average", MeasureType.CO2),
282 // skip battery-level, since it is read via Command.CMD_READ_SENSOR_ID_NEW
285 ITEM_LEAF_WETNESS_CH1("leaf-wetness-channel-1", (byte) 0x72, "Leaf Moisture channel 1", MeasureType.PERCENTAGE,
286 CHANNEL_TYPE_MOISTURE),
288 ITEM_LEAF_WETNESS_CH2("leaf-wetness-channel-2", (byte) 0x73, "Leaf Moisture channel 2", MeasureType.PERCENTAGE,
289 CHANNEL_TYPE_MOISTURE),
291 ITEM_LEAF_WETNESS_CH3("leaf-wetness-channel-3", (byte) 0x74, "Leaf Moisture channel 3", MeasureType.PERCENTAGE,
292 CHANNEL_TYPE_MOISTURE),
294 ITEM_LEAF_WETNESS_CH4("leaf-wetness-channel-4", (byte) 0x75, "Leaf Moisture channel 4", MeasureType.PERCENTAGE,
295 CHANNEL_TYPE_MOISTURE),
297 ITEM_LEAF_WETNESS_CH5("leaf-wetness-channel-5", (byte) 0x76, "Leaf Moisture channel 5", MeasureType.PERCENTAGE,
298 CHANNEL_TYPE_MOISTURE),
300 ITEM_LEAF_WETNESS_CH6("leaf-wetness-channel-6", (byte) 0x77, "Leaf Moisture channel 6", MeasureType.PERCENTAGE,
301 CHANNEL_TYPE_MOISTURE),
303 ITEM_LEAF_WETNESS_CH7("leaf-wetness-channel-7", (byte) 0x78, "Leaf Moisture channel 7", MeasureType.PERCENTAGE,
304 CHANNEL_TYPE_MOISTURE),
306 ITEM_LEAF_WETNESS_CH8("leaf-wetness-channel-8", (byte) 0x79, "Leaf Moisture channel 8", MeasureType.PERCENTAGE,
307 CHANNEL_TYPE_MOISTURE),;
309 private static final Map<Byte, Measurand> MEASURANDS = new HashMap<>();
312 for (Measurand value : values()) {
313 MEASURANDS.put(value.code, value);
317 private final byte code;
318 private final Parser[] parsers;
320 Measurand(String channelId, byte code, String name, MeasureType measureType) {
321 this(channelId, code, name, measureType, null);
324 Measurand(String channelId, byte code, String name, MeasureType measureType,
325 @Nullable ChannelTypeUID channelTypeUID) {
326 this(code, new MeasurandParser(channelId, name, measureType, channelTypeUID));
329 Measurand(byte code, Parser... parsers) {
331 this.parsers = parsers;
334 public static @Nullable Measurand getByCode(byte code) {
335 return MEASURANDS.get(code);
338 public int extractMeasuredValues(byte[] data, int offset, ConversionContext context, List<MeasuredValue> result) {
340 for (Parser parser : parsers) {
341 subOffset += parser.extractMeasuredValues(data, offset + subOffset, context, result);
346 private interface Parser {
347 int extractMeasuredValues(byte[] data, int offset, ConversionContext context, List<MeasuredValue> result);
350 private static class Skip implements Parser {
351 private final int skip;
353 public Skip(int skip) {
358 public int extractMeasuredValues(byte[] data, int offset, ConversionContext context,
359 List<MeasuredValue> result) {
364 private static class MeasurandParser implements Parser {
365 private final String name;
366 private final String channelId;
367 private final MeasureType measureType;
368 private final @Nullable ChannelTypeUID channelTypeUID;
370 MeasurandParser(String channelId, String name, MeasureType measureType) {
371 this(channelId, name, measureType, null);
374 MeasurandParser(String channelId, String name, MeasureType measureType,
375 @Nullable ChannelTypeUID channelTypeUID) {
376 this.channelId = channelId;
378 this.measureType = measureType;
379 this.channelTypeUID = channelTypeUID == null ? measureType.getChannelTypeId() : channelTypeUID;
382 public int extractMeasuredValues(byte[] data, int offset, ConversionContext context,
383 List<MeasuredValue> result) {
384 State state = measureType.toState(data, offset, context);
386 result.add(new MeasuredValue(measureType, channelId, channelTypeUID, state, name));
388 return measureType.getByteSize();