]> git.basschouten.com Git - openhab-addons.git/commitdiff
[freeboxos] Add translatable labels for discovered things (#17287)
authorlolodomo <lg.hc@free.fr>
Mon, 19 Aug 2024 07:19:11 +0000 (09:19 +0200)
committerGitHub <noreply@github.com>
Mon, 19 Aug 2024 07:19:11 +0000 (09:19 +0200)
* [freeboxos] Add translatable labels for discovered things

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/discovery/FreeboxOsDiscoveryService.java
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties

index a474b4c59a37a4898f32b836ab5cb3aa91f91cf9..5dd1fcfe74ce46efbb661d61c79e6e2a70da63bf 100644 (file)
@@ -46,10 +46,10 @@ public class PhoneConfigurationBuilder {
         String label;
         if (Type.DECT.equals(config.type())) {
             thingUID = new ThingUID(THING_TYPE_DECT, bridgeUID, Integer.toString(config.id()));
-            label = "DECT Phone";
+            label = "@text/discovery.dect.label";
         } else {
             thingUID = new ThingUID(THING_TYPE_FXS, bridgeUID, Integer.toString(config.id()));
-            label = "Landline Phone";
+            label = "@text/discovery.fxs.label";
         }
 
         logger.debug("Adding new Freebox Phone {} to inbox", thingUID);
index aa40187ff1661bfde04d86bb5b35a5a7147a352d..c137038fef108c796ba69c6710d53e70205bc011 100644 (file)
@@ -48,11 +48,14 @@ import org.openhab.binding.freeboxos.internal.handler.FreeboxOsHandler;
 import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService;
 import org.openhab.core.config.discovery.DiscoveryResult;
 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
+import org.openhab.core.i18n.LocaleProvider;
+import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.thing.ThingUID;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.component.annotations.ServiceScope;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,6 +86,16 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ
                 DISCOVERY_TIME_SECONDS);
     }
 
+    @Reference(unbind = "-")
+    public void bindTranslationProvider(TranslationProvider translationProvider) {
+        this.i18nProvider = translationProvider;
+    }
+
+    @Reference(unbind = "-")
+    public void bindLocaleProvider(LocaleProvider localeProvider) {
+        this.localeProvider = localeProvider;
+    }
+
     @Override
     protected void startBackgroundDiscovery() {
         stopBackgroundDiscovery();
@@ -162,7 +175,7 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ
             ThingUID thingUID = new ThingUID(THING_TYPE_CALL, bridgeUID, "calls");
             logger.debug("Adding new Call thing {} to inbox", thingUID);
             DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
-                    .withLabel("Phone Calls").build();
+                    .withLabel("@text/discovery.call.label").build();
             thingDiscovered(discoveryResult);
         }
     }
@@ -181,7 +194,8 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ
                         bridgeUID, mac.toHexString(false));
                 logger.debug("Adding new Freebox Network Host {} to inbox", thingUID);
                 DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
-                        .withLabel(lanHost.getPrimaryName().orElse("Network Device %s".formatted(macString)))
+                        .withLabel(lanHost.getPrimaryName()
+                                .orElse("@text/discovery.network-device.label [ \"%s\" ]".formatted(macString)))
                         .withTTL(300).withProperty(Thing.PROPERTY_MAC_ADDRESS, macString)
                         .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS);
                 thingDiscovered(builder.build());
@@ -201,7 +215,8 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ
                 logger.debug("Adding new VM Device {} to inbox", thingUID);
                 DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
                         .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS)
-                        .withLabel("%s (VM)".formatted(vm.name())).withProperty(ClientConfiguration.ID, vm.id())
+                        .withLabel("@text/discovery.vm.label [ \"%s\" ]".formatted(vm.name()))
+                        .withProperty(ClientConfiguration.ID, vm.id())
                         .withProperty(Thing.PROPERTY_MAC_ADDRESS, mac.toColonDelimitedString()).build();
                 thingDiscovered(discoveryResult);
             });
@@ -219,7 +234,7 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ
 
                 ThingUID thingUID = new ThingUID(THING_TYPE_REPEATER, bridgeUID, Integer.toString(repeater.id()));
                 DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
-                        .withLabel("Repeater %s".formatted(repeater.name()))
+                        .withLabel("@text/discovery.repeater.label [ \"%s\" ]".formatted(repeater.name()))
                         .withProperty(Thing.PROPERTY_MAC_ADDRESS, mac.toColonDelimitedString())
                         .withProperty(ClientConfiguration.ID, repeater.id())
                         .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).build();
index fbe6c125853a385e036a1f75234ecc77aa05cdc9..1cd0d21c1f761d6243aaa83701623d0545d3334d 100644 (file)
@@ -385,6 +385,15 @@ info-host-not-reachable = Host is not reachable
 info-player-not-reachable = Player is not reachable
 info-vm-not-running = VM is not running
 
+# discovery result
+
+discovery.call.label = Phone Calls
+discovery.dect.label = DECT Phone
+discovery.fxs.label = Landline Phone
+discovery.network-device.label = Network Device {0}
+discovery.repeater.label = Repeater {0}
+discovery.vm.label = Virtual Machine {0}
+
 # iconprovider
 
 iconset.label = FreeboxOS Icons