Search in sources :

Example 26 with ChannelType

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;
    }
}
Also used : LocalizedKey(org.openhab.core.i18n.LocalizedKey) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 27 with 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;
}
Also used : ChannelDefinitionBuilder(org.openhab.core.thing.type.ChannelDefinitionBuilder) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 28 with ChannelType

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());
}
Also used : ChannelType(org.openhab.core.thing.type.ChannelType) StateOption(org.openhab.core.types.StateOption) StateDescription(org.openhab.core.types.StateDescription) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 29 with ChannelType

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));
}
Also used : Response(javax.ws.rs.core.Response) TriggerProfileType(org.openhab.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelType(org.openhab.core.thing.type.ChannelType) Test(org.junit.jupiter.api.Test)

Example 30 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.

the class ThingResource method normalizeConfiguration.

@Nullable
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, ChannelTypeUID channelTypeUID, ChannelUID channelUID) {
    if (properties == null || properties.isEmpty()) {
        return properties;
    }
    ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID);
    if (channelType == null) {
        return properties;
    }
    List<ConfigDescription> configDescriptions = new ArrayList<>(2);
    URI descURI = channelType.getConfigDescriptionURI();
    if (descURI != null) {
        ConfigDescription typeConfigDesc = configDescRegistry.getConfigDescription(descURI);
        if (typeConfigDesc != null) {
            configDescriptions.add(typeConfigDesc);
        }
    }
    if (getConfigDescriptionURI(channelUID) != null) {
        ConfigDescription channelConfigDesc = configDescRegistry.getConfigDescription(getConfigDescriptionURI(channelUID));
        if (channelConfigDesc != null) {
            configDescriptions.add(channelConfigDesc);
        }
    }
    if (configDescriptions.isEmpty()) {
        return properties;
    }
    return ConfigUtil.normalizeTypes(properties, configDescriptions);
}
Also used : ArrayList(java.util.ArrayList) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ChannelType(org.openhab.core.thing.type.ChannelType) URI(java.net.URI) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ChannelType (org.openhab.core.thing.type.ChannelType)57 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)27 Channel (org.openhab.core.thing.Channel)21 ArrayList (java.util.ArrayList)20 Nullable (org.eclipse.jdt.annotation.Nullable)17 ChannelUID (org.openhab.core.thing.ChannelUID)16 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)14 Test (org.junit.jupiter.api.Test)11 URI (java.net.URI)10 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)10 Thing (org.openhab.core.thing.Thing)9 ThingType (org.openhab.core.thing.type.ThingType)9 StateOption (org.openhab.core.types.StateOption)9 BigDecimal (java.math.BigDecimal)8 Collection (java.util.Collection)8 ChannelDefinitionBuilder (org.openhab.core.thing.type.ChannelDefinitionBuilder)8 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)8 Locale (java.util.Locale)7 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)7 Configuration (org.openhab.core.config.core.Configuration)7