use of org.eclipse.smarthome.core.thing.ThingUID 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.core.thing.ThingUID in project smarthome by eclipse.
the class PersistentInbox method addThingSafely.
private void addThingSafely(Thing thing) {
ThingUID thingUID = thing.getUID();
if (thingRegistry.get(thingUID) != null) {
thingRegistry.remove(thingUID);
}
thingRegistry.add(thing);
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class PersistentInbox method matchFilter.
private boolean matchFilter(DiscoveryResult discoveryResult, InboxFilterCriteria criteria) {
if (criteria != null) {
String bindingId = criteria.getBindingId();
if ((bindingId != null) && (!bindingId.isEmpty())) {
if (!discoveryResult.getBindingId().equals(bindingId)) {
return false;
}
}
ThingTypeUID thingTypeUID = criteria.getThingTypeUID();
if (thingTypeUID != null) {
if (!discoveryResult.getThingTypeUID().equals(thingTypeUID)) {
return false;
}
}
ThingUID thingUID = criteria.getThingUID();
if (thingUID != null) {
if (!discoveryResult.getThingUID().equals(thingUID)) {
return false;
}
}
DiscoveryResultFlag flag = criteria.getFlag();
if (flag != null) {
if (discoveryResult.getFlag() != flag) {
return false;
}
}
}
return true;
}
use of org.eclipse.smarthome.core.thing.ThingUID 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.core.thing.ThingUID in project smarthome by eclipse.
the class InboxConsoleCommandExtension method clearInboxEntries.
private void clearInboxEntries(Console console, List<DiscoveryResult> discoveryResults) {
if (discoveryResults.isEmpty()) {
console.println("No inbox entries found.");
}
for (DiscoveryResult discoveryResult : discoveryResults) {
ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID();
ThingUID thingUID = discoveryResult.getThingUID();
String label = discoveryResult.getLabel();
DiscoveryResultFlag flag = discoveryResult.getFlag();
ThingUID bridgeId = discoveryResult.getBridgeUID();
Map<String, Object> properties = discoveryResult.getProperties();
console.println(String.format("REMOVED [%s]: %s [label=%s, thingId=%s, bridgeId=%s, properties=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties));
inbox.remove(thingUID);
}
}
Aggregations