]> git.basschouten.com Git - openhab-addons.git/blob
940c4a0399fd93049b30790e4ad429254a181320
[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 java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.QuantityType;
19 import org.openhab.core.library.unit.Units;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * DTO for CLIP 2 mirek schema.
25  *
26  * @author Andrew Fiddian-Green - Initial contribution
27  */
28 @NonNullByDefault
29 public class MirekSchema {
30     private static final int MIN = 153;
31     private static final int MAX = 500;
32
33     public static final MirekSchema DEFAULT_SCHEMA = new MirekSchema();
34
35     private @SerializedName("mirek_minimum") int mirekMinimum = MIN;
36     private @SerializedName("mirek_maximum") int mirekMaximum = MAX;
37
38     public int getMirekMaximum() {
39         return mirekMaximum;
40     }
41
42     public int getMirekMinimum() {
43         return mirekMinimum;
44     }
45
46     private String toKelvin(int mirek) {
47         QuantityType<?> kelvin = QuantityType.valueOf(mirek, Units.MIRED).toInvertibleUnit(Units.KELVIN);
48         return Objects.nonNull(kelvin) ? String.format("%.0f K", kelvin.doubleValue()) : "";
49     }
50
51     public String toPropertyValue() {
52         return String.format("%s .. %s", toKelvin(mirekMinimum), toKelvin(mirekMaximum));
53     }
54 }