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.jeelink.internal.lacrosse;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
18 import org.openhab.binding.jeelink.internal.JeeLinkReadingConverter;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Converter for converting a line read from a LGW to a LgwReading.
25 * @author Volker Bier - Initial contribution
27 public class LgwReadingConverter implements JeeLinkReadingConverter<LgwReading> {
28 private static final Pattern LINE_P = Pattern.compile(
29 "OK\\s+WS\\s+([0-9]+)\\s+4\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)(?:\\s+255){8}?\\s+0\\s+([0-9]+)\\s+([0-9]+)(?:\\s+255){9}?");
30 private final Logger logger = LoggerFactory.getLogger(LgwReadingConverter.class);
33 public LgwReading createReading(String inputLine) {
34 // parse lines only if we have registered listeners
35 if (inputLine != null) {
36 Matcher matcher = LINE_P.matcher(inputLine);
37 if (matcher.matches()) {
40 * OK WS 71 4 4 203 53 255 255 255 255 255 255 255 255 0 3 219 255 255 255 255 255 255 255 255 255
41 * OK WS 75 4 4 195 61 255 255 255 255 255 255 255 255 0 255 255 255 255 255 255 255 255 255 255 255
42 * OK WS 213 4 5 126 40 255 255 255 255 255 255 255 255 0 40 53 0 48 57
43 * OK WS ID XXX TTT TTT HHH RRR RRR DDD DDD SSS SSS GGG GGG FFF PPP PPP GAS GAS GAS DEB DEB DEB LUX LUX
45 * | | | | | | | | | | | | | | | | | |-------------------------------------- Pressure LSB
46 * | | | | | | | | | | | | | | | | |------------------------------------------ Pressure MSB
47 * | | | | | | | | | | | | | | | |-- Fix 0
48 * | | | | | | |-------------------------------------- Humidity (1 ... 99 %rH) FF = none
49 * | | | | | |------------------------------------------ Temp * 10 + 1000 LSB (-40 ... +60 °C) FF/FF =
51 * | | | | |---------------------------------------------- Temp * 10 + 1000 MSB
52 * | | | |-------------------------------------------------- fix "4"
53 * | | |------------------------------------------------------ Sensor ID (1 ... 63)
54 * | |--------------------------------------------------------- fix "WS"
55 * |------------------------------------------------------------ fix "OK"
57 logger.trace("Creating reading from: {}", inputLine);
59 int sensorId = Integer.parseInt(matcher.group(1));
61 Float temperature = "255".equals(matcher.group(2)) ? null
62 : (float) (Integer.parseInt(matcher.group(2)) * 256 + Integer.parseInt(matcher.group(3)) - 1000)
65 Integer humidity = "255".equals(matcher.group(4)) ? null : Integer.parseInt(matcher.group(4));
67 Integer pressure = null;
68 if (!"255".equals(matcher.group(5))) {
69 pressure = Integer.parseInt(matcher.group(5)) * 256 + Integer.parseInt(matcher.group(6));
72 return new LgwReading(sensorId, temperature, humidity, pressure);