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.revolt;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
18 import org.openhab.binding.jeelink.internal.JeeLinkReadingConverter;
21 * Converter for converting a line read from a SlowRF CUL to a RevoltReading.
23 * @author Volker Bier - Initial contribution
25 public class RevoltReadingConverter implements JeeLinkReadingConverter<RevoltReading> {
26 private static final Pattern LINE_P = Pattern.compile("""
27 r([0-9A-Za-z]{4})([0-9A-Za-z]{2})([0-9A-Za-z]{4})([0-9A-Za-z]{2})([0-9A-Za-z]{4})\
28 ([0-9A-Za-z]{2})([0-9A-Za-z]{4})[0-9A-Za-z][0-9A-Za-z]\
32 public RevoltReading createReading(String inputLine) {
33 if (inputLine != null) {
34 Matcher matcher = LINE_P.matcher(inputLine);
35 if (matcher.matches()) {
37 * r4F1BE400513206875B312F25
39 String id = matcher.group(1); // 4F1B
41 int voltage = toInt(matcher.group(2)); // 0xE4 = 228 => 228 V
42 float current = toInt(matcher.group(3)) / 100f; // 0x0051 = 81 => 0,81 A
43 int frequency = toInt(matcher.group(4)); // 0x32 = 50 => 50 Hz
44 float power = toInt(matcher.group(5)) / 10f; // 0x0687 = 1671 => 167,1 W
45 float powerFact = toInt(matcher.group(6)) / 100f; // 0x5B = 91 => 0,91 VA
46 float consumption = toInt(matcher.group(7)) / 100f; // 0x312F = 12591 => 125,91 Wh
48 return new RevoltReading(id, voltage, current, frequency, power, powerFact, consumption);
55 private int toInt(String hex) {
56 Integer i = Integer.parseInt(hex, 16);