From 12659595a6048363c86b69c65c743d94beb4ae70 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Tue, 26 Jan 2021 08:13:04 +0100 Subject: [PATCH] Added system default channel type to control color temperature in Kelvin (#2157) * Added system default channel type for controling color temperature in Kelvin Signed-off-by: Christoph Weitkamp --- .../DefaultSystemChannelTypeProvider.java | 24 +++++++++++++------ .../i18n/DefaultSystemChannels_de.properties | 4 +++- .../i18n/DefaultSystemChannels_fr.properties | 4 +++- .../thing/SystemWideChannelTypesTest.java | 19 ++++++++++++--- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/DefaultSystemChannelTypeProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/DefaultSystemChannelTypeProvider.java index 8e402e651..29a9b9bed 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/DefaultSystemChannelTypeProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/DefaultSystemChannelTypeProvider.java @@ -173,13 +173,23 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider { .withDescription("Controls the color of the light").withCategory("ColorLight").build(); /** - * Color-temperature: default system wide {@link ChannelType} which allows changing the color temperature + * Color-temperature: default system wide {@link ChannelType} which allows changing the color temperature in percent */ public static final ChannelType SYSTEM_COLOR_TEMPERATURE = ChannelTypeBuilder .state(new ChannelTypeUID(BINDING_ID, "color-temperature"), "Color Temperature", "Dimmer") - .withDescription("Controls the color temperature of the light").withCategory("ColorLight") - .withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO) - .withMaximum(new BigDecimal(100)).withPattern("%d").build()) + .withDescription("Controls the color temperature of the light from 0 (cold) to 100 (warm)") + .withCategory("ColorLight").withStateDescriptionFragment(StateDescriptionFragmentBuilder.create() + .withMinimum(BigDecimal.ZERO).withMaximum(new BigDecimal(100)).withPattern("%.0f").build()) + .build(); + + /** + * Color-temperature: default system wide {@link ChannelType} which allows changing the color temperature in Kelvin + */ + public static final ChannelType SYSTEM_COLOR_TEMPERATURE_ABS = ChannelTypeBuilder + .state(new ChannelTypeUID(BINDING_ID, "color-temperature-abs"), "Color Temperature", "Number") + .withDescription("Controls the color temperature of the light in Kelvin").withCategory("ColorLight") + .withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(1000)) + .withMaximum(new BigDecimal(10000)).withPattern("%.0f K").build()) .build(); // media channels @@ -280,9 +290,9 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider { private static final Collection CHANNEL_TYPES = List.of(SYSTEM_CHANNEL_SIGNAL_STRENGTH, SYSTEM_CHANNEL_LOW_BATTERY, SYSTEM_CHANNEL_BATTERY_LEVEL, SYSTEM_TRIGGER, SYSTEM_RAWBUTTON, SYSTEM_BUTTON, SYSTEM_RAWROCKER, SYSTEM_POWER, SYSTEM_LOCATION, SYSTEM_MOTION, SYSTEM_BRIGHTNESS, SYSTEM_COLOR, - SYSTEM_COLOR_TEMPERATURE, SYSTEM_VOLUME, SYSTEM_MUTE, SYSTEM_MEDIA_CONTROL, SYSTEM_MEDIA_TITLE, - SYSTEM_MEDIA_ARTIST, SYSTEM_WIND_DIRECTION, SYSTEM_WIND_SPEED, SYSTEM_OUTDOOR_TEMPERATURE, - SYSTEM_ATMOSPHERIC_HUMIDITY, SYSTEM_BAROMETRIC_PRESSURE); + SYSTEM_COLOR_TEMPERATURE, SYSTEM_COLOR_TEMPERATURE_ABS, SYSTEM_VOLUME, SYSTEM_MUTE, SYSTEM_MEDIA_CONTROL, + SYSTEM_MEDIA_TITLE, SYSTEM_MEDIA_ARTIST, SYSTEM_WIND_DIRECTION, SYSTEM_WIND_SPEED, + SYSTEM_OUTDOOR_TEMPERATURE, SYSTEM_ATMOSPHERIC_HUMIDITY, SYSTEM_BAROMETRIC_PRESSURE); private final Map localizedChannelTypeCache = new ConcurrentHashMap<>(); diff --git a/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_de.properties b/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_de.properties index ead62a913..178a9844d 100644 --- a/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_de.properties +++ b/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_de.properties @@ -21,7 +21,9 @@ channel-type.system.brightness.description = Steuert die Helligkeit und schaltet channel-type.system.color.label = Farbe channel-type.system.color.description = Steuert die Lichtfarbe. channel-type.system.color-temperature.label = Farbtemperatur -channel-type.system.color-temperature.description = Steuert die Farbtemperatur des Lichts. +channel-type.system.color-temperature.description = Steuert die Farbtemperatur des Lichts von 0 (kalt) bis 100 (warm). +channel-type.system.color-temperature-abs.label = Farbtemperatur +channel-type.system.color-temperature-abs.description = Steuert die Farbtemperatur des Lichts in Kelvin. channel-type.system.volume.label = Lautstärke channel-type.system.volume.description = Ermöglicht die Steuerung der Lautstärke. channel-type.system.mute.label = Stumm schalten diff --git a/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_fr.properties b/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_fr.properties index bc97394e3..e820fa39f 100644 --- a/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_fr.properties +++ b/bundles/org.openhab.core.thing/src/main/resources/OH-INF/i18n/DefaultSystemChannels_fr.properties @@ -16,7 +16,9 @@ channel-type.system.brightness.description = Contr channel-type.system.color.label = Couleur channel-type.system.color.description = Contrôle la couleur de la lumière. channel-type.system.color-temperature.label = Température de couleur -channel-type.system.color-temperature.description = Contrôle la température de couleur de la lumière. +channel-type.system.color-temperature.description = Contrôle la température de couleur de la lumière de 0 (froid) à 100 (chaud). +channel-type.system.color-temperature-abs.label = Température de couleur +channel-type.system.color-temperature-abs.description = Contrôle la température de couleur de la lumière en Kelvin. channel-type.system.volume.label = Volume channel-type.system.volume.description = Modifie le volume sonore de l'appareil. channel-type.system.mute.label = Muet diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java index ec31b357e..0f23a86c3 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java @@ -34,6 +34,8 @@ import org.openhab.core.types.StateOption; */ public class SystemWideChannelTypesTest extends JavaOSGiTest { + private static final int NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES = 24; + private static final ChannelTypeUID SIGNAL_STRENGTH_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "signal-strength"); private static final ChannelTypeUID LOW_BATTERY_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "low-battery"); @@ -50,6 +52,8 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { private static final ChannelTypeUID COLOR_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "color"); private static final ChannelTypeUID COLOR_TEMPERATURE_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "color-temperature"); + private static final ChannelTypeUID COLOR_TEMPERATURE_ABS_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, + "color-temperature-abs"); private static final ChannelTypeUID VOLUME_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "volume"); private static final ChannelTypeUID MUTE_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, "mute"); private static final ChannelTypeUID MEDIA_CONTROL_CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, @@ -78,7 +82,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { @Test public void systemChannelTypesShouldBeAvailable() { Collection sytemChannelTypes = systemChannelTypeProvider.getChannelTypes(null); - assertEquals(23, sytemChannelTypes.size()); + assertEquals(NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES, sytemChannelTypes.size()); assertNotNull(systemChannelTypeProvider.getChannelType(SIGNAL_STRENGTH_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(LOW_BATTERY_CHANNEL_TYPE_UID, null)); @@ -93,6 +97,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { assertNotNull(systemChannelTypeProvider.getChannelType(BRIGHTNESS_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(COLOR_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(COLOR_TEMPERATURE_CHANNEL_TYPE_UID, null)); + assertNotNull(systemChannelTypeProvider.getChannelType(COLOR_TEMPERATURE_ABS_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(VOLUME_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(MUTE_CHANNEL_TYPE_UID, null)); assertNotNull(systemChannelTypeProvider.getChannelType(MEDIA_CONTROL_CHANNEL_TYPE_UID, null)); @@ -108,7 +113,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { @Test public void systemChannelTypesShouldBeTranslatedProperly() { Collection localizedChannelTypes = systemChannelTypeProvider.getChannelTypes(Locale.GERMAN); - assertEquals(23, localizedChannelTypes.size()); + assertEquals(NUMBER_OF_SYSTEM_WIDE_CHANNEL_TYPES, localizedChannelTypes.size()); ChannelType signalStrengthChannelType = systemChannelTypeProvider .getChannelType(SIGNAL_STRENGTH_CHANNEL_TYPE_UID, Locale.GERMAN); @@ -188,7 +193,15 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { .getChannelType(COLOR_TEMPERATURE_CHANNEL_TYPE_UID, Locale.GERMAN); assertNotNull(colorTemperatureChannelType); assertEquals("Farbtemperatur", colorTemperatureChannelType.getLabel()); - assertEquals("Steuert die Farbtemperatur des Lichts.", colorTemperatureChannelType.getDescription()); + assertEquals("Steuert die Farbtemperatur des Lichts von 0 (kalt) bis 100 (warm).", + colorTemperatureChannelType.getDescription()); + + ChannelType colorTemperatureAbsChannelType = systemChannelTypeProvider + .getChannelType(COLOR_TEMPERATURE_ABS_CHANNEL_TYPE_UID, Locale.GERMAN); + assertNotNull(colorTemperatureAbsChannelType); + assertEquals("Farbtemperatur", colorTemperatureAbsChannelType.getLabel()); + assertEquals("Steuert die Farbtemperatur des Lichts in Kelvin.", + colorTemperatureAbsChannelType.getDescription()); ChannelType volumeChannelType = systemChannelTypeProvider.getChannelType(VOLUME_CHANNEL_TYPE_UID, Locale.GERMAN);