[rotel] Use @text for state options labels (#11468)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2021-10-29 11:41:55 +02:00 committed by GitHub
parent 7de37c6cc4
commit 264e19dbfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 26 deletions

View 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;

View 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;
}