Skip to content

Commit 3ad25d6

Browse files
authored
[freeboxos] Add translatable labels for discovered things (openhab#17287)
* [freeboxos] Add translatable labels for discovered things Signed-off-by: Laurent Garnier <[email protected]>
1 parent 5ae87b8 commit 3ad25d6

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public DiscoveryResultBuilder configure(ThingUID bridgeUID, Status config) {
4646
String label;
4747
if (Type.DECT.equals(config.type())) {
4848
thingUID = new ThingUID(THING_TYPE_DECT, bridgeUID, Integer.toString(config.id()));
49-
label = "DECT Phone";
49+
label = "@text/discovery.dect.label";
5050
} else {
5151
thingUID = new ThingUID(THING_TYPE_FXS, bridgeUID, Integer.toString(config.id()));
52-
label = "Landline Phone";
52+
label = "@text/discovery.fxs.label";
5353
}
5454

5555
logger.debug("Adding new Freebox Phone {} to inbox", thingUID);

bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/discovery/FreeboxOsDiscoveryService.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848
import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService;
4949
import org.openhab.core.config.discovery.DiscoveryResult;
5050
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
51+
import org.openhab.core.i18n.LocaleProvider;
52+
import org.openhab.core.i18n.TranslationProvider;
5153
import org.openhab.core.thing.Thing;
5254
import org.openhab.core.thing.ThingStatus;
5355
import org.openhab.core.thing.ThingTypeUID;
5456
import org.openhab.core.thing.ThingUID;
5557
import org.osgi.service.component.annotations.Component;
58+
import org.osgi.service.component.annotations.Reference;
5659
import org.osgi.service.component.annotations.ServiceScope;
5760
import org.slf4j.Logger;
5861
import org.slf4j.LoggerFactory;
@@ -83,6 +86,16 @@ public FreeboxOsDiscoveryService() {
8386
DISCOVERY_TIME_SECONDS);
8487
}
8588

89+
@Reference(unbind = "-")
90+
public void bindTranslationProvider(TranslationProvider translationProvider) {
91+
this.i18nProvider = translationProvider;
92+
}
93+
94+
@Reference(unbind = "-")
95+
public void bindLocaleProvider(LocaleProvider localeProvider) {
96+
this.localeProvider = localeProvider;
97+
}
98+
8699
@Override
87100
protected void startBackgroundDiscovery() {
88101
stopBackgroundDiscovery();
@@ -162,7 +175,7 @@ private void discoverPhone(ThingUID bridgeUID) {
162175
ThingUID thingUID = new ThingUID(THING_TYPE_CALL, bridgeUID, "calls");
163176
logger.debug("Adding new Call thing {} to inbox", thingUID);
164177
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
165-
.withLabel("Phone Calls").build();
178+
.withLabel("@text/discovery.call.label").build();
166179
thingDiscovered(discoveryResult);
167180
}
168181
}
@@ -181,7 +194,8 @@ private void discoverHosts(ThingUID bridgeUID, List<LanHost> lanHosts) {
181194
bridgeUID, mac.toHexString(false));
182195
logger.debug("Adding new Freebox Network Host {} to inbox", thingUID);
183196
DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
184-
.withLabel(lanHost.getPrimaryName().orElse("Network Device %s".formatted(macString)))
197+
.withLabel(lanHost.getPrimaryName()
198+
.orElse("@text/discovery.network-device.label [ \"%s\" ]".formatted(macString)))
185199
.withTTL(300).withProperty(Thing.PROPERTY_MAC_ADDRESS, macString)
186200
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS);
187201
thingDiscovered(builder.build());
@@ -201,7 +215,8 @@ private void discoverVM(ThingUID bridgeUID, List<LanHost> lanHosts) {
201215
logger.debug("Adding new VM Device {} to inbox", thingUID);
202216
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
203217
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS)
204-
.withLabel("%s (VM)".formatted(vm.name())).withProperty(ClientConfiguration.ID, vm.id())
218+
.withLabel("@text/discovery.vm.label [ \"%s\" ]".formatted(vm.name()))
219+
.withProperty(ClientConfiguration.ID, vm.id())
205220
.withProperty(Thing.PROPERTY_MAC_ADDRESS, mac.toColonDelimitedString()).build();
206221
thingDiscovered(discoveryResult);
207222
});
@@ -219,7 +234,7 @@ private void discoverRepeater(ThingUID bridgeUID, List<LanHost> lanHosts) {
219234

220235
ThingUID thingUID = new ThingUID(THING_TYPE_REPEATER, bridgeUID, Integer.toString(repeater.id()));
221236
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
222-
.withLabel("Repeater %s".formatted(repeater.name()))
237+
.withLabel("@text/discovery.repeater.label [ \"%s\" ]".formatted(repeater.name()))
223238
.withProperty(Thing.PROPERTY_MAC_ADDRESS, mac.toColonDelimitedString())
224239
.withProperty(ClientConfiguration.ID, repeater.id())
225240
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).build();

bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties

+9
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ info-host-not-reachable = Host is not reachable
385385
info-player-not-reachable = Player is not reachable
386386
info-vm-not-running = VM is not running
387387

388+
# discovery result
389+
390+
discovery.call.label = Phone Calls
391+
discovery.dect.label = DECT Phone
392+
discovery.fxs.label = Landline Phone
393+
discovery.network-device.label = Network Device {0}
394+
discovery.repeater.label = Repeater {0}
395+
discovery.vm.label = Virtual Machine {0}
396+
388397
# iconprovider
389398

390399
iconset.label = FreeboxOS Icons

0 commit comments

Comments
 (0)