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.nobohub.internal.model;
15 import java.time.DateTimeException;
16 import java.time.LocalDateTime;
17 import java.time.format.DateTimeParseException;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.nobohub.internal.NoboHubBindingConstants;
24 * Helper class for converting data to/from Nobø Hub.
26 * @author Jørgen Austvik - Initial contribution
27 * @author Espen Fossen - Initial contribution
30 public final class ModelHelper {
33 * Converts a String returned form Nobø hub to a normal Java string.
35 * @param noboString String where Char 160 (nobr space is used for space)
36 * @return String with normal spaces.
38 static String toJavaString(final String noboString) {
39 return noboString.replace((char) 160, ' ');
43 * Converts a String in java to a string the Nobø hub can understand (fix spaces).
45 * @param javaString String to send to Nobø hub
46 * @return String with Nobø hub spaces
48 static String toHubString(final String javaString) {
49 return javaString.replace(' ', (char) 160);
53 * Creates a Java date string from a date string returned from the Nobø Hub.
55 * @param noboDateString Date string from Nobø, like '202001221832' or '-1'
56 * @return Java date for the returned string (or null if -1 is returned)
59 static LocalDateTime toJavaDate(final String noboDateString) throws NoboDataException {
60 if ("-1".equals(noboDateString)) {
65 return LocalDateTime.parse(noboDateString, NoboHubBindingConstants.DATE_FORMAT_MINUTES);
66 } catch (DateTimeParseException pe) {
67 throw new NoboDataException(String.format("Failed parsing string %s", noboDateString), pe);
71 static String toHubDateMinutes(final @Nullable LocalDateTime date) {
77 return date.format(NoboHubBindingConstants.DATE_FORMAT_MINUTES);
78 } catch (DateTimeException dte) {