use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class DefaultSystemChannelTypeProvider method getChannelTypes.
@Override
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
final List<ChannelType> allChannelTypes = new ArrayList<>();
final Bundle bundle = bundleResolver.resolveBundle(DefaultSystemChannelTypeProvider.class);
for (final ChannelType channelType : CHANNEL_TYPES) {
allChannelTypes.add(createLocalizedChannelType(bundle, channelType, locale));
}
return allChannelTypes;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class DefaultSystemChannelTypeProvider method createLocalizedChannelType.
private ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, @Nullable Locale locale) {
LocalizedKey localizedKey = new LocalizedKey(channelType.getUID(), locale != null ? locale.toLanguageTag() : null);
ChannelType cachedEntry = localizedChannelTypeCache.get(localizedKey);
if (cachedEntry != null) {
return cachedEntry;
}
ChannelType localizedChannelType = channelTypeI18nLocalizationService.createLocalizedChannelType(bundle, channelType, locale);
if (localizedChannelType != null) {
localizedChannelTypeCache.put(localizedKey, localizedChannelType);
return localizedChannelType;
} else {
return channelType;
}
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class ChannelI18nUtil method createLocalizedChannelDefinitions.
public List<ChannelDefinition> createLocalizedChannelDefinitions(final Bundle bundle, final List<ChannelDefinition> channelDefinitions, final Function<ChannelDefinition, @Nullable String> channelLabelResolver, final Function<ChannelDefinition, @Nullable String> channelDescriptionResolver, @Nullable final Locale locale) {
List<ChannelDefinition> localizedChannelDefinitions = new ArrayList<>(channelDefinitions.size());
for (final ChannelDefinition channelDefinition : channelDefinitions) {
final ChannelDefinitionBuilder builder = new ChannelDefinitionBuilder(channelDefinition);
String channelLabel = channelLabelResolver.apply(channelDefinition);
String channelDescription = channelDescriptionResolver.apply(channelDefinition);
if (channelLabel == null || channelDescription == null) {
ChannelTypeUID channelTypeUID = channelDefinition.getChannelTypeUID();
ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID, locale);
if (channelType != null) {
ChannelType localizedChannelType = channelTypeI18nLocalizationService.createLocalizedChannelType(bundle, channelType, locale);
if (channelLabel == null) {
channelLabel = localizedChannelType.getLabel();
}
if (channelDescription == null) {
channelDescription = localizedChannelType.getDescription();
}
}
}
builder.withLabel(channelLabel);
builder.withDescription(channelDescription);
localizedChannelDefinitions.add(builder.build());
}
return localizedChannelDefinitions;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class SystemWideChannelTypesTest method systemChannelTypesShouldBeTranslatedProperly.
@Test
public void systemChannelTypesShouldBeTranslatedProperly() {
Collection<ChannelType> localizedChannelTypes = systemChannelTypeProvider.getChannelTypes(Locale.GERMAN);
assertEquals(NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES, localizedChannelTypes.size());
ChannelType signalStrengthChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_SIGNAL_STRENGTH, Locale.GERMAN);
assertNotNull(signalStrengthChannelType);
assertEquals("Signalstärke", signalStrengthChannelType.getLabel());
assertNull(signalStrengthChannelType.getDescription());
StateDescription stateDescription = signalStrengthChannelType.getState();
if (stateDescription != null) {
List<StateOption> signalStrengthChannelTypeOptions = stateDescription.getOptions();
assertEquals(5, signalStrengthChannelTypeOptions.size());
StateOption noSignalOption = signalStrengthChannelTypeOptions.stream().filter(it -> "0".equals(it.getValue())).findFirst().get();
assertNotNull(noSignalOption);
assertEquals("Kein Signal", noSignalOption.getLabel());
StateOption weakOption = signalStrengthChannelTypeOptions.stream().filter(it -> "1".equals(it.getValue())).findFirst().get();
assertNotNull(weakOption);
assertEquals("Schwach", weakOption.getLabel());
StateOption averageOption = signalStrengthChannelTypeOptions.stream().filter(it -> "2".equals(it.getValue())).findFirst().get();
assertNotNull(averageOption);
assertEquals("Durchschnittlich", averageOption.getLabel());
StateOption goodOption = signalStrengthChannelTypeOptions.stream().filter(it -> "3".equals(it.getValue())).findFirst().get();
assertNotNull(goodOption);
assertEquals("Gut", goodOption.getLabel());
StateOption excellentOption = signalStrengthChannelTypeOptions.stream().filter(it -> "4".equals(it.getValue())).findFirst().get();
assertNotNull(excellentOption);
assertEquals("Ausgezeichnet", excellentOption.getLabel());
}
ChannelType lowBatteryChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_LOW_BATTERY, Locale.GERMAN);
assertNotNull(lowBatteryChannelType);
assertEquals("Niedriger Batteriestatus", lowBatteryChannelType.getLabel());
assertNull(lowBatteryChannelType.getDescription());
ChannelType batteryLevelChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_BATTERY_LEVEL, Locale.GERMAN);
assertNotNull(batteryLevelChannelType);
assertEquals("Batterieladung", batteryLevelChannelType.getLabel());
assertNull(batteryLevelChannelType.getDescription());
ChannelType powerChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_POWER, Locale.GERMAN);
assertNotNull(powerChannelType);
assertEquals("Betrieb", powerChannelType.getLabel());
assertEquals("Steuert die Betriebsbereitschaft. Bei ON ist das Gerät betriebsbereit, bei OFF nicht.", powerChannelType.getDescription());
ChannelType locationChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_LOCATION, Locale.GERMAN);
assertNotNull(locationChannelType);
assertEquals("Ort", locationChannelType.getLabel());
assertEquals("Zeigt einen Ort in geographischen Koordinaten (Breitengrad/Längengrad/Höhe) an.", locationChannelType.getDescription());
ChannelType motionChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_MOTION, Locale.GERMAN);
assertNotNull(motionChannelType);
assertEquals("Bewegung", motionChannelType.getLabel());
assertEquals("Zeigt eine erkannte Bewegung an.", motionChannelType.getDescription());
ChannelType brightnessChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_BRIGHTNESS, Locale.GERMAN);
assertNotNull(brightnessChannelType);
assertEquals("Helligkeit", brightnessChannelType.getLabel());
assertEquals("Steuert die Helligkeit und schaltet das Licht ein und aus.", brightnessChannelType.getDescription());
ChannelType colorChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_COLOR, Locale.GERMAN);
assertNotNull(colorChannelType);
assertEquals("Farbe", colorChannelType.getLabel());
assertEquals("Steuert die Farbe, die Helligkeit und schaltet das Licht ein und aus.", colorChannelType.getDescription());
ChannelType colorTemperatureChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_COLOR_TEMPERATURE, Locale.GERMAN);
assertNotNull(colorTemperatureChannelType);
assertEquals("Farbtemperatur", colorTemperatureChannelType.getLabel());
assertEquals("Steuert die Farbtemperatur des Lichts von 0 (kalt) bis 100 (warm).", colorTemperatureChannelType.getDescription());
ChannelType colorTemperatureAbsChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_COLOR_TEMPERATURE_ABS, Locale.GERMAN);
assertNotNull(colorTemperatureAbsChannelType);
assertEquals("Farbtemperatur", colorTemperatureAbsChannelType.getLabel());
assertEquals("Steuert die Farbtemperatur des Lichts (in Kelvin).", colorTemperatureAbsChannelType.getDescription());
ChannelType volumeChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_VOLUME, Locale.GERMAN);
assertNotNull(volumeChannelType);
assertEquals("Lautstärke", volumeChannelType.getLabel());
assertEquals("Steuert die Lautstärke eines Gerätes.", volumeChannelType.getDescription());
ChannelType muteChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_MUTE, Locale.GERMAN);
assertNotNull(muteChannelType);
assertEquals("Stumm schalten", muteChannelType.getLabel());
assertEquals("Schaltet ein Gerät stumm.", muteChannelType.getDescription());
ChannelType mediaControlChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_MEDIA_CONTROL, Locale.GERMAN);
assertNotNull(mediaControlChannelType);
assertEquals("Fernbedienung", mediaControlChannelType.getLabel());
assertNull(mediaControlChannelType.getDescription());
ChannelType mediaTitleChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_MEDIA_TITLE, Locale.GERMAN);
assertNotNull(mediaTitleChannelType);
assertEquals("Titel", mediaTitleChannelType.getLabel());
assertEquals("Zeigt den Titel der (aktuell abgespielten) Video- oder Audiodatei an.", mediaTitleChannelType.getDescription());
ChannelType mediaArtistChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_MEDIA_ARTIST, Locale.GERMAN);
assertNotNull(mediaArtistChannelType);
assertEquals("Künstler", mediaArtistChannelType.getLabel());
assertEquals("Zeigt den Künstler der (aktuell abgespielten) Video- oder Audiodatei an.", mediaArtistChannelType.getDescription());
ChannelType windDirectionChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_WIND_DIRECTION, Locale.GERMAN);
assertNotNull(windDirectionChannelType);
assertEquals("Windrichtung", windDirectionChannelType.getLabel());
assertEquals("Zeigt die aktuelle Windrichtung an (als Winkel).", windDirectionChannelType.getDescription());
ChannelType windSpeedChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_WIND_SPEED, Locale.GERMAN);
assertNotNull(windSpeedChannelType);
assertEquals("Windgeschwindigkeit", windSpeedChannelType.getLabel());
assertEquals("Zeigt die aktuelle Windgeschwindigkeit an.", windSpeedChannelType.getDescription());
ChannelType outdoorTemperatureChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_OUTDOOR_TEMPERATURE, Locale.GERMAN);
assertNotNull(outdoorTemperatureChannelType);
assertEquals("Außentemperatur", outdoorTemperatureChannelType.getLabel());
assertEquals("Zeigt die aktuelle Außentemperatur an.", outdoorTemperatureChannelType.getDescription());
ChannelType atmosphericHumidityChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_ATMOSPHERIC_HUMIDITY, Locale.GERMAN);
assertNotNull(atmosphericHumidityChannelType);
assertEquals("Luftfeuchtigkeit", atmosphericHumidityChannelType.getLabel());
assertEquals("Zeigt die aktuelle atmosphärische relative Luftfeuchtigkeit an.", atmosphericHumidityChannelType.getDescription());
ChannelType barometricPressureChannelType = systemChannelTypeProvider.getChannelType(SYSTEM_CHANNEL_TYPE_UID_BAROMETRIC_PRESSURE, Locale.GERMAN);
assertNotNull(barometricPressureChannelType);
assertEquals("Luftdruck", barometricPressureChannelType.getLabel());
assertEquals("Zeigt den aktuellen Luftdruck an.", barometricPressureChannelType.getDescription());
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class ChannelTypeResourceTest method returnLinkableItemTypesForTriggerChannelType.
@SuppressWarnings("unchecked")
@Test
public void returnLinkableItemTypesForTriggerChannelType() throws IOException {
ChannelTypeUID channelTypeUID = new ChannelTypeUID("binding", "ct");
ChannelType channelType = ChannelTypeBuilder.trigger(channelTypeUID, "Label").build();
when(channelTypeRegistryMock.getChannelType(channelTypeUID)).thenReturn(channelType);
TriggerProfileType profileType = mock(TriggerProfileType.class);
when(profileType.getSupportedChannelTypeUIDs()).thenReturn(List.of(channelTypeUID));
when(profileType.getSupportedItemTypes()).thenReturn(List.of(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER));
when(profileTypeRegistryMock.getProfileTypes()).thenReturn(List.of(profileType));
Response response = channelTypeResource.getLinkableItemTypes(channelTypeUID.getAsString());
verify(channelTypeRegistryMock).getChannelType(channelTypeUID);
verify(profileTypeRegistryMock).getProfileTypes();
assertThat(response.getStatus(), is(200));
assertThat((Set<String>) response.getEntity(), IsIterableContaining.hasItems(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER));
}
Aggregations