From 511fab73c01590ecb71c94f8a4e06c02615a2100 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Fri, 22 Nov 2024 10:05:32 -0600 Subject: [PATCH] [oppo] Add missing input option and enable translations (#17783) * Add missing input option and enable translations Signed-off-by: Michael Lobstein --- .../oppo/internal/OppoHandlerFactory.java | 12 +++- .../oppo/internal/handler/OppoHandler.java | 60 ++++++++++++------- .../resources/OH-INF/i18n/oppo.properties | 17 ++++++ 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/OppoHandlerFactory.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/OppoHandlerFactory.java index 7478f158d7147..eb0083a811c97 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/OppoHandlerFactory.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/OppoHandlerFactory.java @@ -19,6 +19,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.oppo.internal.handler.OppoHandler; +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; @@ -41,14 +43,19 @@ public class OppoHandlerFactory extends BaseThingHandlerFactory { private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PLAYER); private final SerialPortManager serialPortManager; + private final TranslationProvider translationProvider; + private final LocaleProvider localeProvider; private final OppoStateDescriptionOptionProvider stateDescriptionProvider; @Activate public OppoHandlerFactory(final @Reference OppoStateDescriptionOptionProvider provider, - final @Reference SerialPortManager serialPortManager) { + final @Reference SerialPortManager serialPortManager, @Reference TranslationProvider translationProvider, + @Reference LocaleProvider localeProvider) { this.stateDescriptionProvider = provider; this.serialPortManager = serialPortManager; + this.translationProvider = translationProvider; + this.localeProvider = localeProvider; } @Override @@ -61,7 +68,8 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { - return new OppoHandler(thing, stateDescriptionProvider, serialPortManager); + return new OppoHandler(thing, stateDescriptionProvider, serialPortManager, translationProvider, + localeProvider); } return null; } diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java index 7f6b38b131dfb..0f8ca5c14004f 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java @@ -36,6 +36,8 @@ import org.openhab.binding.oppo.internal.communication.OppoSerialConnector; import org.openhab.binding.oppo.internal.communication.OppoStatusCodes; import org.openhab.binding.oppo.internal.configuration.OppoThingConfiguration; +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.NextPreviousType; @@ -56,6 +58,8 @@ 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; @@ -85,6 +89,10 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis private SerialPortManager serialPortManager; private OppoConnector connector = new OppoDefaultConnector(); + private final TranslationProvider translationProvider; + private final LocaleProvider localeProvider; + private final @Nullable Bundle bundle; + private List inputSourceOptions = new ArrayList<>(); private List hdmiModeOptions = new ArrayList<>(); @@ -105,10 +113,14 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis * Constructor */ public OppoHandler(Thing thing, OppoStateDescriptionOptionProvider stateDescriptionProvider, - SerialPortManager serialPortManager) { + SerialPortManager serialPortManager, TranslationProvider translationProvider, + LocaleProvider localeProvider) { super(thing); this.stateDescriptionProvider = stateDescriptionProvider; this.serialPortManager = serialPortManager; + this.translationProvider = translationProvider; + this.localeProvider = localeProvider; + this.bundle = FrameworkUtil.getBundle(OppoHandler.class); } @Override @@ -842,9 +854,12 @@ private void handleControlCommand(Command command) throws OppoException { } private void buildOptionDropdowns(int model) { + hdmiModeOptions.clear(); + inputSourceOptions.clear(); + if (model == MODEL83 || model == MODEL103 || model == MODEL105) { - hdmiModeOptions.add(new StateOption("AUTO", "Auto")); - hdmiModeOptions.add(new StateOption("SRC", "Source Direct")); + hdmiModeOptions.add(new StateOption("AUTO", getString("auto", "Auto"))); + hdmiModeOptions.add(new StateOption("SRC", getString("direct", "Source Direct"))); if (model != MODEL83) { hdmiModeOptions.add(new StateOption("4K2K", "4K*2K")); } @@ -856,26 +871,27 @@ private void buildOptionDropdowns(int model) { } if (model == MODEL103 || model == MODEL105) { - inputSourceOptions.add(new StateOption("0", "Blu-Ray Player")); - inputSourceOptions.add(new StateOption("1", "HDMI/MHL IN-Front")); - inputSourceOptions.add(new StateOption("2", "HDMI IN-Back")); - inputSourceOptions.add(new StateOption("3", "ARC")); + inputSourceOptions.add(new StateOption("0", getString("blu_ray", "Blu-ray Player"))); + inputSourceOptions.add(new StateOption("1", getString("hdmi_in_front", "HDMI/MHL In-Front"))); + inputSourceOptions.add(new StateOption("2", getString("hdmi_in_back", "HDMI In-Back"))); + inputSourceOptions.add(new StateOption("3", getString("arc1", "ARC 1"))); + inputSourceOptions.add(new StateOption("4", getString("arc2", "ARC 2"))); if (model == MODEL105) { - inputSourceOptions.add(new StateOption("4", "Optical In")); - inputSourceOptions.add(new StateOption("5", "Coaxial In")); - inputSourceOptions.add(new StateOption("6", "USB Audio In")); + inputSourceOptions.add(new StateOption("5", getString("optical", "Optical In"))); + inputSourceOptions.add(new StateOption("6", getString("coaxial", "Coaxial In"))); + inputSourceOptions.add(new StateOption("7", getString("usb", "USB Audio In"))); } } if (model == MODEL203 || model == MODEL205) { - hdmiModeOptions.add(new StateOption("AUTO", "Auto")); - hdmiModeOptions.add(new StateOption("SRC", "Source Direct")); - hdmiModeOptions.add(new StateOption("UHD_AUTO", "UHD Auto")); + hdmiModeOptions.add(new StateOption("AUTO", getString("auto", "Auto"))); + hdmiModeOptions.add(new StateOption("SRC", getString("direct", "Source Direct"))); + hdmiModeOptions.add(new StateOption("UHD_AUTO", getString("auto_uhd", "UHD Auto"))); hdmiModeOptions.add(new StateOption("UHD24", "UHD24")); hdmiModeOptions.add(new StateOption("UHD50", "UHD50")); hdmiModeOptions.add(new StateOption("UHD60", "UHD60")); - hdmiModeOptions.add(new StateOption("1080P_AUTO", "1080P Auto")); + hdmiModeOptions.add(new StateOption("1080P_AUTO", getString("auto_1080p", "1080P Auto"))); hdmiModeOptions.add(new StateOption("1080P24", "1080P24")); hdmiModeOptions.add(new StateOption("1080P50", "1080P50")); hdmiModeOptions.add(new StateOption("1080P60", "1080P60")); @@ -888,18 +904,22 @@ private void buildOptionDropdowns(int model) { hdmiModeOptions.add(new StateOption("480P", "480P")); hdmiModeOptions.add(new StateOption("480I", "480I")); - inputSourceOptions.add(new StateOption("0", "Blu-Ray Player")); - inputSourceOptions.add(new StateOption("1", "HDMI IN")); - inputSourceOptions.add(new StateOption("2", "ARC")); + inputSourceOptions.add(new StateOption("0", getString("blu_ray", "Blu-ray Player"))); + inputSourceOptions.add(new StateOption("1", getString("hdmi_in", "HDMI In"))); + inputSourceOptions.add(new StateOption("2", getString("arc", "ARC"))); if (model == MODEL205) { - inputSourceOptions.add(new StateOption("3", "Optical In")); - inputSourceOptions.add(new StateOption("4", "Coaxial In")); - inputSourceOptions.add(new StateOption("5", "USB Audio In")); + inputSourceOptions.add(new StateOption("3", getString("optical", "Optical In"))); + inputSourceOptions.add(new StateOption("4", getString("coaxial", "Coaxial In"))); + inputSourceOptions.add(new StateOption("5", getString("usb", "USB Audio In"))); } } } + private @Nullable String getString(String i18nKey, String defaultStr) { + return translationProvider.getText(bundle, "option." + i18nKey, defaultStr, localeProvider.getLocale()); + } + private void handleHdmiModeUpdate(String updateData) { // ugly... a couple of the query hdmi mode response codes on the earlier models don't match the code to set it // some of this protocol is weird like that... diff --git a/bundles/org.openhab.binding.oppo/src/main/resources/OH-INF/i18n/oppo.properties b/bundles/org.openhab.binding.oppo/src/main/resources/OH-INF/i18n/oppo.properties index 6cefab948ae2a..3821d9cf947b0 100644 --- a/bundles/org.openhab.binding.oppo/src/main/resources/OH-INF/i18n/oppo.properties +++ b/bundles/org.openhab.binding.oppo/src/main/resources/OH-INF/i18n/oppo.properties @@ -163,3 +163,20 @@ channel-type.oppo.zoom_mode.state.option.09 = 4x channel-type.oppo.zoom_mode.state.option.10 = 1/2 channel-type.oppo.zoom_mode.state.option.11 = 1/3 channel-type.oppo.zoom_mode.state.option.12 = 1/4 + +# selectable player option descriptions + +option.arc = ARC +option.arc1 = ARC 1 +option.arc2 = ARC 2 +option.auto = Auto +option.auto_1080p = 1080P Auto +option.auto_uhd = UHD Auto +option.blu_ray = Blu-ray Player +option.coaxial = Coaxial In +option.direct = Source Direct +option.hdmi_in = HDMI In +option.hdmi_in_back = HDMI In-Back +option.hdmi_in_front = HDMI/MHL In-Front +option.optical = Optical In +option.usb = USB Audio In