Skip to content

Commit 8212a6f

Browse files
authored
[tuya] Not all presumed dimmer channels are dimmer channels (openhab#20918)
* [tuya] Remove explicit handling of (presumed) dimmer channels They will be "value" types anyway and can be handled as such. Signed-off-by: Mike Jagdis <mjagdis@eris-associates.co.uk>
1 parent 78f0ad7 commit 8212a6f

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

bundles/org.openhab.binding.tuya/src/main/java/org/openhab/binding/tuya/internal/TuyaChannelTypeProvider.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,7 @@ private ChannelType clone(ChannelTypeUID channelTypeUID, ChannelType orig) {
256256
StateDescriptionFragmentBuilder stateDescriptionFragmentBuilder = null;
257257
boolean advanced = false;
258258

259-
if (DIMMER_CHANNEL_CODES.contains(channelTypeId)) {
260-
acceptedItemType = DIMMER;
261-
category = "slider";
262-
configurationRef = "channel-type:tuya:dimmer";
263-
tags.add(schemaDp.readOnly ? "Status" : "Control");
264-
tags.add("Brightness");
265-
} else if ("bitmap".equals(schemaDp.type)) {
259+
if ("bitmap".equals(schemaDp.type)) {
266260
acceptedItemType = NUMBER;
267261
category = "";
268262
configurationRef = "channel-type:tuya:bitmap";
@@ -305,7 +299,14 @@ private ChannelType clone(ChannelTypeUID channelTypeUID, ChannelType orig) {
305299
category = "";
306300
configurationRef = "channel-type:tuya:number";
307301

308-
if (!schemaDp.unit.isEmpty()) {
302+
if ((schemaDp.unit.isEmpty() && DIMMER_CHANNEL_CODES.contains(channelTypeId)) //
303+
|| (!schemaDp.readOnly && "%".equals(schemaDp.unit))) {
304+
acceptedItemType = DIMMER;
305+
category = "slider";
306+
configurationRef = "channel-type:tuya:dimmer";
307+
tags.add(schemaDp.readOnly ? "Status" : "Control");
308+
tags.add("Brightness");
309+
} else if (!schemaDp.unit.isEmpty()) {
309310
Unit<?> unit = schemaDp.parsedUnit;
310311
if (unit == null) {
311312
unit = UnitUtils.parseUnit(schemaDp.unit);

bundles/org.openhab.binding.tuya/src/main/java/org/openhab/binding/tuya/internal/handler/TuyaDeviceHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.openhab.binding.tuya.internal.TuyaBindingConstants.CONFIG_PRODUCT_ID;
2424
import static org.openhab.binding.tuya.internal.TuyaBindingConstants.CONFIG_PROTOCOL;
2525
import static org.openhab.binding.tuya.internal.TuyaBindingConstants.CONFIG_RANGE;
26-
import static org.openhab.binding.tuya.internal.TuyaBindingConstants.DIMMER_CHANNEL_CODES;
2726
import static org.openhab.core.library.CoreItemFactory.COLOR;
2827
import static org.openhab.core.library.CoreItemFactory.DIMMER;
2928
import static org.openhab.core.library.CoreItemFactory.NUMBER;
@@ -645,10 +644,7 @@ private void addChannels() {
645644
Map<@Nullable String, @Nullable Object> configuration = new HashMap<>();
646645
configuration.put(CONFIG_DP, schemaDp.id);
647646

648-
if (DIMMER_CHANNEL_CODES.contains(channelId)) {
649-
configuration.put(CONFIG_MIN, schemaDp.min);
650-
configuration.put(CONFIG_MAX, schemaDp.max);
651-
} else if ("enum".equals(schemaDp.type)) {
647+
if ("enum".equals(schemaDp.type)) {
652648
List<String> range = Objects.requireNonNullElse(schemaDp.range, List.of());
653649
configuration.put(CONFIG_RANGE, String.join(",", range));
654650
} else if ("value".equals(schemaDp.type)) {

0 commit comments

Comments
 (0)