]> git.basschouten.com Git - openhab-addons.git/commitdiff
[ecobee] Rework discovery (#9522)
authorMark Hilbush <mark@hilbush.com>
Wed, 30 Dec 2020 00:18:42 +0000 (19:18 -0500)
committerGitHub <noreply@github.com>
Wed, 30 Dec 2020 00:18:42 +0000 (16:18 -0800)
* Rework discovery
* Consolidate discovery into one service

Signed-off-by: Mark Hilbush <mark@hilbush.com>
bundles/org.openhab.binding.ecobee/README.md
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/EcobeeBindingConstants.java
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/config/EcobeeAccountConfiguration.java
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java [new file with mode: 0644]
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/SensorDiscoveryService.java [deleted file]
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/ThermostatDiscoveryService.java [deleted file]
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeAccountBridgeHandler.java
bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java
bundles/org.openhab.binding.ecobee/src/main/resources/OH-INF/config/config.xml

index 8ae34c50f54c3e371ec9d67ae775bbef5a96dc52..d7a450b1b4f2dcbd246703f552f0f3456e8414e6 100644 (file)
@@ -107,7 +107,6 @@ The following configuration parameters are available on the Ecobee Account:
 | refreshIntervalQuick    | Integer    | Required         | Specifies the interval in seconds with which the Ecobee data will be updated after sending an update or executing a function. |
 | apiTimeout              | Integer    | Required         | Time in seconds to allow an API request against the Ecobee servers to complete. |
 | discoveryEnabled        | Switch     | Required         | Specifies whether the binding should auto-discover thermostats and remote sensors. |
-| discoveryInterval       | Integer    | Optional         | Specifies time interval in seconds in which the binding will attempt to discover thermostats. |
 
 ### Ecobee Thermostat
 
index d08a4f960135d32db7ae711e1c2baa879ff07e7f..d4c35cbc103042171bb5fbfd688534d1031f3629 100644 (file)
@@ -59,10 +59,19 @@ public class EcobeeBindingConstants {
     public static final Set<ThingTypeUID> SUPPORTED_SENSOR_THING_TYPES_UIDS = Collections
             .unmodifiableSet(Stream.of(UID_SENSOR_THING).collect(Collectors.toSet()));
 
+    // Collection of thermostat and sensor thing types
+    public static final Set<ThingTypeUID> SUPPORTED_THERMOSTAT_AND_SENSOR_THING_TYPES_UIDS = Stream
+            .concat(SUPPORTED_THERMOSTAT_BRIDGE_THING_TYPES_UIDS.stream(), SUPPORTED_SENSOR_THING_TYPES_UIDS.stream())
+            .collect(Collectors.toSet());
+
     // Collection of all supported thing types
     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
             Stream.of(UID_ACCOUNT_BRIDGE, UID_THERMOSTAT_BRIDGE, UID_SENSOR_THING).collect(Collectors.toSet()));
 
+    // Background discovery frequency
+    public static final int DISCOVERY_INTERVAL_SECONDS = 300;
+    public static final int DISCOVERY_INITIAL_DELAY_SECONDS = 10;
+
     // Thermostat bridge and remote sensor thing config parameters
     public static final String CONFIG_THERMOSTAT_ID = "thermostatId";
     public static final String CONFIG_SENSOR_ID = "sensorId";
index 72d7f9888b4622a01134afa18813e00648ef948b..63ebf84cc2f1939c99423802617f3dc237a277bd 100644 (file)
@@ -48,9 +48,4 @@ public class EcobeeAccountConfiguration {
      * Enable/disable automatic discovery
      */
     public @Nullable Boolean discoveryEnabled;
-
-    /**
-     * Interval with which to run the thermostat discovery process
-     */
-    public @Nullable Integer discoveryInterval;
 }
diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java
new file mode 100644 (file)
index 0000000..034752c
--- /dev/null
@@ -0,0 +1,185 @@
+/**
+ * Copyright (c) 2010-2020 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.ecobee.internal.discovery;
+
+import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorDTO;
+import org.openhab.binding.ecobee.internal.dto.thermostat.ThermostatDTO;
+import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
+import org.openhab.binding.ecobee.internal.handler.EcobeeThermostatBridgeHandler;
+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.thing.Thing;
+import org.openhab.core.thing.ThingStatus;
+import org.openhab.core.thing.ThingTypeUID;
+import org.openhab.core.thing.ThingUID;
+import org.openhab.core.thing.binding.ThingHandler;
+import org.openhab.core.thing.binding.ThingHandlerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The {@link EcobeeDiscoveryService} is responsible for discovering the Ecobee
+ * thermostats that are associated with the Ecobee Account, as well as the sensors
+ * are associated with the Ecobee thermostats.
+ *
+ * @author Mark Hilbush - Initial contribution
+ */
+@NonNullByDefault
+public class EcobeeDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService {
+
+    private final Logger logger = LoggerFactory.getLogger(EcobeeDiscoveryService.class);
+
+    private @NonNullByDefault({}) EcobeeAccountBridgeHandler bridgeHandler;
+
+    private @Nullable Future<?> discoveryJob;
+
+    public EcobeeDiscoveryService() {
+        super(SUPPORTED_THERMOSTAT_AND_SENSOR_THING_TYPES_UIDS, 8, true);
+    }
+
+    @Override
+    public void setThingHandler(@Nullable ThingHandler handler) {
+        if (handler instanceof EcobeeAccountBridgeHandler) {
+            this.bridgeHandler = (EcobeeAccountBridgeHandler) handler;
+        }
+    }
+
+    @Override
+    public @Nullable ThingHandler getThingHandler() {
+        return bridgeHandler;
+    }
+
+    @Override
+    public void activate() {
+        super.activate(null);
+    }
+
+    @Override
+    public void deactivate() {
+        super.deactivate();
+    }
+
+    @Override
+    public Set<ThingTypeUID> getSupportedThingTypes() {
+        return SUPPORTED_THERMOSTAT_AND_SENSOR_THING_TYPES_UIDS;
+    }
+
+    @Override
+    protected void startBackgroundDiscovery() {
+        logger.debug("EcobeeDiscovery: Starting background discovery job");
+        Future<?> localDiscoveryJob = discoveryJob;
+        if (localDiscoveryJob == null || localDiscoveryJob.isCancelled()) {
+            discoveryJob = scheduler.scheduleWithFixedDelay(this::backgroundDiscover, DISCOVERY_INITIAL_DELAY_SECONDS,
+                    DISCOVERY_INTERVAL_SECONDS, TimeUnit.SECONDS);
+        }
+    }
+
+    @Override
+    protected void stopBackgroundDiscovery() {
+        logger.debug("EcobeeDiscovery: Stopping background discovery job");
+        Future<?> localDiscoveryJob = discoveryJob;
+        if (localDiscoveryJob != null) {
+            localDiscoveryJob.cancel(true);
+            discoveryJob = null;
+        }
+    }
+
+    @Override
+    public void startScan() {
+        logger.debug("EcobeeDiscovery: Starting discovery scan");
+        discover();
+    }
+
+    private void backgroundDiscover() {
+        if (!bridgeHandler.isBackgroundDiscoveryEnabled()) {
+            return;
+        }
+        discover();
+    }
+
+    private void discover() {
+        if (bridgeHandler.getThing().getStatus() != ThingStatus.ONLINE) {
+            logger.debug("EcobeeDiscovery: Skipping discovery because Account Bridge thing is not ONLINE");
+            return;
+        }
+        logger.debug("EcobeeDiscovery: Discovering Ecobee devices");
+        discoverThermostats();
+        discoverSensors();
+    }
+
+    private synchronized void discoverThermostats() {
+        logger.debug("EcobeeDiscovery: Discovering thermostats");
+        for (ThermostatDTO thermostat : bridgeHandler.getRegisteredThermostats()) {
+            String name = thermostat.name;
+            String identifier = thermostat.identifier;
+            if (identifier != null && name != null) {
+                ThingUID thingUID = new ThingUID(UID_THERMOSTAT_BRIDGE, bridgeHandler.getThing().getUID(), identifier);
+                thingDiscovered(createThermostatDiscoveryResult(thingUID, identifier, name));
+                logger.debug("EcobeeDiscovery: Thermostat '{}' and name '{}' added with UID '{}'", identifier, name,
+                        thingUID);
+            }
+        }
+    }
+
+    private DiscoveryResult createThermostatDiscoveryResult(ThingUID thermostatUID, String identifier, String name) {
+        Map<String, Object> properties = new HashMap<>();
+        properties.put(CONFIG_THERMOSTAT_ID, identifier);
+        return DiscoveryResultBuilder.create(thermostatUID).withProperties(properties)
+                .withRepresentationProperty(CONFIG_THERMOSTAT_ID).withBridge(bridgeHandler.getThing().getUID())
+                .withLabel(String.format("Ecobee Thermostat %s", name)).build();
+    }
+
+    private synchronized void discoverSensors() {
+        List<Thing> thermostatThings = bridgeHandler.getThing().getThings();
+        if (thermostatThings.size() == 0) {
+            logger.debug("EcobeeDiscovery: Skipping sensor discovery because there are no thermostat things");
+            return;
+        }
+        logger.debug("EcobeeDiscovery: Discovering sensors");
+        for (Thing thermostat : thermostatThings) {
+            EcobeeThermostatBridgeHandler thermostatHandler = (EcobeeThermostatBridgeHandler) thermostat.getHandler();
+            if (thermostatHandler != null) {
+                String thermostatId = thermostatHandler.getThermostatId();
+                logger.debug("EcobeeDiscovery: Discovering sensors for thermostat '{}'", thermostatId);
+                for (RemoteSensorDTO sensor : thermostatHandler.getSensors()) {
+                    ThingUID bridgeUID = thermostatHandler.getThing().getUID();
+                    ThingUID sensorUID = new ThingUID(UID_SENSOR_THING, bridgeUID, sensor.id.replace(":", "-"));
+                    thingDiscovered(createSensorDiscoveryResult(sensorUID, bridgeUID, sensor));
+                    logger.debug("EcobeeDiscovery: Sensor for '{}' with id '{}' and name '{}' added with UID '{}'",
+                            thermostatId, sensor.id, sensor.name, sensorUID);
+                }
+            }
+        }
+    }
+
+    private DiscoveryResult createSensorDiscoveryResult(ThingUID sensorUID, ThingUID bridgeUID,
+            RemoteSensorDTO sensor) {
+        Map<String, Object> properties = new HashMap<>();
+        properties.put(CONFIG_SENSOR_ID, sensor.id);
+        return DiscoveryResultBuilder.create(sensorUID).withProperties(properties)
+                .withRepresentationProperty(CONFIG_SENSOR_ID).withBridge(bridgeUID)
+                .withLabel(String.format("Ecobee Sensor %s", sensor.name)).build();
+    }
+}
diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/SensorDiscoveryService.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/SensorDiscoveryService.java
deleted file mode 100644 (file)
index 1e975eb..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright (c) 2010-2020 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.ecobee.internal.discovery;
-
-import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorDTO;
-import org.openhab.binding.ecobee.internal.handler.EcobeeThermostatBridgeHandler;
-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.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.binding.ThingHandlerService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The {@link SensorDiscoveryService} is responsible for discovering the Ecobee
- * sensors that are assigned to a thermostat.
- *
- * @author Mark Hilbush - Initial contribution
- */
-@NonNullByDefault
-public class SensorDiscoveryService extends AbstractDiscoveryService implements DiscoveryService, ThingHandlerService {
-
-    private final Logger logger = LoggerFactory.getLogger(SensorDiscoveryService.class);
-
-    private @NonNullByDefault({}) EcobeeThermostatBridgeHandler bridgeHandler;
-
-    public SensorDiscoveryService() {
-        super(30);
-    }
-
-    @Override
-    public void setThingHandler(@Nullable ThingHandler handler) {
-        if (handler instanceof EcobeeThermostatBridgeHandler) {
-            ((EcobeeThermostatBridgeHandler) handler).setDiscoveryService(this);
-            bridgeHandler = (EcobeeThermostatBridgeHandler) handler;
-        }
-    }
-
-    @Override
-    public @Nullable ThingHandler getThingHandler() {
-        return bridgeHandler;
-    }
-
-    @Override
-    public void activate() {
-        logger.debug("SensorDiscovery: Activating Ecobee sensor discovery service");
-    }
-
-    @Override
-    public void deactivate() {
-        logger.debug("SensorDiscovery: Deactivating Ecobee sensor discovery service");
-    }
-
-    @Override
-    public Set<ThingTypeUID> getSupportedThingTypes() {
-        return SUPPORTED_SENSOR_THING_TYPES_UIDS;
-    }
-
-    @Override
-    public void startBackgroundDiscovery() {
-        logger.debug("SensorDiscovery: Performing background discovery scan for {}", bridgeHandler.getThing().getUID());
-        discoverSensors();
-    }
-
-    @Override
-    public void startScan() {
-        logger.debug("SensorDiscovery: Starting discovery scan for {}", bridgeHandler.getThing().getUID());
-        discoverSensors();
-    }
-
-    @Override
-    public synchronized void abortScan() {
-        super.abortScan();
-    }
-
-    @Override
-    protected synchronized void stopScan() {
-        super.stopScan();
-    }
-
-    private String buildLabel(String name) {
-        return String.format("Ecobee Sensor %s", name);
-    }
-
-    private synchronized void discoverSensors() {
-        for (RemoteSensorDTO sensor : bridgeHandler.getSensors()) {
-            ThingUID bridgeUID = bridgeHandler.getThing().getUID();
-            ThingUID sensorUID = new ThingUID(UID_SENSOR_THING, bridgeUID, sensor.id.replace(":", "-"));
-            thingDiscovered(createDiscoveryResult(sensorUID, bridgeUID, sensor));
-            logger.trace("SensorDiscovery: Sensor with id '{}' and name '{}' added to Inbox with UID '{}'", sensor.id,
-                    sensor.name, sensorUID);
-        }
-    }
-
-    private DiscoveryResult createDiscoveryResult(ThingUID sensorUID, ThingUID bridgeUID, RemoteSensorDTO sensor) {
-        Map<String, Object> properties = new HashMap<>(2);
-        properties.put(CONFIG_SENSOR_ID, sensor.id);
-        return DiscoveryResultBuilder.create(sensorUID).withProperties(properties)
-                .withRepresentationProperty(CONFIG_SENSOR_ID).withBridge(bridgeUID).withLabel(buildLabel(sensor.name))
-                .build();
-    }
-}
diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/ThermostatDiscoveryService.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/ThermostatDiscoveryService.java
deleted file mode 100644 (file)
index 5b8f7b7..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Copyright (c) 2010-2020 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.ecobee.internal.discovery;
-
-import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.ecobee.internal.dto.thermostat.ThermostatDTO;
-import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
-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.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.binding.ThingHandlerService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The {@link ThermostatDiscoveryService} is responsible for discovering the Ecobee
- * thermostats that are associated with the Ecobee Account.
- *
- * @author Mark Hilbush - Initial contribution
- */
-@NonNullByDefault
-public class ThermostatDiscoveryService extends AbstractDiscoveryService
-        implements DiscoveryService, ThingHandlerService {
-
-    private final Logger logger = LoggerFactory.getLogger(ThermostatDiscoveryService.class);
-
-    private @NonNullByDefault({}) EcobeeAccountBridgeHandler bridgeHandler;
-
-    public ThermostatDiscoveryService() {
-        super(30);
-    }
-
-    @Override
-    public void setThingHandler(@Nullable ThingHandler handler) {
-        if (handler instanceof EcobeeAccountBridgeHandler) {
-            this.bridgeHandler = (EcobeeAccountBridgeHandler) handler;
-            this.bridgeHandler.setDiscoveryService(this);
-        }
-    }
-
-    @Override
-    public @Nullable ThingHandler getThingHandler() {
-        return bridgeHandler;
-    }
-
-    @Override
-    public void activate() {
-        logger.debug("ThermostatDiscovery: Activating Ecobee thermostat discovery service for {}",
-                bridgeHandler.getThing().getUID());
-    }
-
-    @Override
-    public void deactivate() {
-        logger.debug("ThermostatDiscovery: Deactivating Ecobee thermostat discovery service for {}",
-                bridgeHandler.getThing().getUID());
-    }
-
-    @Override
-    public Set<ThingTypeUID> getSupportedThingTypes() {
-        return SUPPORTED_THERMOSTAT_BRIDGE_THING_TYPES_UIDS;
-    }
-
-    @Override
-    public void startBackgroundDiscovery() {
-        logger.trace("ThermostatDiscovery: Performing background discovery scan for {}",
-                bridgeHandler.getThing().getUID());
-        discoverThermostats();
-    }
-
-    @Override
-    public void startScan() {
-        logger.debug("ThermostatDiscovery: Starting discovery scan for {}", bridgeHandler.getThing().getUID());
-        discoverThermostats();
-    }
-
-    @Override
-    public synchronized void abortScan() {
-        super.abortScan();
-    }
-
-    @Override
-    protected synchronized void stopScan() {
-        super.stopScan();
-    }
-
-    private String buildLabel(String name) {
-        return String.format("Ecobee Thermostat %s", name);
-    }
-
-    private synchronized void discoverThermostats() {
-        for (ThermostatDTO thermostat : bridgeHandler.getRegisteredThermostats()) {
-            String name = thermostat.name;
-            String identifier = thermostat.identifier;
-            if (identifier != null && name != null) {
-                ThingUID thingUID = new ThingUID(UID_THERMOSTAT_BRIDGE, bridgeHandler.getThing().getUID(),
-                        thermostat.identifier);
-                thingDiscovered(createDiscoveryResult(thingUID, identifier, name));
-                logger.trace("ThermostatDiscovery: Thermostat with id '{}' and name '{}' added to Inbox with UID '{}'",
-                        thermostat.identifier, thermostat.name, thingUID);
-            }
-        }
-    }
-
-    private DiscoveryResult createDiscoveryResult(ThingUID thermostatUID, String identifier, String name) {
-        Map<String, Object> properties = new HashMap<>(2);
-        properties.put(CONFIG_THERMOSTAT_ID, identifier);
-        return DiscoveryResultBuilder.create(thermostatUID).withProperties(properties)
-                .withRepresentationProperty(CONFIG_THERMOSTAT_ID).withBridge(bridgeHandler.getThing().getUID())
-                .withLabel(buildLabel(name)).build();
-    }
-}
index 9b35e8521017de44031a0ab99602c97cb3c39701..5622b6c9fb9b591caa66ef30f8ea9a1835712e47 100644 (file)
@@ -31,7 +31,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpClient;
 import org.openhab.binding.ecobee.internal.api.EcobeeApi;
 import org.openhab.binding.ecobee.internal.config.EcobeeAccountConfiguration;
-import org.openhab.binding.ecobee.internal.discovery.ThermostatDiscoveryService;
+import org.openhab.binding.ecobee.internal.discovery.EcobeeDiscoveryService;
 import org.openhab.binding.ecobee.internal.dto.SelectionDTO;
 import org.openhab.binding.ecobee.internal.dto.thermostat.ThermostatDTO;
 import org.openhab.binding.ecobee.internal.dto.thermostat.ThermostatUpdateRequestDTO;
@@ -61,8 +61,6 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
 
     private static final int REFRESH_STARTUP_DELAY_SECONDS = 3;
     private static final int REFRESH_INTERVAL_SECONDS = 1;
-    private static final int DISCOVERY_INTERVAL_SECONDS = 300;
-    private static final int DISCOVERY_INITIAL_DELAY_SECONDS = 10;
     private static final int DEFAULT_REFRESH_INTERVAL_NORMAL_SECONDS = 20;
     private static final int DEFAULT_REFRESH_INTERVAL_QUICK_SECONDS = 5;
     private static final int DEFAULT_API_TIMEOUT_SECONDS = 20;
@@ -78,15 +76,12 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
     private int refreshIntervalQuick;
     private int apiTimeout;
     private boolean discoveryEnabled;
-    private int discoveryInterval;
 
     private final Map<String, EcobeeThermostatBridgeHandler> thermostatHandlers = new ConcurrentHashMap<>();
     private final Set<String> thermostatIds = new CopyOnWriteArraySet<>();
 
     private @Nullable Future<?> refreshThermostatsJob;
     private final AtomicInteger refreshThermostatsCounter = new AtomicInteger(REFRESH_STARTUP_DELAY_SECONDS);
-    private final AtomicInteger discoveryCounter = new AtomicInteger(DISCOVERY_INITIAL_DELAY_SECONDS);
-    private @Nullable ThermostatDiscoveryService discoveryService;
 
     private @Nullable SummaryResponseDTO previousSummary;
 
@@ -117,9 +112,6 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
         discoveryEnabled = booleanValue == null ? false : booleanValue.booleanValue();
         logger.debug("AccountBridge: Thermostat and sensor discovery is {}", discoveryEnabled ? "enabled" : "disabled");
 
-        value = config.discoveryInterval;
-        discoveryInterval = value == null ? DISCOVERY_INTERVAL_SECONDS : value;
-
         api = new EcobeeApi(this, apiKey, apiTimeout, oAuthFactory, httpClient);
 
         scheduleRefreshJob();
@@ -139,7 +131,7 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
 
     @Override
     public Collection<Class<? extends ThingHandlerService>> getServices() {
-        return Collections.singleton(ThermostatDiscoveryService.class);
+        return Collections.singleton(EcobeeDiscoveryService.class);
     }
 
     @Override
@@ -161,11 +153,7 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
                 thermostatId);
     }
 
-    public void setDiscoveryService(ThermostatDiscoveryService discoveryService) {
-        this.discoveryService = discoveryService;
-    }
-
-    public boolean isDiscoveryEnabled() {
+    public boolean isBackgroundDiscoveryEnabled() {
         return discoveryEnabled;
     }
 
@@ -213,17 +201,13 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
     }
 
     /*
-     * The refresh job
-     * - updates the thermostat channels on the refresh interval set in the thermostat thing config, and
-     * - runs the thermostat discovery on the refresh interval set in the thing config
-     *
+     * The refresh job updates the thermostat channels on the refresh interval set in the thermostat thing config.
      * The thermostat update process involves first running a thermostat summary transaction to
      * determine if any thermostat data has changed since the last summary. If any change is detected,
      * a full query of the thermostats is performed.
      */
     private void refresh() {
         refreshThermostats();
-        discoverThermostats();
     }
 
     @SuppressWarnings("null")
@@ -243,19 +227,6 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler {
         }
     }
 
-    private void discoverThermostats() {
-        if (isDiscoveryEnabled()) {
-            if (discoveryCounter.getAndDecrement() == 0) {
-                discoveryCounter.set(discoveryInterval);
-                ThermostatDiscoveryService localDiscoveryService = discoveryService;
-                if (localDiscoveryService != null) {
-                    logger.debug("AccountBridge: Running thermostat discovery");
-                    localDiscoveryService.startBackgroundDiscovery();
-                }
-            }
-        }
-    }
-
     private void scheduleQuickPoll() {
         if (refreshThermostatsCounter.get() > refreshIntervalQuick) {
             logger.debug("AccountBridge: Scheduling quick poll");
index 3ff2697d169b16b70eecdace6eaf643c91924582..b5dab50aa3d6887d56c22d8c09d7823ff731eee1 100644 (file)
@@ -15,27 +15,20 @@ package org.openhab.binding.ecobee.internal.handler;
 import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
 
 import java.lang.reflect.Field;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import javax.measure.Unit;
 
 import org.apache.commons.lang.WordUtils;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.ecobee.internal.action.EcobeeActions;
 import org.openhab.binding.ecobee.internal.api.EcobeeApi;
 import org.openhab.binding.ecobee.internal.config.EcobeeThermostatConfiguration;
-import org.openhab.binding.ecobee.internal.discovery.SensorDiscoveryService;
 import org.openhab.binding.ecobee.internal.dto.SelectionDTO;
 import org.openhab.binding.ecobee.internal.dto.thermostat.AlertDTO;
 import org.openhab.binding.ecobee.internal.dto.thermostat.ClimateDTO;
@@ -72,7 +65,6 @@ import org.openhab.core.thing.ThingStatusDetail;
 import org.openhab.core.thing.ThingStatusInfo;
 import org.openhab.core.thing.binding.BaseBridgeHandler;
 import org.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.binding.ThingHandlerService;
 import org.openhab.core.thing.type.ChannelType;
 import org.openhab.core.thing.type.ChannelTypeRegistry;
 import org.openhab.core.thing.type.ChannelTypeUID;
@@ -90,9 +82,6 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
 
-    private static final int SENSOR_DISCOVERY_STARTUP_DELAY_SECONDS = 30;
-    private static final int SENSOR_DISCOVERY_INTERVAL_SECONDS = 300;
-
     private final Logger logger = LoggerFactory.getLogger(EcobeeThermostatBridgeHandler.class);
 
     private TimeZoneProvider timeZoneProvider;
@@ -102,9 +91,6 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
 
     private final Map<String, EcobeeSensorThingHandler> sensorHandlers = new ConcurrentHashMap<>();
 
-    private @Nullable Future<?> discoverSensorsJob;
-    private @Nullable SensorDiscoveryService discoveryService;
-
     private @Nullable ThermostatDTO savedThermostat;
     private @Nullable List<RemoteSensorDTO> savedSensors;
     private List<String> validClimateRefs = new CopyOnWriteArrayList<>();
@@ -127,13 +113,11 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
         initializeWeatherMaps();
         initializeReadOnlyChannels();
         clearSavedState();
-        scheduleDiscoveryJob();
         updateStatus(EcobeeUtils.isBridgeOnline(getBridge()) ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
     }
 
     @Override
     public void dispose() {
-        cancelDiscoveryJob();
         logger.debug("ThermostatBridge: Disposing thermostat '{}'", thermostatId);
     }
 
@@ -179,10 +163,6 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
         });
     }
 
-    public void setDiscoveryService(SensorDiscoveryService discoveryService) {
-        this.discoveryService = discoveryService;
-    }
-
     /**
      * Called by the AccountBridgeHandler to create a Selection that
      * includes only the Ecobee objects for which there's at least one
@@ -264,12 +244,6 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
         return false;
     }
 
-    @Override
-    public Collection<Class<? extends ThingHandlerService>> getServices() {
-        return Collections.unmodifiableList(
-                Stream.of(EcobeeActions.class, SensorDiscoveryService.class).collect(Collectors.toList()));
-    }
-
     public void updateChannels(ThermostatDTO thermostat) {
         logger.debug("ThermostatBridge: Updating channels for thermostat id {}", thermostat.identifier);
         savedThermostat = thermostat;
@@ -823,32 +797,6 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
         }
     }
 
-    private void scheduleDiscoveryJob() {
-        logger.debug("ThermostatBridge: Scheduling sensor discovery job");
-        cancelDiscoveryJob();
-        discoverSensorsJob = scheduler.scheduleWithFixedDelay(this::discoverSensors,
-                SENSOR_DISCOVERY_STARTUP_DELAY_SECONDS, SENSOR_DISCOVERY_INTERVAL_SECONDS, TimeUnit.SECONDS);
-    }
-
-    private void cancelDiscoveryJob() {
-        Future<?> localDiscoverSensorsJob = discoverSensorsJob;
-        if (localDiscoverSensorsJob != null) {
-            localDiscoverSensorsJob.cancel(true);
-            logger.debug("ThermostatBridge: Canceling sensor discovery job");
-        }
-    }
-
-    private void discoverSensors() {
-        EcobeeAccountBridgeHandler handler = getBridgeHandler();
-        if (handler != null && handler.isDiscoveryEnabled()) {
-            SensorDiscoveryService localDiscoveryService = discoveryService;
-            if (localDiscoveryService != null) {
-                logger.debug("ThermostatBridge: Running sensor discovery");
-                localDiscoveryService.startBackgroundDiscovery();
-            }
-        }
-    }
-
     private @Nullable EcobeeAccountBridgeHandler getBridgeHandler() {
         EcobeeAccountBridgeHandler handler = null;
         Bridge bridge = getBridge();
index 006c43e4345976f97bae9fe72c0b0faf34ed0964..e0316254195a71837455dad85fc7578bd22c70a0 100644 (file)
                        <description>Enable/disable automatic discovery</description>
                        <default>true</default>
                </parameter>
-               <parameter name="discoveryInterval" type="integer" min="60" required="false" unit="s">
-                       <label>Thermostat Discovery Interval</label>
-                       <description>Specifies time in seconds in which the binding will attempt to discover thermostats</description>
-               </parameter>
        </config-description>
 
        <config-description uri="thing-type:ecobee:thermostat">