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
27 .compile("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]");
31 public RevoltReading createReading(String inputLine) {
32 if (inputLine != null) {
33 Matcher matcher = LINE_P.matcher(inputLine);
34 if (matcher.matches()) {
36 * r4F1BE400513206875B312F25
38 String id = matcher.group(1); // 4F1B
40 int voltage = toInt(matcher.group(2)); // 0xE4 = 228 => 228 V
41 float current = toInt(matcher.group(3)) / 100f; // 0x0051 = 81 => 0,81 A
42 int frequency = toInt(matcher.group(4)); // 0x32 = 50 => 50 Hz
43 float power = toInt(matcher.group(5)) / 10f; // 0x0687 = 1671 => 167,1 W
44 float powerFact = toInt(matcher.group(6)) / 100f; // 0x5B = 91 => 0,91 VA
45 float consumption = toInt(matcher.group(7)) / 100f; // 0x312F = 12591 => 125,91 Wh
47 return new RevoltReading(id, voltage, current, frequency, power, powerFact, consumption);
54 private int toInt(String hex) {
55 Integer i = Integer.parseInt(hex, 16);