Fix StateDescription deprecations (#9352)

Related to #1408

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-12-13 08:53:16 +01:00
committed by GitHub
parent 863606e311
commit 8f53e320dc
12 changed files with 59 additions and 51 deletions

View File

@@ -31,7 +31,8 @@ import org.openhab.core.thing.type.ChannelType;
import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.StateDescription;
import org.openhab.core.types.StateDescriptionFragment;
import org.openhab.core.types.StateDescriptionFragmentBuilder;
import org.openhab.core.types.StateOption;
/**
@@ -64,12 +65,12 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
return channelTypeUID;
}
private void createChannelType(StateDescription state) {
private void createChannelType(StateDescriptionFragment state) {
channelType = ChannelTypeBuilder.state(channelTypeUID, "Input source", "String")
.withDescription("Select the input source of the AVR").withStateDescription(state).build();
.withDescription("Select the input source of the AVR").withStateDescriptionFragment(state).build();
}
private StateDescription getDefaultStateDescription() {
private StateDescriptionFragment getDefaultStateDescription() {
List<StateOption> options = new ArrayList<>();
options.add(new StateOption(INPUT_NET_RADIO, "Net Radio"));
options.add(new StateOption(INPUT_PC, "PC"));
@@ -110,8 +111,8 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
options.add(new StateOption(INPUT_PANDORA, "Pandora"));
options.add(new StateOption(INPUT_NAPSTER, "Napster"));
options.add(new StateOption(INPUT_SPOTIFY, "Spotify"));
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
return state;
return StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false).withOptions(options)
.build();
}
public void changeAvailableInputs(Map<String, String> availableInputs) {
@@ -119,7 +120,8 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
for (Entry<String, String> inputEntry : availableInputs.entrySet()) {
options.add(new StateOption(inputEntry.getKey(), inputEntry.getValue()));
}
createChannelType(new StateDescription(null, null, null, "%s", false, options));
createChannelType(StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false)
.withOptions(options).build());
}
@NonNullByDefault({})

View File

@@ -31,7 +31,8 @@ import org.openhab.core.thing.type.ChannelType;
import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.StateDescription;
import org.openhab.core.types.StateDescriptionFragment;
import org.openhab.core.types.StateDescriptionFragmentBuilder;
import org.openhab.core.types.StateOption;
/**
@@ -64,25 +65,24 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
return channelTypeUID;
}
private StateDescription getDefaultStateDescription() {
private StateDescriptionFragment getDefaultStateDescription() {
List<StateOption> options = IntStream.rangeClosed(1, 40)
.mapToObj(i -> new StateOption(Integer.toString(i), "Item_" + i)).collect(toList());
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
return state;
return StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false).withOptions(options)
.build();
}
public void changePresetNames(List<PresetInfoState.Preset> presets) {
List<StateOption> options = presets.stream()
.map(preset -> new StateOption(String.valueOf(preset.getValue()), preset.getName())).collect(toList());
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
createChannelType(state);
createChannelType(StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false)
.withOptions(options).build());
}
private void createChannelType(StateDescription state) {
private void createChannelType(StateDescriptionFragment state) {
channelType = ChannelTypeBuilder.state(channelTypeUID, "Preset", "Number")
.withDescription("Select a saved channel by its preset number").withStateDescription(state).build();
.withDescription("Select a saved channel by its preset number").withStateDescriptionFragment(state)
.build();
}
@NonNullByDefault({})
@@ -96,8 +96,7 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
channelTypeUID = new ChannelTypeUID(BINDING_ID,
CHANNEL_PLAYBACK_PRESET_TYPE_NAMED + handler.getThing().getUID().getId());
StateDescription state = getDefaultStateDescription();
createChannelType(state);
createChannelType(getDefaultStateDescription());
}
@Override