forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[somneo] Add alarm support and other improvements (openhab#14882)
* [somneo] Add alarm clock channels Signed-off-by: Michael Myrcik <[email protected]> Signed-off-by: Jørgen Austvik <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,737 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
428 changes: 357 additions & 71 deletions
428
...enhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHandler.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ng.somneo/src/main/java/org/openhab/binding/somneo/internal/model/AlarmSchedulesData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.somneo.internal.model; | ||
|
||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.openhab.core.library.types.DateTimeType; | ||
import org.openhab.core.library.types.DecimalType; | ||
import org.openhab.core.types.State; | ||
import org.openhab.core.types.UnDefType; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* This class represents the audio state from the API. | ||
* | ||
* @author Michael Myrcik - Initial contribution | ||
*/ | ||
public class AlarmSchedulesData { | ||
|
||
/** | ||
* None = 0, | ||
* Monday = 2, | ||
* Tuesday = 4, | ||
* Wednesday = 8, | ||
* Thursday = 16, | ||
* Friday = 32, | ||
* Saturday = 64, | ||
* Sunday = 128 | ||
*/ | ||
@SerializedName("daynm") | ||
private List<Integer> repeatDays; | ||
|
||
@SerializedName("almhr") | ||
private List<Integer> hours; | ||
|
||
@SerializedName("almmn") | ||
private List<Integer> minutes; | ||
|
||
public @NonNull State getRepeatDayState(int position) { | ||
final List<Integer> repeatDays = this.repeatDays; | ||
if (repeatDays == null) { | ||
return UnDefType.NULL; | ||
} | ||
final Integer repeatDay = repeatDays.get(position - 1); | ||
if (repeatDay == null) { | ||
return UnDefType.NULL; | ||
} | ||
return new DecimalType(repeatDay); | ||
} | ||
|
||
public LocalTime getAlarmTime(int position) { | ||
final List<Integer> hours = this.hours; | ||
if (hours == null) { | ||
return null; | ||
} | ||
final List<Integer> minutes = this.minutes; | ||
if (minutes == null) { | ||
return null; | ||
} | ||
final Integer hour = hours.get(position - 1); | ||
final Integer minute = minutes.get(position - 1); | ||
return LocalTime.of(hour, minute); | ||
} | ||
|
||
public @NonNull State getAlarmTimeState(int position) { | ||
final LocalTime time = getAlarmTime(position); | ||
if (time == null) { | ||
return UnDefType.NULL; | ||
} | ||
final String alarmTimeString = String.format("%02d:%02d:00", time.getHour(), time.getMinute()); | ||
if (alarmTimeString == null) { | ||
return UnDefType.NULL; | ||
} | ||
return DateTimeType.valueOf(alarmTimeString); | ||
} | ||
} |
Oops, something went wrong.