2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.generic.values;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mqtt.generic.ChannelConfig;
17 import org.openhab.binding.mqtt.generic.internal.MqttBindingConstants;
18 import org.openhab.binding.mqtt.generic.mapping.ColorMode;
23 * @author David Graeff - Initial contribution
26 public class ValueFactory {
28 * Creates a new channel state value.
30 * @param config The channel configuration
31 * @param channelTypeID The channel type, for instance TEXT_CHANNEL.
33 public static Value createValueState(ChannelConfig config, String channelTypeID) throws IllegalArgumentException {
35 switch (channelTypeID) {
36 case MqttBindingConstants.STRING:
37 value = config.allowedStates.isBlank() ? new TextValue()
38 : new TextValue(config.allowedStates.split(","));
40 case MqttBindingConstants.DATETIME:
41 value = new DateTimeValue();
43 case MqttBindingConstants.IMAGE:
44 value = new ImageValue();
46 case MqttBindingConstants.LOCATION:
47 value = new LocationValue();
49 case MqttBindingConstants.NUMBER:
50 value = new NumberValue(config.min, config.max, config.step, config.unit);
52 case MqttBindingConstants.DIMMER:
53 value = new PercentageValue(config.min, config.max, config.step, config.on, config.off);
55 case MqttBindingConstants.COLOR_HSB:
56 value = new ColorValue(ColorMode.HSB, config.on, config.off, config.onBrightness);
58 case MqttBindingConstants.COLOR_RGB:
59 value = new ColorValue(ColorMode.RGB, config.on, config.off, config.onBrightness);
61 case MqttBindingConstants.COLOR:
62 value = new ColorValue(ColorMode.valueOf(config.colorMode), config.on, config.off, config.onBrightness);
64 case MqttBindingConstants.SWITCH:
65 value = new OnOffValue(config.on, config.off);
67 case MqttBindingConstants.CONTACT:
68 value = new OpenCloseValue(config.on, config.off);
70 case MqttBindingConstants.ROLLERSHUTTER:
71 value = new RollershutterValue(config.on, config.off, config.stop);
73 case MqttBindingConstants.TRIGGER:
74 config.trigger = true;
75 value = new TextValue();
78 throw new IllegalArgumentException("ChannelTypeUID not recognised: " + channelTypeID);