2 * Copyright (c) 2010-2020 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.neohub.internal;
15 import java.time.Instant;
17 import javax.measure.Unit;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.library.unit.ImperialUnits;
22 import org.openhab.core.library.unit.SIUnits;
24 import com.google.gson.Gson;
25 import com.google.gson.JsonSyntaxException;
26 import com.google.gson.annotations.SerializedName;
29 * A wrapper around the JSON response to the JSON READ_DCB and GET_SYSTEM
32 * @author Andrew Fiddian-Green - Initial contribution
35 public class NeoHubReadDcbResponse {
37 private static final Gson GSON = new Gson();
39 @SerializedName("CORF")
40 private @Nullable String degreesCorF;
43 * note: time-stamps are measured in seconds from 1970-01-01T00:00:00Z
45 * this time-stamp is the moment of creation of this class instance; it is used
46 * to compare with the system last change time-stamp reported by the hub
48 public final long timeStamp = Instant.now().getEpochSecond();
50 public Unit<?> getTemperatureUnit() {
51 return "F".equalsIgnoreCase(degreesCorF) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS;
55 * Create wrapper around a JSON string
57 * @param fromJson the JSON string
58 * @return a NeoHubReadDcbResponse wrapper around the JSON string
59 * @throws JsonSyntaxException
62 public static @Nullable NeoHubReadDcbResponse createSystemData(String fromJson) throws JsonSyntaxException {
63 return GSON.fromJson(fromJson, NeoHubReadDcbResponse.class);