2 * Copyright 2017-2018 Gregory Moyer and contributors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.lametrictime.api.model;
18 import java.time.LocalTime;
19 import java.time.format.DateTimeFormatter;
20 import java.util.SortedMap;
21 import java.util.TreeMap;
23 import org.openhab.binding.lametrictime.api.local.model.BooleanParameter;
24 import org.openhab.binding.lametrictime.api.local.model.Parameter;
25 import org.openhab.binding.lametrictime.api.local.model.StringParameter;
26 import org.openhab.binding.lametrictime.api.local.model.UpdateAction;
28 public class ClockApp extends CoreApplication
30 private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
32 private static final String NAME = "com.lametric.clock";
34 private static final String ACTION_ALARM = "clock.alarm";
36 private static final String PARAMETER_ENABLED = "enabled";
37 private static final String PARAMETER_TIME = "time";
38 private static final String PARAMETER_WAKE_WITH_RADIO = "wake_with_radio";
45 public CoreAction setAlarm(Boolean enabled, LocalTime time, Boolean wakeWithRadio)
47 SortedMap<String, Parameter> parameters = new TreeMap<>();
51 parameters.put(PARAMETER_ENABLED, new BooleanParameter().withValue(enabled));
56 parameters.put(PARAMETER_TIME,
57 new StringParameter().withValue(time.format(TIME_FORMATTER)));
60 if (wakeWithRadio != null)
62 parameters.put(PARAMETER_WAKE_WITH_RADIO,
63 new BooleanParameter().withValue(wakeWithRadio));
66 return new CoreAction(this,
67 new UpdateAction().withId(ACTION_ALARM).withParameters(parameters));
70 public CoreAction stopAlarm()
72 SortedMap<String, Parameter> parameters = new TreeMap<>();
73 parameters.put(PARAMETER_ENABLED, new BooleanParameter().withValue(false));
75 return new CoreAction(this,
76 new UpdateAction().withId(ACTION_ALARM).withParameters(parameters));