Skip to content

Commit

Permalink
remove deprecated discovery interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
J-N-K committed Jul 11, 2020
1 parent fe947c8 commit 9b352b3
Showing 1 changed file with 9 additions and 46 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);
}
}
}

0 comments on commit 9b352b3

Please sign in to comment.