]> git.basschouten.com Git - openhab-addons.git/blob
88b8dd33420aed1cc56b58700b7cc5f82850d591
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.openuv.internal.json;
14
15 import java.time.LocalDateTime;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.library.types.DateTimeType;
21 import org.openhab.core.types.State;
22 import org.openhab.core.types.UnDefType;
23
24 /**
25  * The {@link OpenUVResult} is responsible for storing
26  * the "result" node from the OpenUV JSON response
27  *
28  * @author GaĆ«l L'hopital - Initial contribution
29  */
30 @NonNullByDefault
31 public class OpenUVResult {
32     private final ZonedDateTime DEFAULT_ZDT = ZonedDateTime.of(LocalDateTime.MIN, ZoneId.systemDefault());
33     private double uv;
34     private ZonedDateTime uvTime = DEFAULT_ZDT;
35     private double uvMax;
36     private ZonedDateTime uvMaxTime = DEFAULT_ZDT;
37     private double ozone;
38     private ZonedDateTime ozoneTime = DEFAULT_ZDT;
39     private SafeExposureTime safeExposureTime = new SafeExposureTime();
40
41     public int getUv() {
42         return (int) uv;
43     }
44
45     public int getUvMax() {
46         return (int) uvMax;
47     }
48
49     public double getOzone() {
50         return ozone;
51     }
52
53     public State getUVTime() {
54         return uvTime != DEFAULT_ZDT ? new DateTimeType(uvTime.withZoneSameInstant(ZoneId.systemDefault()))
55                 : UnDefType.NULL;
56     }
57
58     public State getUVMaxTime() {
59         return uvMaxTime != DEFAULT_ZDT ? new DateTimeType(uvMaxTime.withZoneSameInstant(ZoneId.systemDefault()))
60                 : UnDefType.NULL;
61     }
62
63     public State getOzoneTime() {
64         return ozoneTime != DEFAULT_ZDT ? new DateTimeType(ozoneTime.withZoneSameInstant(ZoneId.systemDefault()))
65                 : UnDefType.NULL;
66     }
67
68     public SafeExposureTime getSafeExposureTime() {
69         return safeExposureTime;
70     }
71 }