[SOLVED] How to change DiscoveryResult thing type programmactically

in my binding when I receive a response to a device search method I create a new DiscoveryResult with ThingTypeUID "A".
Sometimes, but not always, a second further response to the device search is received from the protocol, giving more details about the device discovered which needs changing its ThingType.
Thus the previous DiscoveryResult should be updated to ThingTypeUID "B", and therefore also the ThingUID will be different, so Inbox will not automatically remove the previous discovery.
In the past I achieved this device type change with:

// 2nd device search message received...
// get old discovered DiscoveryResult
discoveryResult = discoveryServiceCallback.getExistingDiscoveryResult(thingUID);
if (discoveryResult != null) { 
    // remove previously discovered thing
// create new thingUID with new type and create new DiscoveryResult
thingUID = new ThingUID(thingTypeUID, bridgeUID, ....);
newDiscoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).build();

This worked for me but unfortunately now DiscoveryServiceCallback is deprecated.

How can I remove a previous DiscoveryResult from Inbox programmactically, to change it with a new DiscoveryResult with a different device type and ThingUID ?


Just few thoughts - not directly related to your question.

You don’t have to remove previous discovery result - you can specify timeToLive property which will automatically discard it after a while.
Maybe its also worth to handle this kind of situations in ThingHandler itself. Its possible to call editThing and append new channels to existing Thing instance if necessary.

Thansk @splatch but I need to create a new ThingUID with different ThingTypeUID and I need not to present anymore the first discovery to the user, only the updated thing.
In fact looking again to it, since I already know the ThingUID of the first device found that should be changed, I can just use:


without checking back if the discovery result exists.
I have tested it and it works.
So no need to use DiscoveryServiceCallback that is obsolete.

So I think this is solved. Thanks!