]> git.basschouten.com Git - openhab-addons.git/commitdiff
[rotel] Use @text for state options labels (#11468)
authorlolodomo <lg.hc@free.fr>
Fri, 29 Oct 2021 09:41:55 +0000 (11:41 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Oct 2021 09:41:55 +0000 (11:41 +0200)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/RotelHandlerFactory.java
bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/handler/RotelHandler.java

index 376f9dad181d9c8af4100712887b2dbed8b09f52..bbf72a4a107fe3aa568d4b4aaaf2977b672f784d 100644 (file)
@@ -22,8 +22,6 @@ import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.rotel.internal.handler.RotelHandler;
-import org.openhab.core.i18n.LocaleProvider;
-import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingTypeUID;
@@ -57,17 +55,12 @@ public class RotelHandlerFactory extends BaseThingHandlerFactory {
 
     private final SerialPortManager serialPortManager;
     private final RotelStateDescriptionOptionProvider stateDescriptionProvider;
-    private final TranslationProvider i18nProvider;
-    private final LocaleProvider localeProvider;
 
     @Activate
     public RotelHandlerFactory(final @Reference SerialPortManager serialPortManager,
-            final @Reference RotelStateDescriptionOptionProvider stateDescriptionProvider,
-            final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider) {
+            final @Reference RotelStateDescriptionOptionProvider stateDescriptionProvider) {
         this.serialPortManager = serialPortManager;
         this.stateDescriptionProvider = stateDescriptionProvider;
-        this.i18nProvider = i18nProvider;
-        this.localeProvider = localeProvider;
     }
 
     @Override
@@ -80,7 +73,7 @@ public class RotelHandlerFactory extends BaseThingHandlerFactory {
         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
 
         if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
-            return new RotelHandler(thing, stateDescriptionProvider, serialPortManager, i18nProvider, localeProvider);
+            return new RotelHandler(thing, stateDescriptionProvider, serialPortManager);
         }
 
         return null;
index b28a7843fae6bc4bfb11eb3e5e065c9e60be08ba..dee9a28ed44778966212cfa02463db2ef41605af 100644 (file)
@@ -41,8 +41,6 @@ import org.openhab.binding.rotel.internal.communication.RotelSerialConnector;
 import org.openhab.binding.rotel.internal.communication.RotelSimuConnector;
 import org.openhab.binding.rotel.internal.communication.RotelSource;
 import org.openhab.binding.rotel.internal.configuration.RotelThingConfiguration;
-import org.openhab.core.i18n.LocaleProvider;
-import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.IncreaseDecreaseType;
@@ -61,8 +59,6 @@ import org.openhab.core.types.RefreshType;
 import org.openhab.core.types.State;
 import org.openhab.core.types.StateOption;
 import org.openhab.core.types.UnDefType;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.FrameworkUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -89,9 +85,6 @@ public class RotelHandler extends BaseThingHandler implements RotelMessageEventL
 
     private RotelStateDescriptionOptionProvider stateDescriptionProvider;
     private SerialPortManager serialPortManager;
-    private TranslationProvider i18nProvider;
-    private LocaleProvider localeProvider;
-    private Bundle bundle;
 
     private RotelConnector connector = new RotelSimuConnector(DEFAULT_MODEL, RotelProtocol.HEX, new HashMap<>(),
             "OH-binding-rotel");
@@ -139,13 +132,10 @@ public class RotelHandler extends BaseThingHandler implements RotelMessageEventL
      * Constructor
      */
     public RotelHandler(Thing thing, RotelStateDescriptionOptionProvider stateDescriptionProvider,
-            SerialPortManager serialPortManager, TranslationProvider i18nProvider, LocaleProvider localeProvider) {
+            SerialPortManager serialPortManager) {
         super(thing);
         this.stateDescriptionProvider = stateDescriptionProvider;
         this.serialPortManager = serialPortManager;
-        this.i18nProvider = i18nProvider;
-        this.localeProvider = localeProvider;
-        this.bundle = FrameworkUtil.getBundle(this.getClass()).getBundleContext().getBundle();
     }
 
     @Override
@@ -455,12 +445,7 @@ public class RotelHandler extends BaseThingHandler implements RotelMessageEventL
         List<StateOption> options = new ArrayList<>();
         for (RotelSource item : list) {
             String label = sourcesLabels.get(item);
-            String key = "source." + item.getName();
-            String label2 = i18nProvider.getText(bundle, key, key, localeProvider.getLocale());
-            if (label2 == null || label2.isEmpty()) {
-                label2 = key;
-            }
-            options.add(new StateOption(item.getName(), label == null ? label2 : label));
+            options.add(new StateOption(item.getName(), label == null ? ("@text/source." + item.getName()) : label));
         }
         return options;
     }