From 81465e03aeddd6cc818f74d72da8b9f8f9b9b4f6 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Wed, 7 Aug 2024 12:05:51 +0200 Subject: [PATCH] Quick fix fan dim capability range --- lib/TuyaOAuth2DriverFan.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/TuyaOAuth2DriverFan.js b/lib/TuyaOAuth2DriverFan.js index 0f333cdd..2665f916 100644 --- a/lib/TuyaOAuth2DriverFan.js +++ b/lib/TuyaOAuth2DriverFan.js @@ -14,7 +14,7 @@ class TuyaOAuth2DriverFan extends TuyaOAuth2Driver { // TODO ]; - onTuyaPairListDeviceProperties(device) { + onTuyaPairListDeviceProperties(device, deviceSpecs) { const props = super.onTuyaPairListDeviceProperties(device); // onoff @@ -27,14 +27,28 @@ class TuyaOAuth2DriverFan extends TuyaOAuth2Driver { const hasFanSpeedPercent = device.status.some(({ code }) => code === 'fan_speed_percent'); if (hasFanSpeedPercent) { props.capabilities.push('dim'); - props.capabilitiesOptions = props.capabilitiesOptions ?? {}; props.capabilitiesOptions['dim'] = { - max: 1, + min: 1, max: 6, step: 1 }; } + // Device Specifications + for (const functionSpecification of specifications.functions) { + const tuyaCapability = functionSpecification.code; + const values = JSON.parse(functionSpecification.values); + + if (tuyaCapability === 'fan_speed_percent') { + props.store.tuya_brightness = values; + props.capabilitiesOptions['dim'] = { + min: values.min ?? 1, + max: values.max ?? 100, + step: values.step ?? 1, + } + } + } + return props; }