]> git.basschouten.com Git - openhab-addons.git/commitdiff
[netatmo] Localized label/pattern for dynamic channel types (#13012)
authorlolodomo <lg.hc@free.fr>
Mon, 27 Jun 2022 16:09:37 +0000 (18:09 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Jun 2022 16:09:37 +0000 (18:09 +0200)
* [netatmo] Localized label/pattern for dynamic channel types
* Review comment about key naming
* Fix label for timestamp extensible channel types

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/providers/NetatmoChannelTypeProvider.java
bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties

index fdd7d2340b85906f6bd7c4c8000be972f992a099..737e6b8425621c8a1baebd478e58e63025eac86a 100644 (file)
@@ -107,8 +107,8 @@ public class NetatmoConstants {
                         new MeasureChannelDetails(confFragment, String.join(":", NUMBER, dimension),
                                 String.format("%%.%df %s", measureDefinition.scale, UnitUtils.UNIT_PLACEHOLDER)));
                 if (canScale) {
-                    channels.put(String.join("-", apiDescriptor, GROUP_TIMESTAMP),
-                            new MeasureChannelDetails(GROUP_TIMESTAMP, DATETIME, "%1$tA, %1$td.%1$tm. %1$tH:%1$tM"));
+                    channels.put(String.join("-", apiDescriptor, GROUP_TIMESTAMP), new MeasureChannelDetails(
+                            GROUP_TIMESTAMP, DATETIME, "@text/extensible-channel-type.timestamp.pattern"));
                 }
             }
         }
index 42fe411ce496ca81c5d77f1e66add509a2d7d03e..e8972cf3c0b324c0116aec4077c2b4029e64c473 100644 (file)
@@ -22,17 +22,24 @@ import java.util.Locale;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
+import org.openhab.core.i18n.LocaleProvider;
+import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
 import org.openhab.core.thing.type.ChannelType;
 import org.openhab.core.thing.type.ChannelTypeBuilder;
 import org.openhab.core.thing.type.ChannelTypeProvider;
 import org.openhab.core.thing.type.ChannelTypeUID;
 import org.openhab.core.thing.type.StateChannelTypeBuilder;
+import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Extends the ChannelTypeProvider generating Channel Types based on {@link MeasureClass} enum.
  *
  * @author GaĆ«l L'hopital - Initial contribution
+ * @author Laurent Garnier - Localizing the extensible channel types
  *
  */
 @NonNullByDefault
@@ -40,15 +47,20 @@ import org.osgi.service.component.annotations.Component;
 public class NetatmoChannelTypeProvider implements ChannelTypeProvider {
     private final Collection<ChannelType> channelTypes = new HashSet<>();
 
-    public NetatmoChannelTypeProvider() {
+    @Activate
+    public NetatmoChannelTypeProvider(final @Reference ChannelTypeI18nLocalizationService localizationService,
+            final @Reference LocaleProvider localeProvider, ComponentContext componentContext) {
+        final Bundle bundle = componentContext.getBundleContext().getBundle();
         MeasureClass.AS_SET.forEach(mc -> mc.channels.forEach((measureChannel, channelDetails) -> {
             StateChannelTypeBuilder channelTypeBuilder = ChannelTypeBuilder
-                    .state(new ChannelTypeUID(BINDING_ID, measureChannel), measureChannel.replace("-", " "),
+                    .state(new ChannelTypeUID(BINDING_ID, measureChannel),
+                            String.format("@text/extensible-channel-type.%s.label", measureChannel),
                             channelDetails.itemType)
                     .withStateDescriptionFragment(channelDetails.stateDescriptionFragment)
                     .withConfigDescriptionURI(channelDetails.configURI);
-
-            channelTypes.add(channelTypeBuilder.build());
+            ChannelType channelType = localizationService.createLocalizedChannelType(bundle, channelTypeBuilder.build(),
+                    localeProvider.getLocale());
+            channelTypes.add(channelType);
         }));
     }
 
index c0f5a687799677a84632b5847b240e6e69c0c73c..51f17f9b90e42ffb4a6128d546528d7963d979a3 100644 (file)
@@ -354,6 +354,21 @@ config.period.option.1day = This day
 config.period.option.1week = This week
 config.period.option.1month = This month
 
+# extensible channel types
+
+extensible-channel-type.co2-measurement.label = CO2 Measurement
+extensible-channel-type.co2-timestamp.label = CO2 Measurement Timestamp
+extensible-channel-type.hum-measurement.label = Humidity Measurement
+extensible-channel-type.hum-timestamp.label = Humidity Measurement Timestamp
+extensible-channel-type.noise-measurement.label = Noise Measurement
+extensible-channel-type.noise-timestamp.label = Noise Measurement Timestamp
+extensible-channel-type.pressure-measurement.label = Pressure Measurement
+extensible-channel-type.pressure-timestamp.label = Pressure Measurement Timestamp
+extensible-channel-type.sum_rain-measurement.label = Summing Rain Measurement
+extensible-channel-type.temp-measurement.label = Temperature Measurement
+extensible-channel-type.temp-timestamp.label = Temperature Measurement Timestamp
+extensible-channel-type.timestamp.pattern = %1$tA, %1$td.%1$tm. %1$tH:%1$tM
+
 # thing types
 
 thing-type.netatmo.account.label = Netatmo Account