Skip to content

Commit

Permalink
[amazonechocontrol] Remove deprecated discovery interfaces (openhab#8095
Browse files Browse the repository at this point in the history
)

* Remove deprecated discovery interfaces

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
Signed-off-by: CSchlipp <christian@schlipp.de>
  • Loading branch information
J-N-K authored and CSchlipp committed Jul 26, 2020
1 parent 26fd69f commit 87ea39a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryServiceCallback;
import org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.openhab.binding.amazonechocontrol.internal.Connection;
Expand All @@ -54,22 +52,15 @@
* @author Michael Geramb - Initial contribution
*/
@NonNullByDefault
public class AmazonEchoDiscovery extends AbstractDiscoveryService implements ExtendedDiscoveryService {
public class AmazonEchoDiscovery extends AbstractDiscoveryService {

AccountHandler accountHandler;
private final Logger logger = LoggerFactory.getLogger(AmazonEchoDiscovery.class);
private final Set<String> discoverdFlashBriefings = new HashSet<>();

private @Nullable DiscoveryServiceCallback discoveryServiceCallback;
private final Set<String> discoveredFlashBriefings = new HashSet<>();

private @Nullable ScheduledFuture<?> startScanStateJob;
private @Nullable Long activateTimeStamp;

@Override
public void setDiscoveryServiceCallback(DiscoveryServiceCallback discoveryServiceCallback) {
this.discoveryServiceCallback = discoveryServiceCallback;
}

public AmazonEchoDiscovery(AccountHandler accountHandler) {
super(SUPPORTED_ECHO_THING_TYPES_UIDS, 10);
this.accountHandler = accountHandler;
Expand Down Expand Up @@ -150,10 +141,6 @@ public void activate(@Nullable Map<String, @Nullable Object> config) {
}

synchronized void setDevices(List<Device> deviceList) {
DiscoveryServiceCallback discoveryServiceCallback = this.discoveryServiceCallback;
if (discoveryServiceCallback == null) {
return;
}
for (Device device : deviceList) {
String serialNumber = device.serialNumber;
if (serialNumber != null) {
Expand All @@ -175,12 +162,7 @@ synchronized void setDevices(List<Device> deviceList) {

ThingUID brigdeThingUID = this.accountHandler.getThing().getUID();
ThingUID thingUID = new ThingUID(thingTypeId, brigdeThingUID, serialNumber);
if (discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
continue;
}
if (discoveryServiceCallback.getExistingThing(thingUID) != null) {
continue;
}

DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(device.accountName)
.withProperty(DEVICE_PROPERTY_SERIAL_NUMBER, serialNumber)
.withProperty(DEVICE_PROPERTY_FAMILY, deviceFamily)
Expand All @@ -200,41 +182,22 @@ public synchronized void discoverFlashBriefingProfiles(String currentFlashBriefi
if (currentFlashBriefingJson.isEmpty()) {
return;
}
DiscoveryServiceCallback discoveryServiceCallback = this.discoveryServiceCallback;
if (discoveryServiceCallback == null) {
return;
}

if (!discoverdFlashBriefings.contains(currentFlashBriefingJson)) {
ThingUID freeThingUID = null;
int freeIndex = 0;
for (int i = 1; i < 1000; i++) {
String id = Integer.toString(i);
ThingUID brigdeThingUID = this.accountHandler.getThing().getUID();
ThingUID thingUID = new ThingUID(THING_TYPE_FLASH_BRIEFING_PROFILE, brigdeThingUID, id);
if (discoveryServiceCallback.getExistingThing(thingUID) == null
&& discoveryServiceCallback.getExistingDiscoveryResult(thingUID) == null) {
freeThingUID = thingUID;
freeIndex = i;
break;
}
}
if (freeThingUID == null) {
logger.debug("No more free flashbriefing thing ID found");
return;
}
DiscoveryResult result = DiscoveryResultBuilder.create(freeThingUID).withLabel("FlashBriefing " + freeIndex)
if (!discoveredFlashBriefings.contains(currentFlashBriefingJson)) {
ThingUID brigdeThingUID = this.accountHandler.getThing().getUID();
ThingUID freeThingUID = new ThingUID(THING_TYPE_FLASH_BRIEFING_PROFILE, brigdeThingUID, Integer.toString(currentFlashBriefingJson.hashCode()));
DiscoveryResult result = DiscoveryResultBuilder.create(freeThingUID).withLabel("FlashBriefing")
.withProperty(DEVICE_PROPERTY_FLASH_BRIEFING_PROFILE, currentFlashBriefingJson)
.withBridge(accountHandler.getThing().getUID()).build();
logger.debug("Flash Briefing {} discovered", currentFlashBriefingJson);
thingDiscovered(result);
discoverdFlashBriefings.add(currentFlashBriefingJson);
discoveredFlashBriefings.add(currentFlashBriefingJson);
}
}

public synchronized void removeExistingFlashBriefingProfile(@Nullable String currentFlashBriefingJson) {
if (currentFlashBriefingJson != null) {
discoverdFlashBriefings.remove(currentFlashBriefingJson);
discoveredFlashBriefings.remove(currentFlashBriefingJson);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryServiceCallback;
import org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.openhab.binding.amazonechocontrol.internal.Connection;
import org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler;
Expand All @@ -51,20 +49,13 @@
* @author Lukas Knoeller - Initial contribution
*/
@NonNullByDefault
public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService implements ExtendedDiscoveryService {
public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
private AccountHandler accountHandler;
private final Logger logger = LoggerFactory.getLogger(SmartHomeDevicesDiscovery.class);

private @Nullable ScheduledFuture<?> startScanStateJob;
private @Nullable Long activateTimeStamp;

private @Nullable DiscoveryServiceCallback discoveryServiceCallback;

@Override
public void setDiscoveryServiceCallback(DiscoveryServiceCallback discoveryServiceCallback) {
this.discoveryServiceCallback = discoveryServiceCallback;
}

public SmartHomeDevicesDiscovery(AccountHandler accountHandler) {
super(SUPPORTED_SMART_HOME_THING_TYPES_UIDS, 10);
this.accountHandler = accountHandler;
Expand Down Expand Up @@ -143,11 +134,6 @@ public void activate(@Nullable Map<String, @Nullable Object> config) {
};

synchronized void setSmartHomeDevices(List<SmartHomeBaseDevice> deviceList) {
DiscoveryServiceCallback discoveryServiceCallback = this.discoveryServiceCallback;

if (discoveryServiceCallback == null) {
return;
}
int smartHomeDeviceDiscoveryMode = accountHandler.getSmartHomeDevicesDiscoveryMode();
if (smartHomeDeviceDiscoveryMode == 0) {
return;
Expand Down Expand Up @@ -227,14 +213,6 @@ synchronized void setSmartHomeDevices(List<SmartHomeBaseDevice> deviceList) {
}

if (thingUID != null) {
if (discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
continue;
}

if (discoveryServiceCallback.getExistingThing(thingUID) != null) {
continue;
}

DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(deviceName)
.withProperties(props).withBridge(bridgeThingUID).build();

Expand Down

0 comments on commit 87ea39a

Please sign in to comment.