[icalendar] Change migration of last_update to use ThingHandlerCallback (#9681)
* [icalendar] Change migration of last_update to use ThingHandlerCallback Fixes #9674. Signed-off-by: Michael Wodniok <michi@noorganization.org>
This commit is contained in:
parent
7e06da2401
commit
8da4d4d0cb
@ -49,6 +49,7 @@ import org.openhab.core.thing.ThingStatus;
|
|||||||
import org.openhab.core.thing.ThingStatusDetail;
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
import org.openhab.core.thing.binding.BaseBridgeHandler;
|
import org.openhab.core.thing.binding.BaseBridgeHandler;
|
||||||
import org.openhab.core.thing.binding.ThingHandler;
|
import org.openhab.core.thing.binding.ThingHandler;
|
||||||
|
import org.openhab.core.thing.binding.ThingHandlerCallback;
|
||||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
@ -269,12 +270,18 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
|||||||
* Migration for last_update-channel as this change is compatible to previous instances.
|
* Migration for last_update-channel as this change is compatible to previous instances.
|
||||||
*/
|
*/
|
||||||
private void migrateLastUpdateChannel() {
|
private void migrateLastUpdateChannel() {
|
||||||
Thing thing = getThing();
|
final Thing thing = getThing();
|
||||||
if (thing.getChannel(CHANNEL_LAST_UPDATE) == null) {
|
if (thing.getChannel(CHANNEL_LAST_UPDATE) == null) {
|
||||||
logger.debug("last_update channel is missing in this Thing. Adding it.");
|
logger.trace("last_update channel is missing in this Thing. Adding it.");
|
||||||
ThingBuilder thingBuilder = editThing();
|
final ThingHandlerCallback callback = getCallback();
|
||||||
ChannelBuilder channelBuilder = ChannelBuilder.create(new ChannelUID(thing.getUID(), CHANNEL_LAST_UPDATE));
|
if (callback == null) {
|
||||||
thingBuilder.withChannel(channelBuilder.withType(LAST_UPDATE_TYPE_UID).build());
|
logger.debug("ThingHandlerCallback is null. Skipping migration of last_update channel.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ChannelBuilder channelBuilder = callback
|
||||||
|
.createChannelBuilder(new ChannelUID(thing.getUID(), CHANNEL_LAST_UPDATE), LAST_UPDATE_TYPE_UID);
|
||||||
|
final ThingBuilder thingBuilder = editThing();
|
||||||
|
thingBuilder.withChannel(channelBuilder.build());
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user