mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Fix StateDescription deprecations (#9352)
Related to #1408 Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
863606e311
commit
8f53e320dc
@ -37,7 +37,8 @@ import org.openhab.core.thing.type.ChannelType;
|
|||||||
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeProvider;
|
import org.openhab.core.thing.type.ChannelTypeProvider;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
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;
|
import org.openhab.core.types.StateOption;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
@ -322,7 +323,7 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StateDescription getSensorStateDescription(SensorEnum sensorType) {
|
private StateDescriptionFragment getSensorStateDescription(SensorEnum sensorType) {
|
||||||
// the digitalSTROM resolution for temperature in kelvin is not correct but sensor-events and cached values are
|
// the digitalSTROM resolution for temperature in kelvin is not correct but sensor-events and cached values are
|
||||||
// shown in °C so we will use this unit for temperature sensors
|
// shown in °C so we will use this unit for temperature sensors
|
||||||
String unitShortCut = sensorType.getUnitShortcut();
|
String unitShortCut = sensorType.getUnitShortcut();
|
||||||
@ -332,14 +333,15 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
if (sensorType.toString().contains("TEMPERATURE")) {
|
if (sensorType.toString().contains("TEMPERATURE")) {
|
||||||
unitShortCut = "°C";
|
unitShortCut = "°C";
|
||||||
}
|
}
|
||||||
return new StateDescription(null, null, null, sensorType.getPattern() + " " + unitShortCut, true, null);
|
return StateDescriptionFragmentBuilder.create().withPattern(sensorType.getPattern() + " " + unitShortCut)
|
||||||
|
.withReadOnly(true).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStageChannelOption(String type, String option) {
|
private String getStageChannelOption(String type, String option) {
|
||||||
return buildIdentifier(type, STAGE, OPTION, option);
|
return buildIdentifier(type, STAGE, OPTION, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StateDescription getStageDescription(String channelID, Locale locale) {
|
private StateDescriptionFragment getStageDescription(String channelID, Locale locale) {
|
||||||
if (channelID.contains(STAGE.toLowerCase())) {
|
if (channelID.contains(STAGE.toLowerCase())) {
|
||||||
List<StateOption> stateOptions = new ArrayList<>();
|
List<StateOption> stateOptions = new ArrayList<>();
|
||||||
if (channelID.contains(LIGHT)) {
|
if (channelID.contains(LIGHT)) {
|
||||||
@ -369,11 +371,12 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
locale)));
|
locale)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new StateDescription(null, null, null, null, false, stateOptions);
|
return StateDescriptionFragmentBuilder.create().withReadOnly(false).withOptions(stateOptions).build();
|
||||||
}
|
}
|
||||||
if (channelID.contains(TEMPERATURE_CONTROLLED)) {
|
if (channelID.contains(TEMPERATURE_CONTROLLED)) {
|
||||||
return new StateDescription(new BigDecimal(0), new BigDecimal(50), new BigDecimal(0.1), "%.1f °C", false,
|
return StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(0))
|
||||||
null);
|
.withMaximum(new BigDecimal(50)).withStep(new BigDecimal(0.1)).withPattern("%.1f °C")
|
||||||
|
.withReadOnly(false).build();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -485,14 +488,14 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
|
return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
|
||||||
.withDescription(getDescText(channelID, locale)).withCategory(getSensorCategory(sensorType))
|
.withDescription(getDescText(channelID, locale)).withCategory(getSensorCategory(sensorType))
|
||||||
.withTags(getSimpleTags(channelID, locale))
|
.withTags(getSimpleTags(channelID, locale))
|
||||||
.withStateDescription(getSensorStateDescription(sensorType)).build();
|
.withStateDescriptionFragment(getSensorStateDescription(sensorType)).build();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
if (SUPPORTED_OUTPUT_CHANNEL_TYPES.contains(channelID)) {
|
if (SUPPORTED_OUTPUT_CHANNEL_TYPES.contains(channelID)) {
|
||||||
return ChannelTypeBuilder
|
return ChannelTypeBuilder
|
||||||
.state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
|
.state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
|
||||||
.withDescription(getDescText(channelID, locale)).withCategory(getCategory(channelID))
|
.withDescription(getDescText(channelID, locale)).withCategory(getCategory(channelID))
|
||||||
.withTags(getTags(channelID, locale))
|
.withTags(getTags(channelID, locale))
|
||||||
.withStateDescription(getStageDescription(channelID, locale)).build();
|
.withStateDescriptionFragment(getStageDescription(channelID, locale)).build();
|
||||||
}
|
}
|
||||||
MeteringTypeEnum meteringType = getMeteringType(channelID);
|
MeteringTypeEnum meteringType = getMeteringType(channelID);
|
||||||
if (meteringType != null) {
|
if (meteringType != null) {
|
||||||
@ -501,11 +504,14 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
if (MeteringTypeEnum.CONSUMPTION.equals(meteringType)) {
|
if (MeteringTypeEnum.CONSUMPTION.equals(meteringType)) {
|
||||||
pattern = "%d W";
|
pattern = "%d W";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
|
return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
|
||||||
.withDescription(getDescText(channelID, locale)).withCategory(CATEGORY_ENERGY)
|
.withDescription(getDescText(channelID, locale)).withCategory(CATEGORY_ENERGY)
|
||||||
.withTags(
|
.withTags(
|
||||||
new HashSet<>(Arrays.asList(getLabelText(channelID, locale), getText(DS, locale))))
|
new HashSet<>(Arrays.asList(getLabelText(channelID, locale), getText(DS, locale))))
|
||||||
.withStateDescription(new StateDescription(null, null, null, pattern, true, null)).build();
|
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withPattern(pattern)
|
||||||
|
.withReadOnly(true).build())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
DeviceBinarayInputEnum binarayInputType = DeviceBinarayInputEnum
|
DeviceBinarayInputEnum binarayInputType = DeviceBinarayInputEnum
|
||||||
@ -514,8 +520,9 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
|
|||||||
.state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
|
.state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
|
||||||
.withDescription(getDescText(channelID, locale))
|
.withDescription(getDescText(channelID, locale))
|
||||||
.withCategory(getBinaryInputCategory(binarayInputType))
|
.withCategory(getBinaryInputCategory(binarayInputType))
|
||||||
.withTags(getSimpleTags(channelTypeUID.getId(), locale))
|
.withTags(getSimpleTags(channelTypeUID.getId(), locale)).withStateDescriptionFragment(
|
||||||
.withStateDescription(new StateDescription(null, null, null, null, true, null)).build();
|
StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
|
||||||
|
.build();
|
||||||
} catch (IllegalArgumentException e1) {
|
} catch (IllegalArgumentException e1) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ import org.openhab.core.thing.type.ChannelTypeBuilder;
|
|||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.RefreshType;
|
import org.openhab.core.types.RefreshType;
|
||||||
import org.openhab.core.types.StateDescription;
|
import org.openhab.core.types.StateDescriptionFragmentBuilder;
|
||||||
import org.openhab.core.types.StateOption;
|
import org.openhab.core.types.StateOption;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -187,7 +187,8 @@ public class HarmonyDeviceHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Send Button Press", "String")
|
ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Send Button Press", "String")
|
||||||
.withDescription("Send a button press to device " + getThing().getLabel())
|
.withDescription("Send a button press to device " + getThing().getLabel())
|
||||||
.withStateDescription(new StateDescription(null, null, null, null, false, states)).build();
|
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withOptions(states).build())
|
||||||
|
.build();
|
||||||
|
|
||||||
factory.addChannelType(channelType);
|
factory.addChannelType(channelType);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ import org.openhab.core.thing.type.ChannelTypeBuilder;
|
|||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.RefreshType;
|
import org.openhab.core.types.RefreshType;
|
||||||
import org.openhab.core.types.StateDescription;
|
import org.openhab.core.types.StateDescriptionFragmentBuilder;
|
||||||
import org.openhab.core.types.StateOption;
|
import org.openhab.core.types.StateOption;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -382,7 +382,9 @@ public class HarmonyHubHandler extends BaseBridgeHandler implements HarmonyClien
|
|||||||
|
|
||||||
ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Current Activity", "String")
|
ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Current Activity", "String")
|
||||||
.withDescription("Current activity for " + getThing().getLabel())
|
.withDescription("Current activity for " + getThing().getLabel())
|
||||||
.withStateDescription(new StateDescription(null, null, null, "%s", false, states)).build();
|
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withPattern("%s")
|
||||||
|
.withReadOnly(false).withOptions(states).build())
|
||||||
|
.build();
|
||||||
|
|
||||||
factory.addChannelType(channelType);
|
factory.addChannelType(channelType);
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class KM200ThingHandler extends BaseThingHandler {
|
|||||||
.withDescription(description) //
|
.withDescription(description) //
|
||||||
.withCategory(checkCategory(unitOfMeasure, category, state.isReadOnly())) //
|
.withCategory(checkCategory(unitOfMeasure, category, state.isReadOnly())) //
|
||||||
.withTags(checkTags(unitOfMeasure, state.isReadOnly())) //
|
.withTags(checkTags(unitOfMeasure, state.isReadOnly())) //
|
||||||
.withStateDescription(state.toStateDescription()) //
|
.withStateDescriptionFragment(state) //
|
||||||
.withConfigDescriptionURI(configDescriptionUriChannel).build();
|
.withConfigDescriptionURI(configDescriptionUriChannel).build();
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
logger.warn("Can't create ConfigDescription URI '{}', ConfigDescription for channels not avilable!",
|
logger.warn("Can't create ConfigDescription URI '{}', ConfigDescription for channels not avilable!",
|
||||||
|
@ -38,7 +38,7 @@ import org.openhab.core.thing.type.ChannelDefinitionBuilder;
|
|||||||
import org.openhab.core.thing.type.ChannelType;
|
import org.openhab.core.thing.type.ChannelType;
|
||||||
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||||
import org.openhab.core.types.StateDescription;
|
import org.openhab.core.types.StateDescriptionFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AbstractComponent}s derived class consists of one or multiple channels.
|
* An {@link AbstractComponent}s derived class consists of one or multiple channels.
|
||||||
@ -208,11 +208,10 @@ public class CChannel {
|
|||||||
type = ChannelTypeBuilder.trigger(channelTypeUID, label)
|
type = ChannelTypeBuilder.trigger(channelTypeUID, label)
|
||||||
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL)).build();
|
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL)).build();
|
||||||
} else {
|
} else {
|
||||||
StateDescription description = valueState.createStateDescription(command_topic == null).build()
|
StateDescriptionFragment description = valueState.createStateDescription(command_topic == null).build();
|
||||||
.toStateDescription();
|
|
||||||
type = ChannelTypeBuilder.state(channelTypeUID, label, channelState.getItemType())
|
type = ChannelTypeBuilder.state(channelTypeUID, label, channelState.getItemType())
|
||||||
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL))
|
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL))
|
||||||
.withStateDescription(description).build();
|
.withStateDescriptionFragment(description).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
|
@ -142,8 +142,8 @@ public class Property implements AttributeChanged {
|
|||||||
if (attributes.retained) {
|
if (attributes.retained) {
|
||||||
return ChannelTypeBuilder.state(channelTypeUID, attributes.name, channelState.getItemType())
|
return ChannelTypeBuilder.state(channelTypeUID, attributes.name, channelState.getItemType())
|
||||||
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HOMIE_CHANNEL))
|
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HOMIE_CHANNEL))
|
||||||
.withStateDescription(channelState.getCache().createStateDescription(!attributes.settable).build()
|
.withStateDescriptionFragment(
|
||||||
.toStateDescription())
|
channelState.getCache().createStateDescription(!attributes.settable).build())
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
// Non-retained and settable property -> State channel
|
// Non-retained and settable property -> State channel
|
||||||
|
@ -113,7 +113,7 @@ class NUTDynamicChannelFactory {
|
|||||||
final ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channel.getUID().getId() + "Type");
|
final ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channel.getUID().getId() + "Type");
|
||||||
final String label = channel.getLabel();
|
final String label = channel.getLabel();
|
||||||
final ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, label == null ? "" : label, itemType)
|
final ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, label == null ? "" : label, itemType)
|
||||||
.withStateDescription(sdb.withReadOnly(Boolean.TRUE).build().toStateDescription())
|
.withStateDescriptionFragment(sdb.withReadOnly(Boolean.TRUE).build())
|
||||||
.withConfigDescriptionURI(NUTBindingConstants.DYNAMIC_CHANNEL_CONFIG_QUANTITY_TYPE).build();
|
.withConfigDescriptionURI(NUTBindingConstants.DYNAMIC_CHANNEL_CONFIG_QUANTITY_TYPE).build();
|
||||||
channelTypeProvider.addChannelType(channelType);
|
channelTypeProvider.addChannelType(channelType);
|
||||||
return channelTypeUID;
|
return channelTypeUID;
|
||||||
|
@ -389,7 +389,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
|
|||||||
stateDescription = stateDescription.withPattern(pattern);
|
stateDescription = stateDescription.withPattern(pattern);
|
||||||
}
|
}
|
||||||
final StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
|
final StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
|
||||||
.withStateDescription(stateDescription.build().toStateDescription());
|
.withStateDescriptionFragment(stateDescription.build());
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
builder.withTag(tag);
|
builder.withTag(tag);
|
||||||
}
|
}
|
||||||
|
@ -83,16 +83,14 @@ public class SmartMeterChannelTypeProvider implements ChannelTypeProvider, Meter
|
|||||||
stateDescriptionBuilder = ChannelTypeBuilder
|
stateDescriptionBuilder = ChannelTypeBuilder
|
||||||
.state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
|
.state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
|
||||||
CoreItemFactory.NUMBER + ":" + dimension)
|
CoreItemFactory.NUMBER + ":" + dimension)
|
||||||
.withStateDescription(StateDescriptionFragmentBuilder.create().withReadOnly(true)
|
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true)
|
||||||
.withPattern("%.2f %unit%").build().toStateDescription())
|
.withPattern("%.2f %unit%").build())
|
||||||
.withConfigDescriptionURI(URI.create(SmartMeterBindingConstants.CHANNEL_TYPE_METERREADER_OBIS));
|
.withConfigDescriptionURI(URI.create(SmartMeterBindingConstants.CHANNEL_TYPE_METERREADER_OBIS));
|
||||||
} else {
|
} else {
|
||||||
stateDescriptionBuilder = ChannelTypeBuilder
|
stateDescriptionBuilder = ChannelTypeBuilder
|
||||||
.state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
|
.state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
|
||||||
CoreItemFactory.STRING)
|
CoreItemFactory.STRING)
|
||||||
.withStateDescription(
|
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build());
|
||||||
StateDescriptionFragmentBuilder.create().withReadOnly(true).build().toStateDescription());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return stateDescriptionBuilder.build();
|
return stateDescriptionBuilder.build();
|
||||||
}
|
}
|
||||||
|
@ -469,8 +469,8 @@ public class ApiPageParser extends AbstractSimpleMarkupHandler {
|
|||||||
}
|
}
|
||||||
ChannelType ct = ChannelTypeBuilder
|
ChannelType ct = ChannelTypeBuilder
|
||||||
.state(new ChannelTypeUID(TACmiBindingConstants.BINDING_ID, shortName), shortName, itemType)
|
.state(new ChannelTypeUID(TACmiBindingConstants.BINDING_ID, shortName), shortName, itemType)
|
||||||
.withDescription("Auto-created for " + shortName)
|
.withDescription("Auto-created for " + shortName).withStateDescriptionFragment(sdb.build())
|
||||||
.withStateDescription(sdb.build().toStateDescription()).build();
|
.build();
|
||||||
channelTypeProvider.addChannelType(ct);
|
channelTypeProvider.addChannelType(ct);
|
||||||
channelBuilder.withType(ct.getUID());
|
channelBuilder.withType(ct.getUID());
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +31,8 @@ import org.openhab.core.thing.type.ChannelType;
|
|||||||
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeProvider;
|
import org.openhab.core.thing.type.ChannelTypeProvider;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
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;
|
import org.openhab.core.types.StateOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,12 +65,12 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
|
|||||||
return channelTypeUID;
|
return channelTypeUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createChannelType(StateDescription state) {
|
private void createChannelType(StateDescriptionFragment state) {
|
||||||
channelType = ChannelTypeBuilder.state(channelTypeUID, "Input source", "String")
|
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<>();
|
List<StateOption> options = new ArrayList<>();
|
||||||
options.add(new StateOption(INPUT_NET_RADIO, "Net Radio"));
|
options.add(new StateOption(INPUT_NET_RADIO, "Net Radio"));
|
||||||
options.add(new StateOption(INPUT_PC, "PC"));
|
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_PANDORA, "Pandora"));
|
||||||
options.add(new StateOption(INPUT_NAPSTER, "Napster"));
|
options.add(new StateOption(INPUT_NAPSTER, "Napster"));
|
||||||
options.add(new StateOption(INPUT_SPOTIFY, "Spotify"));
|
options.add(new StateOption(INPUT_SPOTIFY, "Spotify"));
|
||||||
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
|
return StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false).withOptions(options)
|
||||||
return state;
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeAvailableInputs(Map<String, String> availableInputs) {
|
public void changeAvailableInputs(Map<String, String> availableInputs) {
|
||||||
@ -119,7 +120,8 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
|
|||||||
for (Entry<String, String> inputEntry : availableInputs.entrySet()) {
|
for (Entry<String, String> inputEntry : availableInputs.entrySet()) {
|
||||||
options.add(new StateOption(inputEntry.getKey(), inputEntry.getValue()));
|
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({})
|
@NonNullByDefault({})
|
||||||
|
@ -31,7 +31,8 @@ import org.openhab.core.thing.type.ChannelType;
|
|||||||
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
import org.openhab.core.thing.type.ChannelTypeBuilder;
|
||||||
import org.openhab.core.thing.type.ChannelTypeProvider;
|
import org.openhab.core.thing.type.ChannelTypeProvider;
|
||||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
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;
|
import org.openhab.core.types.StateOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,25 +65,24 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
|
|||||||
return channelTypeUID;
|
return channelTypeUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StateDescription getDefaultStateDescription() {
|
private StateDescriptionFragment getDefaultStateDescription() {
|
||||||
List<StateOption> options = IntStream.rangeClosed(1, 40)
|
List<StateOption> options = IntStream.rangeClosed(1, 40)
|
||||||
.mapToObj(i -> new StateOption(Integer.toString(i), "Item_" + i)).collect(toList());
|
.mapToObj(i -> new StateOption(Integer.toString(i), "Item_" + i)).collect(toList());
|
||||||
|
return StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false).withOptions(options)
|
||||||
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
|
.build();
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changePresetNames(List<PresetInfoState.Preset> presets) {
|
public void changePresetNames(List<PresetInfoState.Preset> presets) {
|
||||||
List<StateOption> options = presets.stream()
|
List<StateOption> options = presets.stream()
|
||||||
.map(preset -> new StateOption(String.valueOf(preset.getValue()), preset.getName())).collect(toList());
|
.map(preset -> new StateOption(String.valueOf(preset.getValue()), preset.getName())).collect(toList());
|
||||||
|
createChannelType(StateDescriptionFragmentBuilder.create().withPattern("%s").withReadOnly(false)
|
||||||
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
|
.withOptions(options).build());
|
||||||
createChannelType(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createChannelType(StateDescription state) {
|
private void createChannelType(StateDescriptionFragment state) {
|
||||||
channelType = ChannelTypeBuilder.state(channelTypeUID, "Preset", "Number")
|
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({})
|
@NonNullByDefault({})
|
||||||
@ -96,8 +96,7 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
|
|||||||
channelTypeUID = new ChannelTypeUID(BINDING_ID,
|
channelTypeUID = new ChannelTypeUID(BINDING_ID,
|
||||||
CHANNEL_PLAYBACK_PRESET_TYPE_NAMED + handler.getThing().getUID().getId());
|
CHANNEL_PLAYBACK_PRESET_TYPE_NAMED + handler.getThing().getUID().getId());
|
||||||
|
|
||||||
StateDescription state = getDefaultStateDescription();
|
createChannelType(getDefaultStateDescription());
|
||||||
createChannelType(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user