Skip to content

Commit

Permalink
[rotel] Use @text for state options labels (openhab#11468)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Oct 29, 2021
1 parent e32e957 commit c71bcac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
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;
Expand Down Expand Up @@ -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
Expand All @@ -80,7 +73,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
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;
Expand All @@ -61,8 +59,6 @@
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;

Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -455,12 +445,7 @@ public List<StateOption> getStateOptions(List<RotelSource> list, Map<RotelSource
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;
}
Expand Down

0 comments on commit c71bcac

Please sign in to comment.