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"));
}
}
}
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
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);
}));
}
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