[ecobee] Rework discovery (#9522)

* Rework discovery
* Consolidate discovery into one service

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2020-12-29 19:18:42 -05:00 committed by GitHub
parent 4c685adabc
commit f9b763210d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 198 additions and 351 deletions

View 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

View 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";

View 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;
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View 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");

View 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();

View File

@ -29,10 +29,6 @@
<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">