2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.homeassistant.internal;
15 import java.util.Collections;
16 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.mqtt.homeassistant.internal.handler.HomeAssistantThingHandler;
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.
27 * @author David Graeff - Initial contribution
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";
35 * hint: cannot be final, or <code>getConfigAs</code> will not work.
36 * The MQTT prefix topic
38 public String basetopic;
41 * hint: cannot be final, or <code>getConfigAs</code> will not work.
42 * List of configuration topics.
45 * Each topic is gets the base topic prepended.
51 * <code>component</code> (e.g. "switch", "light", ...)
54 * <code>node_id</code> (optional)
57 * <code>object_id</code> This is only to allow for separate topics for each device
67 public List<String> topics;
69 public HandlerConfiguration() {
70 this(DEFAULT_BASETOPIC, Collections.emptyList());
73 public HandlerConfiguration(String basetopic, List<String> topics) {
75 this.basetopic = basetopic;
80 * Add the <code>basetopic</code> and <code>objectid</code> to the properties.
82 * @param properties properties
83 * @return the modified properties
85 public <T extends Map<String, Object>> T appendToProperties(T properties) {
86 properties.put(PROPERTY_BASETOPIC, basetopic);
87 properties.put(PROPERTY_TOPICS, topics);