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.lametrictime.internal.api.dto;
15 import java.time.LocalTime;
16 import java.time.format.DateTimeFormatter;
17 import java.util.SortedMap;
18 import java.util.TreeMap;
20 import org.openhab.binding.lametrictime.internal.api.local.dto.BooleanParameter;
21 import org.openhab.binding.lametrictime.internal.api.local.dto.Parameter;
22 import org.openhab.binding.lametrictime.internal.api.local.dto.StringParameter;
23 import org.openhab.binding.lametrictime.internal.api.local.dto.UpdateAction;
26 * Implementation class for the ClockApp.
28 * @author Gregory Moyer - Initial contribution
30 public class ClockApp extends CoreApplication {
31 private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
33 private static final String NAME = "com.lametric.clock";
35 private static final String ACTION_ALARM = "clock.alarm";
37 private static final String PARAMETER_ENABLED = "enabled";
38 private static final String PARAMETER_TIME = "time";
39 private static final String PARAMETER_WAKE_WITH_RADIO = "wake_with_radio";
45 public CoreAction setAlarm(Boolean enabled, LocalTime time, Boolean wakeWithRadio) {
46 SortedMap<String, Parameter> parameters = new TreeMap<>();
48 if (enabled != null) {
49 parameters.put(PARAMETER_ENABLED, new BooleanParameter().withValue(enabled));
53 parameters.put(PARAMETER_TIME, new StringParameter().withValue(time.format(TIME_FORMATTER)));
56 if (wakeWithRadio != null) {
57 parameters.put(PARAMETER_WAKE_WITH_RADIO, new BooleanParameter().withValue(wakeWithRadio));
60 return new CoreAction(this, new UpdateAction().withId(ACTION_ALARM).withParameters(parameters));
63 public CoreAction stopAlarm() {
64 SortedMap<String, Parameter> parameters = new TreeMap<>();
65 parameters.put(PARAMETER_ENABLED, new BooleanParameter().withValue(false));
67 return new CoreAction(this, new UpdateAction().withId(ACTION_ALARM).withParameters(parameters));