]> git.basschouten.com Git - openhab-addons.git/blob
f86ea8fa17451a5d16e0e297b6cdcbe83490ec07
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal.api.dto.clip2;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.library.types.QuantityType;
19 import org.openhab.core.library.unit.SIUnits;
20 import org.openhab.core.types.State;
21 import org.openhab.core.types.UnDefType;
22
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  * DTO for CLIP 2 temperature sensor.
27  *
28  * @author Andrew Fiddian-Green - Initial contribution
29  */
30 @NonNullByDefault
31 public class Temperature {
32     private float temperature;
33     private @SerializedName("temperature_valid") boolean temperatureValid;
34     private @Nullable @SerializedName("temperature_report") TemperatureReport temperatureReport;
35
36     /**
37      * The underlying field is deprecated in the CLIP 2 API.
38      * Moved to temperature_report/temperature.
39      * Should be used only as fallback for older firmwares.
40      *
41      * @return temperature in 1.00 degrees Celsius
42      */
43     public float getTemperature() {
44         return temperature;
45     }
46
47     /**
48      * The underlying field is deprecated in the CLIP 2 API.
49      * Indication whether the value presented in temperature is valid
50      * Should be used only as fallback for older firmwares.
51      */
52     public boolean isTemperatureValid() {
53         return temperatureValid;
54     }
55
56     public State getTemperatureState() {
57         return temperatureValid ? new QuantityType<>(temperature, SIUnits.CELSIUS) : UnDefType.UNDEF;
58     }
59
60     public State getTemperatureValidState() {
61         return OnOffType.from(temperatureValid);
62     }
63
64     public @Nullable TemperatureReport getTemperatureReport() {
65         return temperatureReport;
66     }
67 }