]> git.basschouten.com Git - openhab-addons.git/blob
e1934345859888d1961492c30974b4f2e1d56908
[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.somneo.internal.model;
14
15 import java.time.LocalTime;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.openhab.core.library.types.DateTimeType;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.types.State;
22 import org.openhab.core.types.UnDefType;
23
24 import com.google.gson.annotations.SerializedName;
25
26 /**
27  * This class represents the audio state from the API.
28  *
29  * @author Michael Myrcik - Initial contribution
30  */
31 public class AlarmSchedulesData {
32
33     /**
34      * None = 0,
35      * Monday = 2,
36      * Tuesday = 4,
37      * Wednesday = 8,
38      * Thursday = 16,
39      * Friday = 32,
40      * Saturday = 64,
41      * Sunday = 128
42      */
43     @SerializedName("daynm")
44     private List<Integer> repeatDays;
45
46     @SerializedName("almhr")
47     private List<Integer> hours;
48
49     @SerializedName("almmn")
50     private List<Integer> minutes;
51
52     public @NonNull State getRepeatDayState(int position) {
53         final List<Integer> repeatDays = this.repeatDays;
54         if (repeatDays == null) {
55             return UnDefType.NULL;
56         }
57         final Integer repeatDay = repeatDays.get(position - 1);
58         if (repeatDay == null) {
59             return UnDefType.NULL;
60         }
61         return new DecimalType(repeatDay);
62     }
63
64     public LocalTime getAlarmTime(int position) {
65         final List<Integer> hours = this.hours;
66         if (hours == null) {
67             return null;
68         }
69         final List<Integer> minutes = this.minutes;
70         if (minutes == null) {
71             return null;
72         }
73         final Integer hour = hours.get(position - 1);
74         final Integer minute = minutes.get(position - 1);
75         return LocalTime.of(hour, minute);
76     }
77
78     public @NonNull State getAlarmTimeState(int position) {
79         final LocalTime time = getAlarmTime(position);
80         if (time == null) {
81             return UnDefType.NULL;
82         }
83         final String alarmTimeString = String.format("%02d:%02d:00", time.getHour(), time.getMinute());
84         if (alarmTimeString == null) {
85             return UnDefType.NULL;
86         }
87         return DateTimeType.valueOf(alarmTimeString);
88     }
89 }