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 org.eclipse.jdt.annotation.NonNullByDefault;
18 * Nobø serial numbers are 12 digits where 3 and 3 digits form 2 bytes as decimal. In total 32 bits.
20 * @author Jørgen Austvik - Initial contribution
23 public final class Temperature {
25 private final SerialNumber serialNumber;
26 private final double temperature;
28 public Temperature(SerialNumber serialNumber, double temperature) {
29 this.serialNumber = serialNumber;
30 this.temperature = temperature;
33 public static Temperature fromY02(String y02) throws NoboDataException {
34 String[] parts = y02.split(" ", 3);
35 if (parts.length != 3) {
36 throw new NoboDataException(
37 String.format("Unexpected number of parts from hub on Y02 call: %d", parts.length));
40 if (parts[2] == null) {
41 throw new NoboDataException("Missing temperature data");
44 SerialNumber serialNumber = new SerialNumber(parts[1]);
45 double temp = Double.NaN;
47 if (!"N/A".equals(parts[2])) {
49 temp = Double.parseDouble(parts[2]);
50 } catch (NumberFormatException nfe) {
51 throw new NoboDataException(
52 String.format("Failed to parse temperature %s: %s", parts[2], nfe.getMessage()), nfe);
56 return new Temperature(serialNumber, temp);
59 public SerialNumber getSerialNumber() {
63 public double getTemperature() {