]> git.basschouten.com Git - openhab-addons.git/blob
d7508ad37f08386b5c5263c2127f6ca52be2e332
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.homeassistant.internal;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.mqtt.homeassistant.internal.handler.HomeAssistantThingHandler;
21
22 /**
23  * The {@link HomeAssistantThingHandler} manages Things that are responsible for
24  * HomeAssistant MQTT components.
25  * This class contains the necessary configuration for such a Thing handler.
26  *
27  * @author David Graeff - Initial contribution
28  */
29 @NonNullByDefault
30 public class HandlerConfiguration {
31     /**
32      * hint: cannot be final, or <code>getConfigAs</code> will not work.
33      * The MQTT prefix topic
34      */
35     public String basetopic;
36
37     /**
38      * hint: cannot be final, or <code>getConfigAs</code> will not work.
39      * List of configuration topics.
40      * <ul>
41      * <li>
42      * Each topic is gets the base topic prepended.
43      * </li>
44      * <li>
45      * each topic has:
46      * <ol>
47      * <li>
48      * <code>component</code> (e.g. "switch", "light", ...)
49      * </li>
50      * <li>
51      * <code>node_id</code> (optional)
52      * </li>
53      * <li>
54      * <code>object_id</code> This is only to allow for separate topics for each device
55      * </li>
56      * <li>
57      * "config"
58      * </li>
59      * </ol>
60      * </li>
61      * </ul>
62      *
63      */
64     public List<String> topics;
65
66     public HandlerConfiguration() {
67         this("homeassistant", Collections.emptyList());
68     }
69
70     public HandlerConfiguration(String basetopic, List<String> topics) {
71         super();
72         this.basetopic = basetopic;
73         this.topics = topics;
74     }
75
76     /**
77      * Add the <code>basetopic</code> and <code>objectid</code> to the properties.
78      *
79      * @param properties
80      * @return the modified properties
81      */
82     public <T extends Map<String, Object>> T appendToProperties(T properties) {
83         properties.put("basetopic", basetopic);
84         properties.put("topics", topics);
85         return properties;
86     }
87 }