Skip to content

Commit 1c47279

Browse files
authoredNov 26, 2021
Merge branch 'tuya_offset' into to-delete_7
2 parents 1740c1a + 353b121 commit 1c47279

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed
 

‎rest_sensors.cpp

+32-20
Original file line numberDiff line numberDiff line change
@@ -905,46 +905,58 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
905905
}
906906
else if (rid.suffix == RConfigOffset) // Signed integer
907907
{
908-
data.integer = data.integer / 10;
909-
910-
if ((R_GetProductId(sensor) == QLatin1String("Tuya_THD HY369 TRV") ||
911-
R_GetProductId(sensor) == QLatin1String("Tuya_THD Essentials TRV") ||
912-
R_GetProductId(sensor) == QLatin1String("Tuya_THD Smart radiator TRV") ||
913-
R_GetProductId(sensor) == QLatin1String("Tuya_THD NX-4911-675 TRV") ||
914-
R_GetProductId(sensor) == QLatin1String("Tuya_THD SEA801-ZIGBEE TRV")) ||
915-
R_GetProductId(sensor) == QLatin1String("Tuya_THD WZB-TRVL TRV"))
908+
if (R_GetProductId(sensor) == QLatin1String("Tuya_THD HY369 TRV") ||
909+
R_GetProductId(sensor) == QLatin1String("Tuya_THD HY368 TRV") ||
910+
R_GetProductId(sensor) == QLatin1String("Tuya_THD Essentials TRV") ||
911+
R_GetProductId(sensor) == QLatin1String("Tuya_THD Smart radiator TRV") ||
912+
R_GetProductId(sensor) == QLatin1String("Tuya_THD NX-4911-675 TRV") ||
913+
R_GetProductId(sensor) == QLatin1String("Tuya_THD SEA801-ZIGBEE TRV") ||
914+
R_GetProductId(sensor) == QLatin1String("Tuya_THD BTH-002 Thermostat") ||
915+
R_GetProductId(sensor) == QLatin1String("Tuya_THD WZB-TRVL TRV"))
916916
{
917917
QByteArray tuyaData;
918918
bool alternative = false;
919+
920+
qint8 offset2 = data.integer / 100;
921+
922+
if (offset2 > 6) { offset2 = 6; } // offset, min = -60, max = 60
923+
if (offset2 < -6) { offset2 = -6; }
919924

920-
if (R_GetProductId(sensor) == QLatin1String("Tuya_THD WZB-TRVL TRV"))
925+
if (R_GetProductId(sensor) == QLatin1String("Tuya_THD BTH-002 Thermostat")) // Moes
921926
{
922-
if (data.integer > 6) { data.integer = 6; } // offset, min = -60, max = 60
923-
if (data.integer < -6) { data.integer = -6; }
927+
if (offset2 < 0)
928+
{
929+
offset2 = 4096 + offset2;
930+
}
924931

925932
alternative = true;
926933
}
927-
else
934+
else if (R_GetProductId(sensor) == QLatin1String("Tuya_THD WZB-TRVL TRV") || // Saswell
935+
R_GetProductId(sensor) == QLatin1String("Tuya_THD Smart radiator TRV") ||
936+
R_GetProductId(sensor) == QLatin1String("Tuya_THD SEA801-ZIGBEE TRV"))
937+
{
938+
alternative = true;
939+
}
940+
else // others
928941
{
929-
if (data.integer > 90) { data.integer = 90; } // offset, min = -90, max = 90
930-
if (data.integer < -90) { data.integer = -90; }
942+
offset2 = offset2 * 10;
931943
}
932944

933-
tuyaData.append((qint8)((offset >> 24) & 0xff));
934-
tuyaData.append((qint8)((offset >> 16) & 0xff));
935-
tuyaData.append((qint8)((offset >> 8) & 0xff));
936-
tuyaData.append((qint8)(offset & 0xff));
945+
tuyaData.append((qint8)((offset2 >> 24) & 0xff));
946+
tuyaData.append((qint8)((offset2 >> 16) & 0xff));
947+
tuyaData.append((qint8)((offset2 >> 8) & 0xff));
948+
tuyaData.append((qint8)(offset2 & 0xff));
937949

938950
if (!alternative)
939951
{
940-
if (sendTuyaRequest(task, TaskThermostat, DP_TYPE_VALUE, 0x2c, tuyaData))
952+
if (sendTuyaRequest(task, TaskThermostat, DP_TYPE_VALUE, DP_IDENTIFIER_THERMOSTAT_CALIBRATION_2, tuyaData)) // Others
941953
{
942954
updated = true;
943955
}
944956
}
945957
else
946958
{
947-
if (sendTuyaRequest(task, TaskThermostat, DP_TYPE_VALUE, 0x1b, tuyaData))
959+
if (sendTuyaRequest(task, TaskThermostat, DP_TYPE_VALUE, DP_IDENTIFIER_THERMOSTAT_CALIBRATION_1, tuyaData)) // Moes and Saswell
948960
{
949961
updated = true;
950962
}

‎tuya.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,31 @@ void DeRestPluginPrivate::handleTuyaClusterIndication(const deCONZ::ApsDataIndic
11091109
}
11101110
}
11111111
break;
1112+
case 0x021B : // temperature calibration (offset in degree) for Moes and Saswell
1113+
{
1114+
qint16 temp = static_cast<qint16>(data & 0xFFFF);
1115+
1116+
if (productId == "Tuya_THD BTH-002 Thermostat") // Only Moes
1117+
{
1118+
if (temp > 2048)
1119+
{
1120+
temp = temp - 4096;
1121+
}
1122+
}
1123+
1124+
temp = temp * 100;
1125+
1126+
ResourceItem *item = sensorNode->item(RConfigOffset);
1127+
1128+
if (item && item->toNumber() != temp)
1129+
{
1130+
item->setValue(temp);
1131+
Event e(RSensors, RConfigOffset, sensorNode->id(), item);
1132+
enqueueEvent(e);
1133+
update = true;
1134+
}
1135+
}
1136+
break;
11121137
case 0x022c : // temperature calibration (offset in degree)
11131138
{
11141139
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10;

‎tuya.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272

7373
#define DP_IDENTIFIER_THERMOSTAT_BOOST 0x04 // Boost for Moes
7474

75+
#define DP_IDENTIFIER_THERMOSTAT_CALIBRATION_1 0x1B // Calibration offset used by Moes and Saswell
76+
#define DP_IDENTIFIER_THERMOSTAT_CALIBRATION_2 0x2C // Calibration offset used by others
77+
7578
// Value for dp_identifier for covering
7679
//-----------------------------------
7780

0 commit comments

Comments
 (0)
Please sign in to comment.