### 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,
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.
public @Nullable String stop;
public int onBrightness = 10;
- public String colorMode = "";
+ public String colorMode = ColorMode.HSB.toString();
}
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());
}
}
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);