]> git.basschouten.com Git - openhab-addons.git/blob
5b5239a485cd973cf04fbaa6559a01d2593c0c53
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mqtt.homie.internal.handler;
14
15 import static org.openhab.binding.mqtt.homie.generic.internal.MqttBindingConstants.*;
16
17 import java.math.BigDecimal;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.thing.Channel;
25 import org.openhab.core.thing.ThingUID;
26 import org.openhab.core.thing.type.ChannelTypeUID;
27
28 /**
29  * Static test definitions, like thing, bridge and channel definitions
30  *
31  * @author David Graeff - Initial contribution
32  */
33 public class ThingChannelConstants {
34     // Common ThingUID and ChannelUIDs
35     public static final ThingUID TEST_HOMIE_THING = new ThingUID(HOMIE300_MQTT_THING, "device123");
36
37     public static final ChannelTypeUID UNKNOWN_CHANNEL = new ChannelTypeUID(BINDING_ID, "unknown");
38
39     public static final String JSON_PATH_JSON = "{ \"device\": { \"status\": { \"temperature\": 23.2 }}}";
40     public static final String JSON_PATH_PATTERN = "$.device.status.temperature";
41
42     public static final List<Channel> THING_CHANNEL_LIST = new ArrayList<>();
43     public static final List<Channel> THING_CHANNEL_LIST_WITH_JSON = new ArrayList<>();
44
45     static Configuration textConfiguration() {
46         Map<String, Object> data = new HashMap<>();
47         data.put("stateTopic", "test/state");
48         data.put("commandTopic", "test/command");
49         return new Configuration(data);
50     }
51
52     static Configuration textConfigurationWithJson() {
53         Map<String, Object> data = new HashMap<>();
54         data.put("stateTopic", "test/state");
55         data.put("commandTopic", "test/command");
56         data.put("transformationPattern", "JSONPATH:" + JSON_PATH_PATTERN);
57         return new Configuration(data);
58     }
59
60     private static Configuration numberConfiguration() {
61         Map<String, Object> data = new HashMap<>();
62         data.put("stateTopic", "test/state");
63         data.put("commandTopic", "test/command");
64         data.put("min", BigDecimal.valueOf(1));
65         data.put("max", BigDecimal.valueOf(99));
66         data.put("step", BigDecimal.valueOf(2));
67         data.put("isDecimal", true);
68         return new Configuration(data);
69     }
70
71     private static Configuration percentageConfiguration() {
72         Map<String, Object> data = new HashMap<>();
73         data.put("stateTopic", "test/state");
74         data.put("commandTopic", "test/command");
75         data.put("on", "ON");
76         data.put("off", "OFF");
77         return new Configuration(data);
78     }
79
80     private static Configuration onoffConfiguration() {
81         Map<String, Object> data = new HashMap<>();
82         data.put("stateTopic", "test/state");
83         data.put("commandTopic", "test/command");
84         data.put("on", "ON");
85         data.put("off", "OFF");
86         data.put("inverse", true);
87         return new Configuration(data);
88     }
89 }