]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.generic] Fix default configuration and docs for color_mode (#12163)
authorjimtng <2554958+jimtng@users.noreply.github.com>
Sun, 30 Jan 2022 08:13:39 +0000 (18:13 +1000)
committerGitHub <noreply@github.com>
Sun, 30 Jan 2022 08:13:39 +0000 (09:13 +0100)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
bundles/org.openhab.binding.mqtt.generic/README.md
bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelConfig.java
bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/internal/handler/GenericMQTTThingHandler.java
bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ValueFactory.java

index 1d89049cf954d314af232c4bfceda1c40e5dc473..6bfdf7c57acae080474afb8f70641e8543a0ba1d 100644 (file)
@@ -129,7 +129,7 @@ You can connect this channel to a Contact or Switch item.
 
 ### Channel Type "color"
 
-* __color_mode__: A required string that defines the color representation: "hsb", "rgb" or "xyY" (x,y,brightness).
+* __color_mode__: An optional string that defines the color representation: `HSB`, `RGB` or `XYY` (x,y,brightness). Defaults to `HSB` when not specified.
 * __on__: An optional string (like "BRIGHT") that is recognized as on state. (ON will always be recognized.)
 * __off__: An optional string (like "DARK") that is recognized as off state. (OFF will always be recognized.)
 * __onBrightness__: If you connect this channel to a Switch item and turn it on,
index 00097eb4eabecba04af2d48666b58306372d574d..c8cc59c0b444a364b85d7836f20aa3e4edac0a1d 100644 (file)
@@ -16,6 +16,7 @@ import java.math.BigDecimal;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.mqtt.generic.mapping.ColorMode;
 
 /**
  * A user can add custom channels to an MQTT Thing.
@@ -56,5 +57,5 @@ public class ChannelConfig {
     public @Nullable String stop;
 
     public int onBrightness = 10;
-    public String colorMode = "";
+    public String colorMode = ColorMode.HSB.toString();
 }
index b9b86dab96779f9032e874adee14ccd664f19342..0baa72040887986bbf83b66140790bf5fdc83570 100644 (file)
@@ -165,7 +165,7 @@ public class GenericMQTTThingHandler extends AbstractMQTTThingHandler implements
                     stateDescProvider.setDescription(channel.getUID(), description);
                 }
             } catch (IllegalArgumentException e) {
-                logger.warn("Channel configuration error", e);
+                logger.warn("Configuration error for channel '{}'", channel.getUID(), e);
                 configErrors.add(channel.getUID());
             }
         }
index 70bc0ebebfc3db191f2007ea2e34d37d913831a4..90bdf45ddf425700e4a79381f23aa1ae7f897822 100644 (file)
@@ -61,7 +61,13 @@ public class ValueFactory {
                 value = new ColorValue(ColorMode.RGB, config.on, config.off, config.onBrightness);
                 break;
             case MqttBindingConstants.COLOR:
-                value = new ColorValue(ColorMode.valueOf(config.colorMode), config.on, config.off, config.onBrightness);
+                ColorMode colorMode;
+                try {
+                    colorMode = ColorMode.valueOf(config.colorMode);
+                } catch (IllegalArgumentException exception) {
+                    throw new IllegalArgumentException("Invalid color mode: " + config.colorMode, exception);
+                }
+                value = new ColorValue(colorMode, config.on, config.off, config.onBrightness);
                 break;
             case MqttBindingConstants.SWITCH:
                 value = new OnOffValue(config.on, config.off);