2 * Copyright (c) 2010-2021 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.miele.internal;
15 import java.nio.charset.StandardCharsets;
18 * The {@link ExtendedDeviceStateUtil} class contains utility methods for parsing
19 * ExtendedDeviceState information
21 * @author Jacob Laursen - Added power/water consumption channels
23 public class ExtendedDeviceStateUtil {
24 private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
27 * Convert byte array to hex representation.
29 public static String bytesToHex(byte[] bytes) {
30 byte[] hexChars = new byte[bytes.length * 2];
31 for (int j = 0; j < bytes.length; j++) {
32 int v = bytes[j] & 0xFF;
33 hexChars[j * 2] = HEX_ARRAY[v >>> 4];
34 hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
37 return new String(hexChars, StandardCharsets.UTF_8);
41 * Convert string consisting of 8 bit characters to byte array.
42 * Note: This simple operation has been extracted and put here to document
43 * and ensure correct behavior for 8 bit characters that should be turned
44 * into single bytes without any UTF-8 encoding.
46 public static byte[] stringToBytes(String input) {
47 return input.getBytes(StandardCharsets.ISO_8859_1);