]> git.basschouten.com Git - openhab-addons.git/blob
a31aab4b74b280244f3883c20cf36cb8f99451a5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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     public static final String PROPERTY_BASETOPIC = "basetopic";
32     public static final String PROPERTY_TOPICS = "topics";
33     public static final String DEFAULT_BASETOPIC = "homeassistant";
34     /**
35      * hint: cannot be final, or <code>getConfigAs</code> will not work.
36      * The MQTT prefix topic
37      */
38     public String basetopic;
39
40     /**
41      * hint: cannot be final, or <code>getConfigAs</code> will not work.
42      * List of configuration topics.
43      * <ul>
44      * <li>
45      * Each topic is gets the base topic prepended.
46      * </li>
47      * <li>
48      * each topic has:
49      * <ol>
50      * <li>
51      * <code>component</code> (e.g. "switch", "light", ...)
52      * </li>
53      * <li>
54      * <code>node_id</code> (optional)
55      * </li>
56      * <li>
57      * <code>object_id</code> This is only to allow for separate topics for each device
58      * </li>
59      * <li>
60      * "config"
61      * </li>
62      * </ol>
63      * </li>
64      * </ul>
65      *
66      */
67     public List<String> topics;
68
69     public HandlerConfiguration() {
70         this(DEFAULT_BASETOPIC, Collections.emptyList());
71     }
72
73     public HandlerConfiguration(String basetopic, List<String> topics) {
74         super();
75         this.basetopic = basetopic;
76         this.topics = topics;
77     }
78
79     /**
80      * Add the <code>basetopic</code> and <code>objectid</code> to the properties.
81      *
82      * @param properties properties
83      * @return the modified properties
84      */
85     public <T extends Map<String, Object>> T appendToProperties(T properties) {
86         properties.put(PROPERTY_BASETOPIC, basetopic);
87         properties.put(PROPERTY_TOPICS, topics);
88         return properties;
89     }
90 }