2 * Copyright (c) 2010-2024 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.generic;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * A {@link ChannelConfig} is required for the {@link ChannelState} object.
20 * For easily creating a configuration, use this builder.
22 * @author David Graeff - Initial contribution
25 public class ChannelConfigBuilder {
26 private final ChannelConfig config = new ChannelConfig();
28 private ChannelConfigBuilder() {
31 public static ChannelConfigBuilder create() {
32 return new ChannelConfigBuilder();
35 public static ChannelConfigBuilder create(@Nullable String stateTopic, @Nullable String commandTopic) {
36 return new ChannelConfigBuilder().withStateTopic(stateTopic).withCommandTopic(commandTopic);
39 public ChannelConfig build() {
43 public ChannelConfigBuilder withFormatter(String formatter) {
44 config.formatBeforePublish = formatter;
48 public ChannelConfigBuilder withStateTopic(@Nullable String topic) {
50 config.stateTopic = topic;
55 public ChannelConfigBuilder withCommandTopic(@Nullable String topic) {
57 config.commandTopic = topic;
62 public ChannelConfigBuilder withStopCommandTopic(@Nullable String topic) {
64 config.stopCommandTopic = topic;
69 public ChannelConfigBuilder withRetain(boolean retain) {
70 config.retained = retain;
74 public ChannelConfigBuilder withQos(@Nullable Integer qos) {
79 public ChannelConfigBuilder makeTrigger(boolean trigger) {
80 config.trigger = trigger;