001package jmri.jmrix.mqtt.logixng;
002
003import jmri.jmrix.mqtt.MqttSystemConnectionMemo;
004
005import java.util.List;
006
007import jmri.jmrit.logixng.Category;
008
009/**
010 * Defines the category MQTT
011 *
012 * @author Daniel Bergqvist Copyright 2022
013 */
014public final class CategoryMqtt extends Category {
015
016    /**
017     * A item on the layout, for example turnout, sensor and signal mast.
018     */
019    public static final CategoryMqtt MQTT = new CategoryMqtt();
020
021
022    public CategoryMqtt() {
023        super("MQTT", Bundle.getMessage("MenuMQTT"), 300);
024    }
025
026    public static void registerCategory() {
027        // We don't want to add these classes if we don't have a MQTT connection
028        if (hasMQTT() && !Category.values().contains(MQTT)) {
029            Category.registerCategory(MQTT);
030        }
031    }
032
033    /**
034     * Do we have a MQTT connection?
035     * @return true if we have MQTT, false otherwise
036     */
037    public static boolean hasMQTT() {
038        List<MqttSystemConnectionMemo> list = jmri.InstanceManager.getList(MqttSystemConnectionMemo.class);
039
040        // We have at least one LocoNet connection if the list is not empty
041        return !list.isEmpty();
042    }
043
044}