use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class AutomaticInboxProcessor method thingAdded.
@Override
public void thingAdded(Inbox inbox, DiscoveryResult result) {
if (autoIgnore) {
String value = getRepresentationValue(result);
if (value != null) {
Thing thing = thingRegistry.stream().filter(t -> Objects.equals(value, getRepresentationPropertyValueForThing(t))).filter(t -> Objects.equals(t.getThingTypeUID(), result.getThingTypeUID())).findFirst().orElse(null);
if (thing != null) {
logger.debug("Auto-ignoring the inbox entry for the representation value {}", value);
inbox.setFlag(result.getThingUID(), DiscoveryResultFlag.IGNORED);
}
}
}
if (autoApprove) {
inbox.approve(result.getThingUID(), result.getLabel());
}
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method add.
@Override
public synchronized boolean add(DiscoveryResult result) throws IllegalStateException {
if (result != null) {
ThingUID thingUID = result.getThingUID();
Thing thing = this.thingRegistry.get(thingUID);
if (thing == null) {
DiscoveryResult inboxResult = get(thingUID);
if (inboxResult == null) {
discoveryResultStorage.put(result.getThingUID().toString(), result);
notifyListeners(result, EventType.added);
logger.info("Added new thing '{}' to inbox.", thingUID);
return true;
} else {
if (inboxResult instanceof DiscoveryResultImpl) {
DiscoveryResultImpl resultImpl = (DiscoveryResultImpl) inboxResult;
resultImpl.synchronize(result);
discoveryResultStorage.put(result.getThingUID().toString(), resultImpl);
notifyListeners(resultImpl, EventType.updated);
logger.debug("Updated discovery result for '{}'.", thingUID);
return true;
} else {
logger.warn("Cannot synchronize result with implementation class '{}'.", inboxResult.getClass().getName());
}
}
} else {
logger.debug("Discovery result with thing '{}' not added as inbox entry." + " It is already present as thing in the ThingRegistry.", thingUID);
boolean updated = synchronizeConfiguration(result.getThingTypeUID(), result.getProperties(), thing.getConfiguration());
if (updated) {
logger.debug("The configuration for thing '{}' is updated...", thingUID);
this.managedThingProvider.update(thing);
}
}
}
return false;
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method remove.
@Override
public synchronized boolean remove(ThingUID thingUID) throws IllegalStateException {
if (thingUID != null) {
DiscoveryResult discoveryResult = get(thingUID);
if (discoveryResult != null) {
if (!isInRegistry(thingUID)) {
removeResultsForBridge(thingUID);
}
resultDiscovererMap.remove(discoveryResult);
this.discoveryResultStorage.remove(thingUID.toString());
notifyListeners(discoveryResult, EventType.removed);
return true;
}
}
return false;
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method removeOlderResults.
@Override
public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
HashSet<ThingUID> removedThings = new HashSet<>();
for (DiscoveryResult discoveryResult : getAll()) {
Class<?> discoverer = resultDiscovererMap.get(discoveryResult);
if (thingTypeUIDs != null && thingTypeUIDs.contains(discoveryResult.getThingTypeUID()) && discoveryResult.getTimestamp() < timestamp && (discoverer == null || source.getClass() == discoverer)) {
ThingUID thingUID = discoveryResult.getThingUID();
if (bridgeUID == null || bridgeUID.equals(discoveryResult.getBridgeUID())) {
removedThings.add(thingUID);
remove(thingUID);
logger.debug("Removed {} from inbox because it was older than {}", thingUID, new Date(timestamp));
}
}
}
return removedThings;
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method approve.
@Override
public Thing approve(ThingUID thingUID, String label) {
if (thingUID == null) {
throw new IllegalArgumentException("Thing UID must not be null");
}
List<DiscoveryResult> results = stream().filter(forThingUID(thingUID)).collect(Collectors.toList());
if (results.isEmpty()) {
throw new IllegalArgumentException("No Thing with UID " + thingUID.getAsString() + " in inbox");
}
DiscoveryResult result = results.get(0);
final Map<String, String> properties = new HashMap<>();
final Map<String, Object> configParams = new HashMap<>();
getPropsAndConfigParams(result, properties, configParams);
final Configuration config = new Configuration(configParams);
ThingTypeUID thingTypeUID = result.getThingTypeUID();
Thing newThing = ThingFactory.createThing(thingUID, config, properties, result.getBridgeUID(), thingTypeUID, this.thingHandlerFactories);
if (newThing == null) {
logger.warn("Cannot create thing. No binding found that supports creating a thing" + " of type {}.", thingTypeUID);
return null;
}
if (label != null && !label.isEmpty()) {
newThing.setLabel(label);
} else {
newThing.setLabel(result.getLabel());
}
addThingSafely(newThing);
return newThing;
}
Aggregations