Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thing upgrades for bridges #3858

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public static BridgeBuilder create(ThingTypeUID thingTypeUID, ThingUID thingUID)
return new BridgeBuilder(thingTypeUID, thingUID);
}

/**
* Create a new bridge {@link BridgeBuilder} for a copy of the given bridge
*
* @param bridge the {@link Bridge} to create this builder from
* @return the created {@link BridgeBuilder}
*
*/
public static BridgeBuilder create(Bridge bridge) {
return BridgeBuilder.create(bridge.getThingTypeUID(), bridge.getUID()).withBridge(bridge.getBridgeUID())
.withChannels(bridge.getChannels()).withConfiguration(bridge.getConfiguration())
.withLabel(bridge.getLabel()).withLocation(bridge.getLocation()).withProperties(bridge.getProperties());
}

@Override
public Bridge build() {
final BridgeImpl bridge = new BridgeImpl(thingTypeUID, thingUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder;
import org.openhab.core.thing.events.ThingEventFactory;
Expand Down Expand Up @@ -238,7 +239,7 @@ protected void thingUpdated(final Thing thing) {
throw new IllegalArgumentException(MessageFormat.format(
"Cannot update thing {0} because it is not known to the registry", thing.getUID().getAsString()));
}
final Provider<Thing> provider = thingRegistry.getProvider(thing);
final Provider<Thing> provider = thingRegistry.getProvider(oldThing);
if (provider == null) {
throw new IllegalArgumentException(MessageFormat.format(
"Provider for thing {0} cannot be determined because it is not known to the registry",
Expand Down Expand Up @@ -1089,7 +1090,8 @@ private boolean checkAndPerformUpdate(Thing thing, ThingHandlerFactory factory)
}

// create a thing builder and apply the update instructions
ThingBuilder thingBuilder = ThingBuilder.create(thing);
ThingBuilder thingBuilder = thing instanceof Bridge ? BridgeBuilder.create((Bridge) thing)
: ThingBuilder.create(thing);
instructions.forEach(instruction -> instruction.perform(thing, thingBuilder));
int newThingTypeVersion = instructions.get(instructions.size() - 1).getThingTypeVersion();
thingBuilder.withProperty(PROPERTY_THING_TYPE_VERSION, String.valueOf(newThingTypeVersion));
Expand Down