[mqtt.generic] Fix default configuration and docs for color_mode (#12163)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2022-01-30 18:13:39 +10:00 committed by GitHub
parent 4e122005ca
commit 3c32f9aa24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -129,7 +129,7 @@ You can connect this channel to a Contact or Switch item.
### Channel Type "color" ### 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.) * __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.) * __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, * __onBrightness__: If you connect this channel to a Switch item and turn it on,

View File

@ -16,6 +16,7 @@ import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.mapping.ColorMode;
/** /**
* A user can add custom channels to an MQTT Thing. * A user can add custom channels to an MQTT Thing.
@ -56,5 +57,5 @@ public class ChannelConfig {
public @Nullable String stop; public @Nullable String stop;
public int onBrightness = 10; public int onBrightness = 10;
public String colorMode = ""; public String colorMode = ColorMode.HSB.toString();
} }

View File

@ -165,7 +165,7 @@ public class GenericMQTTThingHandler extends AbstractMQTTThingHandler implements
stateDescProvider.setDescription(channel.getUID(), description); stateDescProvider.setDescription(channel.getUID(), description);
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.warn("Channel configuration error", e); logger.warn("Configuration error for channel '{}'", channel.getUID(), e);
configErrors.add(channel.getUID()); configErrors.add(channel.getUID());
} }
} }

View File

@ -61,7 +61,13 @@ public class ValueFactory {
value = new ColorValue(ColorMode.RGB, config.on, config.off, config.onBrightness); value = new ColorValue(ColorMode.RGB, config.on, config.off, config.onBrightness);
break; break;
case MqttBindingConstants.COLOR: 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; break;
case MqttBindingConstants.SWITCH: case MqttBindingConstants.SWITCH:
value = new OnOffValue(config.on, config.off); value = new OnOffValue(config.on, config.off);