]> git.basschouten.com Git - openhab-addons.git/commitdiff
Fix StateDescription deprecations (#9352)
authorWouter Born <github@maindrain.net>
Sun, 13 Dec 2020 07:53:16 +0000 (08:53 +0100)
committerGitHub <noreply@github.com>
Sun, 13 Dec 2020 07:53:16 +0000 (08:53 +0100)
Related to #1408

Signed-off-by: Wouter Born <github@maindrain.net>
12 files changed:
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/providers/DsChannelTypeProvider.java
bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyDeviceHandler.java
bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyHubHandler.java
bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200ThingHandler.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/CChannel.java
bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Property.java
bundles/org.openhab.binding.networkupstools/src/main/java/org/openhab/binding/networkupstools/internal/NUTDynamicChannelFactory.java
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java
bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterChannelTypeProvider.java
bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ApiPageParser.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/ChannelsTypeProviderAvailableInputs.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/ChannelsTypeProviderPreset.java

index b57157b1f696174b11dcf4524dab4543b25f30ce..78c04b195699a9ee283143380f537db5e46d6db8 100644 (file)
@@ -37,7 +37,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;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
@@ -322,7 +323,7 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
         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
         // shown in °C so we will use this unit for temperature sensors
         String unitShortCut = sensorType.getUnitShortcut();
@@ -332,14 +333,15 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
         if (sensorType.toString().contains("TEMPERATURE")) {
             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) {
         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())) {
             List<StateOption> stateOptions = new ArrayList<>();
             if (channelID.contains(LIGHT)) {
@@ -369,11 +371,12 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
                             locale)));
                 }
             }
-            return new StateDescription(null, null, null, null, false, stateOptions);
+            return StateDescriptionFragmentBuilder.create().withReadOnly(false).withOptions(stateOptions).build();
         }
         if (channelID.contains(TEMPERATURE_CONTROLLED)) {
-            return new StateDescription(new BigDecimal(0), new BigDecimal(50), new BigDecimal(0.1), "%.1f °C", false,
-                    null);
+            return StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(0))
+                    .withMaximum(new BigDecimal(50)).withStep(new BigDecimal(0.1)).withPattern("%.1f °C")
+                    .withReadOnly(false).build();
         }
         return null;
     }
@@ -485,14 +488,14 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
                 return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
                         .withDescription(getDescText(channelID, locale)).withCategory(getSensorCategory(sensorType))
                         .withTags(getSimpleTags(channelID, locale))
-                        .withStateDescription(getSensorStateDescription(sensorType)).build();
+                        .withStateDescriptionFragment(getSensorStateDescription(sensorType)).build();
             } catch (IllegalArgumentException e) {
                 if (SUPPORTED_OUTPUT_CHANNEL_TYPES.contains(channelID)) {
                     return ChannelTypeBuilder
                             .state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
                             .withDescription(getDescText(channelID, locale)).withCategory(getCategory(channelID))
                             .withTags(getTags(channelID, locale))
-                            .withStateDescription(getStageDescription(channelID, locale)).build();
+                            .withStateDescriptionFragment(getStageDescription(channelID, locale)).build();
                 }
                 MeteringTypeEnum meteringType = getMeteringType(channelID);
                 if (meteringType != null) {
@@ -501,11 +504,14 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
                     if (MeteringTypeEnum.CONSUMPTION.equals(meteringType)) {
                         pattern = "%d W";
                     }
+
                     return ChannelTypeBuilder.state(channelTypeUID, getLabelText(channelID, locale), NUMBER)
                             .withDescription(getDescText(channelID, locale)).withCategory(CATEGORY_ENERGY)
                             .withTags(
                                     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 {
                     DeviceBinarayInputEnum binarayInputType = DeviceBinarayInputEnum
@@ -514,8 +520,9 @@ public class DsChannelTypeProvider extends BaseDsI18n implements ChannelTypeProv
                             .state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
                             .withDescription(getDescText(channelID, locale))
                             .withCategory(getBinaryInputCategory(binarayInputType))
-                            .withTags(getSimpleTags(channelTypeUID.getId(), locale))
-                            .withStateDescription(new StateDescription(null, null, null, null, true, null)).build();
+                            .withTags(getSimpleTags(channelTypeUID.getId(), locale)).withStateDescriptionFragment(
+                                    StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
+                            .build();
                 } catch (IllegalArgumentException e1) {
                     // ignore
                 }
index 6ad929c511a03ebe5b3e13ddbefce7eec27bce73..5d788bf9fbad951b9f92f55961c59ced7bee957e 100644 (file)
@@ -41,7 +41,7 @@ import org.openhab.core.thing.type.ChannelTypeBuilder;
 import org.openhab.core.thing.type.ChannelTypeUID;
 import org.openhab.core.types.Command;
 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.UnDefType;
 import org.slf4j.Logger;
@@ -187,7 +187,8 @@ public class HarmonyDeviceHandler extends BaseThingHandler {
 
         ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Send Button Press", "String")
                 .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);
 
index 804fe3af6de7dc833316b609230e63f3b97a8631..bbfa099ab5f49f51a989a9e60d8bf7291b00a3ad 100644 (file)
@@ -50,7 +50,7 @@ import org.openhab.core.thing.type.ChannelTypeBuilder;
 import org.openhab.core.thing.type.ChannelTypeUID;
 import org.openhab.core.types.Command;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -382,7 +382,9 @@ public class HarmonyHubHandler extends BaseBridgeHandler implements HarmonyClien
 
         ChannelType channelType = ChannelTypeBuilder.state(channelTypeUID, "Current Activity", "String")
                 .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);
 
index eb771ddab210ba8002d4ffcb78bbb0257cda1802..8b170faa7885cde5c518c5f6bb553d5baeaf8f09 100644 (file)
@@ -189,7 +189,7 @@ public class KM200ThingHandler extends BaseThingHandler {
                     .withDescription(description) //
                     .withCategory(checkCategory(unitOfMeasure, category, state.isReadOnly())) //
                     .withTags(checkTags(unitOfMeasure, state.isReadOnly())) //
-                    .withStateDescription(state.toStateDescription()) //
+                    .withStateDescriptionFragment(state) //
                     .withConfigDescriptionURI(configDescriptionUriChannel).build();
         } catch (URISyntaxException ex) {
             logger.warn("Can't create ConfigDescription URI '{}', ConfigDescription for channels not avilable!",
index 67a78909b7b9e68501f886843294a18fb7cd98c9..5ec45732c6d8d901328b118e240e45bf341349e0 100644 (file)
@@ -38,7 +38,7 @@ import org.openhab.core.thing.type.ChannelDefinitionBuilder;
 import org.openhab.core.thing.type.ChannelType;
 import org.openhab.core.thing.type.ChannelTypeBuilder;
 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.
@@ -208,11 +208,10 @@ public class CChannel {
                 type = ChannelTypeBuilder.trigger(channelTypeUID, label)
                         .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL)).build();
             } else {
-                StateDescription description = valueState.createStateDescription(command_topic == null).build()
-                        .toStateDescription();
+                StateDescriptionFragment description = valueState.createStateDescription(command_topic == null).build();
                 type = ChannelTypeBuilder.state(channelTypeUID, label, channelState.getItemType())
                         .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL))
-                        .withStateDescription(description).build();
+                        .withStateDescriptionFragment(description).build();
             }
 
             Configuration configuration = new Configuration();
index 277b2c74dd8ba2f4e2a6f9ad7d5afe5965cc285e..862bd10eafc442956176a97883f6e8641a24cb6c 100644 (file)
@@ -142,8 +142,8 @@ public class Property implements AttributeChanged {
         if (attributes.retained) {
             return ChannelTypeBuilder.state(channelTypeUID, attributes.name, channelState.getItemType())
                     .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HOMIE_CHANNEL))
-                    .withStateDescription(channelState.getCache().createStateDescription(!attributes.settable).build()
-                            .toStateDescription())
+                    .withStateDescriptionFragment(
+                            channelState.getCache().createStateDescription(!attributes.settable).build())
                     .build();
         } else {
             // Non-retained and settable property -> State channel
index 7ce7a25a5b71fbf91ffe9da81b01a5905b1de43d..f08fc1c13e44997b9139db1525c0deaad865b1e8 100644 (file)
@@ -113,7 +113,7 @@ class NUTDynamicChannelFactory {
         final ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channel.getUID().getId() + "Type");
         final String label = channel.getLabel();
         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();
         channelTypeProvider.addChannelType(channelType);
         return channelTypeUID;
index ff765a25c5ea76a86b64804da16663c17aea224b..93e36d16d6936c5adf21c1b84856c220da290ffc 100644 (file)
@@ -389,7 +389,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
             stateDescription = stateDescription.withPattern(pattern);
         }
         final StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
-                .withStateDescription(stateDescription.build().toStateDescription());
+                .withStateDescriptionFragment(stateDescription.build());
         if (tag != null) {
             builder.withTag(tag);
         }
index 802bc4270fe94514ebd51651673db2f7520a3a37..d3adba2dc90fc23138e1463248ef81c70ac3d62a 100644 (file)
@@ -83,16 +83,14 @@ public class SmartMeterChannelTypeProvider implements ChannelTypeProvider, Meter
             stateDescriptionBuilder = ChannelTypeBuilder
                     .state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
                             CoreItemFactory.NUMBER + ":" + dimension)
-                    .withStateDescription(StateDescriptionFragmentBuilder.create().withReadOnly(true)
-                            .withPattern("%.2f %unit%").build().toStateDescription())
+                    .withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true)
+                            .withPattern("%.2f %unit%").build())
                     .withConfigDescriptionURI(URI.create(SmartMeterBindingConstants.CHANNEL_TYPE_METERREADER_OBIS));
         } else {
             stateDescriptionBuilder = ChannelTypeBuilder
                     .state(new ChannelTypeUID(SmartMeterBindingConstants.BINDING_ID, obisChannelId), obis,
                             CoreItemFactory.STRING)
-                    .withStateDescription(
-                            StateDescriptionFragmentBuilder.create().withReadOnly(true).build().toStateDescription());
-
+                    .withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build());
         }
         return stateDescriptionBuilder.build();
     }
index 872e2b0e9d3d83038c660db2cf733f56d99bf329..58534bc809f23938d3853e10d4ce90b7097d4fe9 100644 (file)
@@ -469,8 +469,8 @@ public class ApiPageParser extends AbstractSimpleMarkupHandler {
                     }
                     ChannelType ct = ChannelTypeBuilder
                             .state(new ChannelTypeUID(TACmiBindingConstants.BINDING_ID, shortName), shortName, itemType)
-                            .withDescription("Auto-created for " + shortName)
-                            .withStateDescription(sdb.build().toStateDescription()).build();
+                            .withDescription("Auto-created for " + shortName).withStateDescriptionFragment(sdb.build())
+                            .build();
                     channelTypeProvider.addChannelType(ct);
                     channelBuilder.withType(ct.getUID());
                 } else {
index 4f46ac88c3a2c1cb9216ac10150adc14b0697e5e..b27bb2a9c30c006d66bb140293aefacd9908be93 100644 (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({})
index 1346e88902136978fccdc0ff7036e0aeec5b1505..2e4f5210c502e29a8d3b1b4b0141504662cb448e 100644 (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