2 * Copyright (c) 2010-2022 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.openuv.internal.json;
15 import java.time.ZonedDateTime;
16 import java.util.HashMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.library.unit.Units;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.google.gson.annotations.SerializedName;
32 * The {@link OpenUVResult} is responsible for storing
33 * the "result" node from the OpenUV JSON response
35 * @author Gaƫl L'hopital - Initial contribution
38 public class OpenUVResult {
39 private final Logger logger = LoggerFactory.getLogger(OpenUVResult.class);
41 public enum FitzpatrickType {
42 @SerializedName("st1")
43 I, // Fitzpatrick Skin Type I
44 @SerializedName("st2")
45 II, // Fitzpatrick Skin Type II
46 @SerializedName("st3")
47 III, // Fitzpatrick Skin Type III
48 @SerializedName("st4")
49 IV, // Fitzpatrick Skin Type IV
50 @SerializedName("st5")
51 V, // Fitzpatrick Skin Type V
52 @SerializedName("st6")
53 VI;// Fitzpatrick Skin Type VI
57 private @Nullable ZonedDateTime uvTime;
59 private @Nullable ZonedDateTime uvMaxTime;
61 private @Nullable ZonedDateTime ozoneTime;
62 private Map<FitzpatrickType, @Nullable Integer> safeExposureTime = new HashMap<>();
64 public double getUv() {
68 public double getUvMax() {
72 public double getOzone() {
76 public State getUVTime() {
77 ZonedDateTime value = uvTime;
78 return value != null ? new DateTimeType(value) : UnDefType.NULL;
81 public State getUVMaxTime() {
82 ZonedDateTime value = uvMaxTime;
83 return value != null ? new DateTimeType(value) : UnDefType.NULL;
86 public State getOzoneTime() {
87 ZonedDateTime value = ozoneTime;
88 return value != null ? new DateTimeType(value) : UnDefType.NULL;
91 public State getSafeExposureTime(String index) {
93 FitzpatrickType value = FitzpatrickType.valueOf(index);
94 Integer duration = safeExposureTime.get(value);
95 if (duration != null) {
96 return new QuantityType<>(duration, Units.MINUTE);
98 } catch (IllegalArgumentException e) {
99 logger.warn("Unexpected Fitzpatrick index value '{}' : {}", index, e.getMessage());
101 return UnDefType.NULL;