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