]> git.basschouten.com Git - openhab-addons.git/blob
972df76d66766bb643040a1308320adab177c620
[openhab-addons.git] /
1 /**
2  * Copyright 2017-2018 Gregory Moyer and contributors.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openhab.binding.lametrictime.api.model;
17
18 import java.util.SortedMap;
19 import java.util.TreeMap;
20
21 import org.openhab.binding.lametrictime.api.local.model.BooleanParameter;
22 import org.openhab.binding.lametrictime.api.local.model.IntegerParameter;
23 import org.openhab.binding.lametrictime.api.local.model.Parameter;
24 import org.openhab.binding.lametrictime.api.local.model.UpdateAction;
25
26 public class CountdownApp extends CoreApplication
27 {
28     private static final String NAME = "com.lametric.countdown";
29
30     private static final String ACTION_CONFIGURE = "countdown.configure";
31     private static final String ACTION_PAUSE = "countdown.pause";
32     private static final String ACTION_RESET = "countdown.reset";
33     private static final String ACTION_START = "countdown.start";
34
35     private static final String PARAMETER_DURATION = "duration";
36     private static final String PARAMETER_START_NOW = "start_now";
37
38     public CountdownApp()
39     {
40         super(NAME);
41     }
42
43     public CoreAction configure(int duration, boolean startNow)
44     {
45         SortedMap<String, Parameter> parameters = new TreeMap<>();
46         parameters.put(PARAMETER_DURATION, new IntegerParameter().withValue(duration));
47         parameters.put(PARAMETER_START_NOW, new BooleanParameter().withValue(startNow));
48
49         return new CoreAction(this,
50                               new UpdateAction().withId(ACTION_CONFIGURE)
51                                                 .withParameters(parameters));
52     }
53
54     public CoreAction pause()
55     {
56         return new CoreAction(this, new UpdateAction().withId(ACTION_PAUSE));
57     }
58
59     public CoreAction reset()
60     {
61         return new CoreAction(this, new UpdateAction().withId(ACTION_RESET));
62     }
63
64     public CoreAction start()
65     {
66         return new CoreAction(this, new UpdateAction().withId(ACTION_START));
67     }
68 }