2 * Copyright (c) 2010-2023 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.somneo.internal.model;
15 import java.time.LocalTime;
16 import java.util.List;
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;
24 import com.google.gson.annotations.SerializedName;
27 * This class represents the audio state from the API.
29 * @author Michael Myrcik - Initial contribution
31 public class AlarmSchedulesData {
43 @SerializedName("daynm")
44 private List<Integer> repeatDays;
46 @SerializedName("almhr")
47 private List<Integer> hours;
49 @SerializedName("almmn")
50 private List<Integer> minutes;
52 public @NonNull State getRepeatDayState(int position) {
53 final List<Integer> repeatDays = this.repeatDays;
54 if (repeatDays == null) {
55 return UnDefType.NULL;
57 final Integer repeatDay = repeatDays.get(position - 1);
58 if (repeatDay == null) {
59 return UnDefType.NULL;
61 return new DecimalType(repeatDay);
64 public LocalTime getAlarmTime(int position) {
65 final List<Integer> hours = this.hours;
69 final List<Integer> minutes = this.minutes;
70 if (minutes == null) {
73 final Integer hour = hours.get(position - 1);
74 final Integer minute = minutes.get(position - 1);
75 return LocalTime.of(hour, minute);
78 public @NonNull State getAlarmTimeState(int position) {
79 final LocalTime time = getAlarmTime(position);
81 return UnDefType.NULL;
83 final String alarmTimeString = String.format("%02d:%02d:00", time.getHour(), time.getMinute());
84 if (alarmTimeString == null) {
85 return UnDefType.NULL;
87 return DateTimeType.valueOf(alarmTimeString);