get discovery running again
remove unwanted thing type
M pom.xml +1 -0
@@ 8,6 8,7 @@ 
     <groupId>org.openhab.addons.bundles</groupId>
     <artifactId>org.openhab.addons.reactor.bundles</artifactId>
     <version>3.0.1</version>
+    <relativePath>../openhab-addons/bundles</relativePath>
   </parent>
 
   <version>3.0.2-SNAPSHOT</version>

          
M src/main/java/org/openhab/binding/lutronmqtt/discovery/LutronMQTTDeviceDiscoveryService.java +28 -7
@@ 9,6 9,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.lutronmqtt.LutronMQTTBindingConstants;
 import org.openhab.binding.lutronmqtt.handler.DeviceStatusListener;
 import org.openhab.binding.lutronmqtt.handler.LutronMQTTHubHandler;

          
@@ 16,27 17,45 @@ import org.openhab.binding.lutronmqtt.mo
 import org.openhab.core.config.discovery.AbstractDiscoveryService;
 import org.openhab.core.config.discovery.DiscoveryResult;
 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
+import org.openhab.core.config.discovery.DiscoveryService;
 import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.thing.ThingUID;
-import org.osgi.service.component.annotations.Component;
+import org.openhab.core.thing.binding.ThingHandler;
+import org.openhab.core.thing.binding.ThingHandlerService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component(service = AbstractDiscoveryService.class, immediate = true, configurationPid = "binding.lutronmqtt", name = "org.openhab.binding.lutronmqtt.discovery.device")
-public class LutronMQTTDeviceDiscoveryService extends AbstractDiscoveryService implements DeviceStatusListener {
+public class LutronMQTTDeviceDiscoveryService extends AbstractDiscoveryService
+        implements ThingHandlerService, DiscoveryService, DeviceStatusListener {
     private final static int SEARCH_TIME = 60;
     private final Logger logger = LoggerFactory.getLogger(LutronMQTTDeviceDiscoveryService.class);
 
     private LutronMQTTHubHandler hubHandler;
+    private ThingUID bridgeUID;
 
-    public LutronMQTTDeviceDiscoveryService(LutronMQTTHubHandler hubHandler) {
+    public LutronMQTTDeviceDiscoveryService() {
         super(SEARCH_TIME);
-        this.hubHandler = hubHandler;
+        logger.warn("LutronMQTTDeviceDiscoveryService create");
+    }
+
+    @Override
+    public void setThingHandler(@Nullable ThingHandler handler) {
+        // logger.warn("SET THING HANDLER: " + handler);
+        if (handler instanceof LutronMQTTHubHandler) {
+            hubHandler = (LutronMQTTHubHandler) handler;
+            bridgeUID = handler.getThing().getUID();
+        }
+    }
+
+    @Override
+    public @Nullable ThingHandler getThingHandler() {
+        return hubHandler;
     }
 
     public void activate() {
         logger.warn("activate");
-        hubHandler.registerDeviceStatusListener(this);
+        if (hubHandler != null)
+            hubHandler.registerDeviceStatusListener(this);
         startScan();
     }
 

          
@@ 96,8 115,10 @@ public class LutronMQTTDeviceDiscoverySe
             logger.warn("discovery result " + d.getName() + " " + d.getObjectId());
 
             DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID)
+                    .withRepresentationProperty(LutronMQTTBindingConstants.PROPERTY_OBJECT_ID)
                     .withProperties(properties).withBridge(bridgeUID).withLabel(d.getName()).build();
 
+            logger.info("discovery result: " + discoveryResult);
             thingDiscovered(discoveryResult);
         } else {
             logger.debug("discovered unsupported device of name '{}' with objectId {}", d.getName(), d.getObjectId());

          
@@ 150,6 171,6 @@ public class LutronMQTTDeviceDiscoverySe
 
     @Override
     public void onDeviceStateChanged(LutronDevice light) {
-        // Do nothing
+        onDeviceFound(light);
     }
 }

          
M src/main/java/org/openhab/binding/lutronmqtt/discovery/LutronMQTTHubDiscoveryParticipant.java +4 -2
@@ 1,5 1,7 @@ 
 package org.openhab.binding.lutronmqtt.discovery;
 
+import static org.openhab.binding.lutronmqtt.LutronMQTTBindingConstants.PROPERTY_UUID;
+
 import java.util.*;
 
 import javax.jmdns.ServiceInfo;

          
@@ 81,10 83,10 @@ public class LutronMQTTHubDiscoveryParti
                 }
 
                 properties.put(LutronMQTTBindingConstants.PROPERTY_URL, "tcp://" + s + ":" + service.getPort());
-                properties.put(LutronMQTTBindingConstants.PROPERTY_UUID, u);
+                properties.put(PROPERTY_UUID, u);
 
                 return DiscoveryResultBuilder.create(uid).withProperties(properties)
-                        .withRepresentationProperty(uid.getId()).withLabel(service.getName() + " Lutron-MQTT Gateway")
+                        .withRepresentationProperty(PROPERTY_UUID).withLabel(service.getName() + " Lutron-MQTT Gateway")
                         .build();
             }
         }

          
M src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTHubHandler.java +46 -10
@@ 23,19 23,16 @@ import java.util.concurrent.TimeoutExcep
 
 import org.apache.commons.lang3.StringUtils;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lutronmqtt.discovery.LutronMQTTDeviceDiscoveryService;
 import org.openhab.binding.lutronmqtt.internal.LutronMQTTConfiguration;
 import org.openhab.binding.lutronmqtt.internal.LutronMqttBrokerConnectionConfig;
 import org.openhab.binding.lutronmqtt.model.LutronDevice;
 import org.openhab.core.config.core.Configuration;
 import org.openhab.core.io.transport.mqtt.*;
 import org.openhab.core.io.transport.mqtt.reconnect.PeriodicReconnectStrategy;
-import org.openhab.core.thing.Bridge;
-import org.openhab.core.thing.ChannelUID;
-import org.openhab.core.thing.Thing;
-import org.openhab.core.thing.ThingStatus;
-import org.openhab.core.thing.ThingStatusDetail;
-import org.openhab.core.thing.ThingUID;
+import org.openhab.core.thing.*;
 import org.openhab.core.thing.binding.BaseBridgeHandler;
+import org.openhab.core.thing.binding.ThingHandlerService;
 import org.openhab.core.types.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

          
@@ 60,6 57,9 @@ public class LutronMQTTHubHandler extend
     private LutronMQTTConfiguration config;
     private String token;
     private MqttBrokerConnection connection;
+    private boolean wasConnected;
+
+    // private LutronMQTTDeviceDiscoveryService discoveryService;
 
     private Gson gson = new Gson();
     private Map<Integer, LutronDevice> devicesByObjectId = new HashMap<>();

          
@@ 157,6 157,12 @@ public class LutronMQTTHubHandler extend
         }
     }
 
+    @Override
+    public Collection<Class<? extends ThingHandlerService>> getServices() {
+        logger.warn("GetServices Called!");
+        return Collections.singleton(LutronMQTTDeviceDiscoveryService.class);
+    }
+
     public void dispose() {
         try {
             if (this.connection != null) {

          
@@ 167,8 173,10 @@ public class LutronMQTTHubHandler extend
                         this.thing.getUID());
             }
         } catch (ExecutionException | TimeoutException | InterruptedException var2) {
+            this.logger.warn("Error while disposing", var2);
         }
 
+        this.goOffline(ThingStatusDetail.NONE, "Disposing");
         this.cancelJobs();
         super.dispose();
     }

          
@@ 210,13 218,18 @@ public class LutronMQTTHubHandler extend
     }
 
     private void setupSubscriptions() {
+        this.logger.error("Setting up subscriptions");
         try {
             if (!(Boolean) this.connection.subscribe("lutron/status", this).get(10L, TimeUnit.SECONDS)) {
-                this.logger.error("Unable to subscribe to lutron/status. Restarting.");
+                this.logger.error("Unable to subscribe to lutron/status.");
+            } else {
+                this.logger.info("Subscription to lutron/status succeeded.");
             }
 
             if (!(Boolean) this.connection.subscribe("lutron/events", this).get()) {
-                this.logger.error("Unable to subscribe to lutron/events. Restarting.");
+                this.logger.error("Unable to subscribe to lutron/events.");
+            } else {
+                this.logger.info("Subscription to lutron/events succeeded.");
             }
 
             this.connection.subscribe("lutron/remote", this).whenComplete(this::subscribeCompleted);

          
@@ 238,8 251,10 @@ public class LutronMQTTHubHandler extend
             this.logger.error("Unable to subscribe.");
         } else {
             this.cancelJobs();
+
             this.allItemsJob = this.scheduler.schedule(new Runnable() {
                 public void run() {
+
                     LutronMQTTHubHandler.this.requestAllItems();
                 }
             }, 5L, TimeUnit.SECONDS);

          
@@ 269,6 284,15 @@ public class LutronMQTTHubHandler extend
         updateStatus(ThingStatus.ONLINE);
     }
 
+    @Override
+    public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
+        super.bridgeStatusChanged(bridgeStatusInfo);
+        if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
+            // if (discoveryService != null)
+            // discoveryService.deactivate();
+        }
+    }
+
     protected void goOffline(ThingStatusDetail detail, String reason) {
         updateStatus(ThingStatus.OFFLINE, detail, reason);
         if (onlineTimeout != null)

          
@@ 310,6 334,14 @@ public class LutronMQTTHubHandler extend
                             // TODO copy properties to new device
                         }
                         devicesByObjectId.put(device.getObjectId(), device);
+
+                        // if (discoveryService != null)
+                        // discoveryService.startScan();
+                        // else {
+                        // if (discoveryService == null)
+                        // logger.error("No DeviceDiscoveryService!");
+                        // }
+
                         scheduler.schedule(new Runnable() {
                             @Override
                             public void run() {

          
@@ 411,9 443,13 @@ public class LutronMQTTHubHandler extend
 
     public void connectionStateChanged(MqttConnectionState mqttConnectionState, @Nullable Throwable throwable) {
         if (mqttConnectionState == MqttConnectionState.DISCONNECTED) {
-            this.goOffline(ThingStatusDetail.BRIDGE_OFFLINE, throwable.getMessage());
-            this.logger.warn("Lost connection to MQTT server. Should retry", throwable);
+            if (wasConnected) {
+                this.goOffline(ThingStatusDetail.BRIDGE_OFFLINE, (throwable != null) ? throwable.getMessage() : null);
+                this.logger.warn("Lost connection to MQTT server. Should retry", throwable);
+            }
+            wasConnected = false;
         } else if (mqttConnectionState == MqttConnectionState.CONNECTED) {
+            wasConnected = true;
             this.scheduler.schedule(new Runnable() {
                 public void run() {
                     LutronMQTTHubHandler.this.setupSubscriptions();

          
M src/main/java/org/openhab/binding/lutronmqtt/internal/LutronMQTTHandlerFactory.java +11 -9
@@ 21,7 21,6 @@ import org.eclipse.jdt.annotation.Nullab
 import org.openhab.binding.lutronmqtt.LutronMQTTBindingConstants;
 import org.openhab.binding.lutronmqtt.discovery.LutronMQTTDeviceDiscoveryService;
 import org.openhab.binding.lutronmqtt.handler.*;
-import org.openhab.core.config.discovery.DiscoveryService;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingTypeUID;

          
@@ 58,6 57,7 @@ public class LutronMQTTHandlerFactory ex
     @Nullable
     protected ThingHandler createHandler(Thing thing) {
 
+        logger.warn("createHandler");
         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
 
         logger.warn("Creating a handler for " + thing.getThingTypeUID() + ", " + thing.getLabel());

          
@@ 65,7 65,6 @@ public class LutronMQTTHandlerFactory ex
         if (thingTypeUID.equals(THING_TYPE_MQTTHUB)) {
             logger.warn("Creating hub handler");
             LutronMQTTHubHandler handler = new LutronMQTTHubHandler((Bridge) thing);
-            registerDeviceDiscoveryService(handler);
             return handler;
         } else if (thingTypeUID.equals(THING_TYPE_REMOTE)) {
             LutronMQTTRemoteHandler handler = new LutronMQTTRemoteHandler(thing);

          
@@ 74,6 73,7 @@ public class LutronMQTTHandlerFactory ex
             LutronMQTTDimmableLightHandler handler = new LutronMQTTDimmableLightHandler(thing);
             return handler;
         } else if (thingTypeUID.equals(THING_TYPE_LIGHT)) {
+            logger.warn("Creating light handler");
             LutronMQTTLightHandler handler = new LutronMQTTLightHandler(thing);
             return handler;
         } else if (thingTypeUID.equals(THING_TYPE_VARIABLE_FAN)) {

          
@@ 84,15 84,17 @@ public class LutronMQTTHandlerFactory ex
             return handler;
         }
 
+        logger.warn("uh oh, falling through");
+
         return null;
     }
-
-    private synchronized void registerDeviceDiscoveryService(LutronMQTTHubHandler hubHandler) {
-        LutronMQTTDeviceDiscoveryService discoveryService = new LutronMQTTDeviceDiscoveryService(hubHandler);
-        discoveryService.activate();
-        this.discoveryServiceRegs.put(hubHandler.getThing().getUID(), bundleContext
-                .registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<String, Object>()));
-    }
+    //
+    // private synchronized void registerDeviceDiscoveryService(LutronMQTTHubHandler hubHandler) {
+    // LutronMQTTDeviceDiscoveryService discoveryService = new LutronMQTTDeviceDiscoveryService(hubHandler);
+    // discoveryService.activate();
+    // this.discoveryServiceRegs.put(hubHandler.getThing().getUID(), bundleContext
+    // .registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<String, Object>()));
+    // }
 
     @Override
     protected synchronized void removeHandler(ThingHandler thingHandler) {

          
M src/main/resources/ESH-INF/binding/binding.xml +2 -2
@@ 1,7 1,7 @@ 
 <?xml version="1.0" encoding="UTF-8"?>
 <binding:binding id="lutronmqtt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0"
-	xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd">
+	xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
+	xsi:schemaLocation="http://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
 
 	<name>LutronMQTT Binding</name>
 	<description>This is the binding for LutronMQTT.</description>

          
M src/main/resources/ESH-INF/thing/thing-types.xml +2 -22
@@ 1,8 1,8 @@ 
 <?xml version="1.0" encoding="UTF-8"?>
 <thing:thing-descriptions bindingId="lutronmqtt"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0"
-	xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd">
+	xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
+	xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
 	<thing-type id="dimmableLight">
 		<supported-bridge-type-refs>

          
@@ 122,24 122,4 @@ 
 		<description>Turn the item on or off</description>
 		<category>VariableFan</category>
 	</channel-type>
-
-
-	<!-- Sample Thing Type -->
-	<thing-type id="sample">
-		<label>LutronMQTT Binding Thing</label>
-		<description>Sample thing for LutronMQTT Binding</description>
-
-		<channels>
-			<channel id="channel1" typeId="sample-channel"/>
-		</channels>
-
-		<config-description>
-			<parameter name="config1" type="text" required="true">
-				<label>Sample parameter</label>
-				<description>This is a sample text configuration parameter.</description>
-			</parameter>
-		</config-description>
-
-	</thing-type>
-
 </thing:thing-descriptions>