forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuya.cpp
1386 lines (1210 loc) · 52.1 KB
/
tuya.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tuya.cpp
*
* Implementation of Tuya cluster.
*
*/
#include <regex>
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
#include "tuya.h"
//***********************************************************************************
// Value for dp_type
// ------------------
// 0x00 DP_TYPE_RAW ?
// 0x01 DP_TYPE_BOOL ?
// 0x02 DP_TYPE_VALUE 4 byte unsigned integer
// 0x03 DP_TYPE_STRING variable length string
// 0x04 DP_TYPE_ENUM 1 byte enum
// 0x05 DP_TYPE_FAULT 1 byte bitmap (didn't test yet)
// Value for dp_identifier (it s device dependent)
//
// Value for windows covering
//-----------------------------------------------------
// 0x01 control enum open, stop, close, continue
// 0x02 percent_control value 0-100% control
// 0x03 percent_state value Report from motor about current percentage
// 0x04 control_back enum Configures motor direction (untested)
// 0x05 work_state enum Supposedly shows if motor is opening or closing, always 0 for me though
// 0x06 situation_set enum Configures if 100% equals to fully closed or fully open (untested)
// 0x07 fault bitmap Anything but 0 means something went wrong (untested)
// Value for switch
//-------------------
// 0x01 Button 1
// 0x02 Button 2
// 0x03 Button 3
// 0x04 ???
// 0x0D All buttons
// Value for thermostat
//---------------------
// 0x04 Preset
// 0x6C Auto / Manu
// 0x65 Manu / Off
// 0x6E Low battery
// 0x02 Actual temperature
// 0x03 Thermostat temperature
// 0x14 Valve
// 0x15 Battery level
// 0x6A Mode
// Value For Various sensor
// -------------------------
// 0x03 Presence detection (with 0x04)
// 0x65 Water leak (with 0x01)
// List of tuya command
// ---------------------
// Cmd ID Description
// 0x01 Product Information Inquiry / Reporting
// 0x02 Device Status Query / Report
// 0x03 Zigbee Device Reset
// 0x04 Order Issuance
// 0x05 Status Report
// 0x06 Status Search
// 0x07 reserved
// 0x08 Zigbee Device Functional Test
// 0x09 Query key information (only scene switch devices are valid)
// 0x0A Scene wakeup command (only scene switch device is valid)
// 0x0A-0x23 reserved
// 0x24 Time synchronization
//******************************************************************************************
/*! Returns true if the \p manufacturer name referes to a Tuya device. */
bool isTuyaManufacturerName(const QString &manufacturer)
{
return manufacturer.startsWith(QLatin1String("_T")) && // quick check for performance
std::regex_match(qPrintable(manufacturer), std::regex("_T[A-Z][A-Z0-9]{4}_[a-z0-9]{8}"));
}
// Tests for Tuya manufacturer name
/*
Q_ASSERT(isTuyaManufacturerName("_TZ3000_bi6lpsew"));
Q_ASSERT(isTuyaManufacturerName("_TYZB02_key8kk7r"));
Q_ASSERT(isTuyaManufacturerName("_TYST11_ckud7u2l"));
Q_ASSERT(isTuyaManufacturerName("_TYZB02_keyjqthh"));
Q_ASSERT(!isTuyaManufacturerName("lumi.sensor_switch.aq2"));
*/
/*! Helper to generate a new task with new task and req id based on a reference */
static void copyTaskReq(TaskItem &a, TaskItem &b)
{
b.req.dstAddress() = a.req.dstAddress();
b.req.setDstAddressMode(a.req.dstAddressMode());
b.req.setSrcEndpoint(a.req.srcEndpoint());
b.req.setDstEndpoint(a.req.dstEndpoint());
b.req.setRadius(a.req.radius());
b.req.setTxOptions(a.req.txOptions());
b.req.setSendDelay(a.req.sendDelay());
b.zclFrame.payload().clear();
}
bool UseTuyaCluster(const QString &manufacturer)
{
// https://docs.tuya.com/en/iot/device-development/module/zigbee-module/zigbeetyzs11module?id=K989rik5nkhez
//_TZ3000 don't use tuya cluster
//_TYZB01 don't use tuya cluster
//_TYZB02 don't use tuya cluster
//_TZ3400 don't use tuya cluster
if (manufacturer.startsWith(QLatin1String("_TZE200_")) || // Tuya clutster visible
manufacturer.startsWith(QLatin1String("Tuya_C_")) || // Used by fake device
manufacturer.startsWith(QLatin1String("_TYST11_"))) // Tuya cluster invisible
{
return true;
}
return false;
}
/*! Handle packets related to Tuya 0xEF00 cluster.
\param ind the APS level data indication containing the ZCL packet
\param zclFrame the actual ZCL frame which holds the scene cluster reponse
Taken from https://medium.com/@dzegarra/zigbee2mqtt-how-to-add-support-for-a-new-tuya-based-device-part-2-5492707e882d
*/
void DeRestPluginPrivate::handleTuyaClusterIndication(const deCONZ::ApsDataIndication &ind, deCONZ::ZclFrame &zclFrame)
{
if (zclFrame.isDefaultResponse())
{
return;
}
bool update = false;
LightNode *lightNode = getLightNodeForAddress(ind.srcAddress(), ind.srcEndpoint());
Sensor *sensorNode = getSensorNodeForAddressAndEndpoint(ind.srcAddress(), ind.srcEndpoint());
if (!sensorNode && !lightNode)
{
return;
}
// DBG_Printf(DBG_INFO, "Tuya debug 4 : Address 0x%016llX, Command 0x%02X, Payload %s\n", ind.srcAddress().ext(), zclFrame.commandId(), qPrintable(zclFrame.payload().toHex()));
if (zclFrame.commandId() == TUYA_REQUEST)
{
// 0x00 : TUYA_REQUEST > Used to send command, so not used here
}
else if (zclFrame.commandId() == TUYA_REPORTING || zclFrame.commandId() == TUYA_QUERY)
{
// 0x01 : TUYA_REPORTING > Used to inform of changes in its state.
// 0x02 : TUYA_QUERY > Send after receiving a 0x00 command.
// Send default response
if (zclFrame.commandId() == TUYA_REPORTING && !(zclFrame.frameControl() & deCONZ::ZclFCDisableDefaultResponse))
{
sendZclDefaultResponse(ind, zclFrame, deCONZ::ZclSuccessStatus);
}
if (zclFrame.payload().size() < 7)
{
DBG_Printf(DBG_INFO, "Tuya : Payload too short\n");
return;
}
QDataStream stream(zclFrame.payload());
stream.setByteOrder(QDataStream::LittleEndian);
// "dp" field describes the action/message of a command frame and was composed by a type and an identifier
// Composed by a type (dp_type) and an identifier (dp_identifier), the identifier is device dependant.
// "transid" is just a "counter", a response will have the same transif than the command.
// "Status" and "fn" are always 0
// More explanations at top of file
quint8 status;
quint8 transid;
quint16 dp;
quint8 fn;
quint8 length = 0;
qint32 data = 0;
quint8 dp_type;
quint8 dp_identifier;
quint8 dummy;
stream >> status;
stream >> transid;
stream >> dp;
stream >> fn;
//Convertion octet string to decimal value
stream >> length;
//security, it seem 4 is the maximum
if (length > 4)
{
DBG_Printf(DBG_INFO, "Tuya : Schedule command\n");
}
else
{
for (; length > 0; length--)
{
stream >> dummy;
data = data << 8;
data = data + dummy;
}
}
//To be more precise
dp_identifier = (dp & 0xFF);
dp_type = ((dp >> 8) & 0xFF);
DBG_Printf(DBG_INFO, "Tuya debug 4 : Address 0x%016llX Payload %s\n", ind.srcAddress().ext(), qPrintable(zclFrame.payload().toHex()));
DBG_Printf(DBG_INFO, "Tuya debug 5 : Status: %u Transid: %u Dp: %u (0x%02X,0x%02X) Fn: %u Data %ld\n", status, transid, dp, dp_type, dp_identifier, fn, data);
if (length > 4) //schedule command
{
// Monday = 64, Tuesday = 32, Wednesday = 16, Thursday = 8, Friday = 4, Saturday = 2, Sunday = 1
// If you want your schedule to run only on workdays, the value would be W124. (64+32+16+8+4 = 124)
// The API specifies 3 numbers, so a schedule that runs on Monday would be W064.
//
// Workday = W124
// Not working day = W003
// Saturday = W002
// Sunday = W001
// All days = W127
QString transitions;
if (zclFrame.payload().size() < ((length * 3) + 6))
{
DBG_Printf(DBG_INFO, "Tuya : Schedule data error\n");
return;
}
quint8 hour;
quint8 minut;
quint8 heatSetpoint;
quint16 minut16;
quint16 heatSetpoint16;
quint8 part = 0;
QList<int> listday;
switch (dp)
{
case 0x0070: //work days (6)
{
part = 1;
listday << 124;
length = length / 3;
}
break;
case 0x0071: // holiday = Not working day (6)
{
part = 1;
listday << 3;
length = length / 3;
}
break;
case 0x0065: // Moe thermostat W124 (4) + W002 (4) + W001 (4)
{
part = length / 3;
listday << 124 << 2 << 1;
length = length / 3;
}
break;
// Daily schedule (mode 8)(minut 16)(temperature 16)(minut 16)(temperature 16)(minut 16)(temperature 16)(minut 16)(temperature 16)
case 0x007B: // Sunday
case 0x007C: // Monday
case 0x007D: // Thuesday
case 0x007E: // Wednesday
case 0x007F: // Thursday
case 0x0080: // Friday
case 0x0081: // Saturday
{
const std::array<int, 7> t = {1,64,32,46,8,4,2};
part = 1;
if (dp < 0x007B || (dp - 0x007B) >= static_cast<int>(t.size()))
{
DBG_Printf(DBG_INFO, "Tuya unsupported daily schedule dp value: 0x%04X\n", dp);
return; // bail out early
}
listday << t[dp - 0x007B];
length = (length - 1) / 2;
quint8 mode;
stream >> mode; // First octet is the mode
break;
}
default:
{
DBG_Printf(DBG_INFO, "Tuya : Unknow Schedule mode\n");
}
break;
}
for (; part > 0; part--)
{
for (; length > 0; length--)
{
if (dp >= 0x007B && dp <= 0x0081)
{
stream >> minut16;
stream >> heatSetpoint16;
hour = static_cast<quint8>((minut16 / 60) & 0xff);
minut = static_cast<quint8>((minut16 - 60 * hour) & 0xff);
heatSetpoint = static_cast<quint8>((heatSetpoint16 / 10) & 0xff);
}
else
{
stream >> hour;
stream >> minut;
stream >> heatSetpoint;
}
transitions += QString("T%1:%2|%3")
.arg(hour, 2, 10, QChar('0'))
.arg(minut, 2, 10, QChar('0'))
.arg(heatSetpoint);
if (part > 0 && listday.size() >= static_cast<int>(part))
{
updateThermostatSchedule(sensorNode, listday.at(part - 1), transitions);
}
}
}
return;
}
// Sensor and light use same cluster, so need to make a choice for device that have both
// Some device have sensornode AND lightnode, so need to use the good one.
if (sensorNode && lightNode)
{
if (dp == 0x0215) // battery
{
lightNode = nullptr;
}
if (sensorNode->type() == QLatin1String("ZHAThermostat"))
{
lightNode = nullptr;
}
if (R_GetProductId(sensorNode) == QLatin1String("NAS-AB02B0 Siren"))
{
if (dp == 0x0168) // Siren alarm
{
sensorNode = nullptr;
}
else
{
lightNode = nullptr;
}
}
}
//Some device are more than 1 sensors for the same endpoint, so trying to take the good one
if (sensorNode && R_GetProductId(sensorNode) == QLatin1String("NAS-AB02B0 Siren"))
{
switch (dp)
{
//temperature
case 0x0269:
{
sensorNode = getSensorNodeForAddressAndEndpoint(ind.srcAddress(), ind.srcEndpoint(), QLatin1String("ZHATemperature"));
}
break;
//Humidity
case 0x026A:
{
sensorNode = getSensorNodeForAddressAndEndpoint(ind.srcAddress(), ind.srcEndpoint(), QLatin1String("ZHAHumidity"));
}
break;
default:
// All other are for the alarm sensor
{
sensorNode = getSensorNodeForAddressAndEndpoint(ind.srcAddress(), ind.srcEndpoint(), QLatin1String("ZHAAlarm"));
}
break;
}
}
if (lightNode)
{
//Window covering ?
if (lightNode->manufacturer() == QLatin1String("_TYST11_wmcdj3aq") ||
lightNode->manufacturer() == QLatin1String("_TZE200_xuzcvlku") ||
lightNode->manufacturer() == QLatin1String("_TZE200_wmcdj3aq") ||
lightNode->manufacturer() == QLatin1String("_TZE200_nogaemzt") ||
lightNode->manufacturer() == QLatin1String("_TZE200_zah67ekd") || // MoesHouse / Livolo Roller Blinds
lightNode->manufacturer() == QLatin1String("_TZE200_fzo2pocs") ||
lightNode->manufacturer() == QLatin1String("_TYST11_xu1rkty3"))
{
switch (dp)
{
// 0x0407 > starting moving
// 0x0105 > configuration done
case 0x0401:
{
if (data == 0x02) //open
{
lightNode->setValue(RStateOpen, true);
lightNode->setValue(RStateOn, false);
}
else if (data == 0x00) //close
{
lightNode->setValue(RStateOpen, false);
lightNode->setValue(RStateOn, true);
}
else if (data == 0x01) //stop
{
}
}
break;
case 0x0202: // going to position
case 0x0203: // position reached (more usefull I think)
{
quint8 lift = static_cast<quint8>(data);
bool open = lift < 100;
lightNode->setValue(RStateLift, lift);
lightNode->setValue(RStateOpen, open);
quint8 level = lift * 254 / 100;
bool on = level > 0;
lightNode->setValue(RStateBri, level);
lightNode->setValue(RStateOn, on);
}
break;
case 0x0405: // rotation direction
{
DBG_Printf(DBG_INFO, "Tuya debug 3 : Covering motor direction %ld\n", data);
}
break;
//other
default:
break;
}
}
//siren
else if (R_GetProductId(lightNode) == QLatin1String("NAS-AB02B0 Siren"))
{
if (dp == 0x0168)
{
if (data == 0x00)
{
lightNode->setValue(RStateAlert, QString("none"));
}
else
{
lightNode->setValue(RStateAlert, QString("lselect"));
}
update = true;
}
}
else
{
// Switch device 1/2/3 gangs
switch (dp)
{
case 0x0101:
case 0x0102:
case 0x0103:
{
bool onoff = (data == 0) ? false : true;
{
uint ep = 0x01;
if (dp == 0x0102) { ep = 0x02; }
if (dp == 0x0103) { ep = 0x03; }
LightNode *lightNode2 = lightNode;
lightNode = getLightNodeForAddress(ind.srcAddress(), ep);
if (!lightNode)
{
return;
}
//Find model id if missing (modelId().isEmpty ?) and complete it
if (lightNode->modelId().isNull() || lightNode->modelId() == QLatin1String("Unknown") || lightNode->manufacturer() == QLatin1String("Unknown"))
{
DBG_Printf(DBG_INFO, "Tuya debug 10 : Updating model ID\n");
if (!lightNode2->modelId().isNull())
{
lightNode->setModelId(lightNode2->modelId());
}
if (lightNode2->manufacturer().startsWith(QLatin1String("_T")))
{
lightNode->setManufacturerName(lightNode2->manufacturer());
}
}
ResourceItem *item = lightNode->item(RStateOn);
if (item && item->toBool() != onoff)
{
item->setValue(onoff);
Event e(RLights, RStateOn, lightNode->id(), item);
enqueueEvent(e);
update = true;
}
}
}
break;
//other
default:
break;
}
}
}
else if (sensorNode)
{
//Special part just for siren
if (R_GetProductId(sensorNode) == QLatin1String("NAS-AB02B0 Siren")) //siren
{
switch (dp)
{
case 0x0171: // Alarm siren temperature
{
ResourceItem *item = sensorNode->item(RConfigPreset);
if (item)
{
QString mode;
if (data == 0)
{
if (item->toString() == "both")
{
mode = QLatin1String("humidity");
}
else
{
mode = QLatin1String("off");
}
}
else if (data == 1)
{
if (item->toString() == "humidity")
{
mode = QLatin1String("both");
}
else
{
mode = QLatin1String("temperature");
}
}
else
{
return;
}
if (item->toString() != mode)
{
update = true;
item->setValue(mode);
Event e(RSensors, RConfigPreset, sensorNode->id(), item);
enqueueEvent(e);
}
}
}
break;
case 0x0172: // Alarm siren humidity
{
ResourceItem *item = sensorNode->item(RConfigPreset);
if (item)
{
QString mode;
if (data == 0)
{
if (item->toString() == "both")
{
mode = QLatin1String("temperature");
}
else
{
mode = QLatin1String("off");
}
}
else if (data == 1)
{
if (item->toString() == "temperature")
{
mode = QLatin1String("both");
}
else
{
mode = QLatin1String("humidity");
}
}
else
{
return;
}
if (item->toString() != mode)
{
update = true;
item->setValue(mode);
Event e(RSensors, RConfigPreset, sensorNode->id(), item);
enqueueEvent(e);
}
}
}
break;
case 0x0269: // siren temperature
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10 + 200;
ResourceItem *item = sensorNode->item(RStateTemperature);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RStateTemperature, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x026A : // Siren Humidity
{
qint16 Hum = static_cast<qint16>(data & 0xFFFF) * 100;
ResourceItem *item = sensorNode->item(RStateHumidity);
if (item && item->toNumber() != Hum)
{
item->setValue(Hum);
Event e(RSensors, RStateHumidity, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x026B : // min alarm temperature threshold
case 0x026C : // max alarm temperature threshold
{
qint8 min = static_cast<qint8>(data & 0xFF);
ResourceItem *item = sensorNode->item(RConfigTempThreshold);
if (item)
{
QString values;
if (item->toString().isEmpty())
{
values = QString("0,0");
}
else
{
values = item->toString();
}
QStringList valuesList = values.split(",");
if (valuesList.size() != 2)
{
valuesList = QStringList();
valuesList << "0" << "0" ;
}
DBG_Printf(DBG_INFO, "Tuya debug 33 : %s\n", qPrintable(valuesList.join(',')));
if (dp == 0x026B) { valuesList[0] = QString::number(min); }
if (dp == 0x026C) { valuesList[1] = QString::number(min); }
DBG_Printf(DBG_INFO, "Tuya debug 34 : %s\n", qPrintable(valuesList.join(',')));
item->setValue(valuesList.join(','));
Event e(RSensors, RConfigTempThreshold, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x026D : // min alarm humidity threshold
case 0x026E : // max alarm humidity threshold
{
qint8 min = static_cast<qint8>(data & 0xFF);
ResourceItem *item = sensorNode->item(RConfigHumiThreshold);
if (item)
{
QString values;
if (item->toString().isEmpty())
{
values = QString("0,0");
}
else
{
values = item->toString();
}
QStringList valuesList = values.split(",");
if (valuesList.size() != 2)
{
valuesList = QStringList();
valuesList << "0" << "0";
}
if (dp == 0x026D) { valuesList[0] = QString::number(min); }
if (dp == 0x026E) { valuesList[1] = QString::number(min); }
item->setValue(valuesList.join(','));
Event e(RSensors, RConfigHumiThreshold, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x0466 : // melody
{
quint8 melody = static_cast<qint8>(data & 0xFF);
ResourceItem *item = sensorNode->item(RConfigMelody);
if (item && item->toNumber() != melody)
{
item->setValue(melody);
enqueueEvent(Event(RSensors, RConfigMelody, sensorNode->id(), item));
update = true;
}
}
break;
case 0x0474 : // volume
{
quint8 volume = static_cast<qint8>(data & 0xFF);
ResourceItem *item = sensorNode->item(RConfigVolume);
if (item && item->toNumber() != volume)
{
item->setValue(volume);
enqueueEvent(Event(RSensors, RConfigVolume, sensorNode->id(), item));
update = true;
}
}
break;
default:
break;
}
}
else
{
// Generic part
switch (dp)
{
case 0x0068: // window open information
{
}
break;
case 0x0101: // off / running for Moe
{
QString mode;
if (data == 0) { mode = QLatin1String("off"); }
else if (data == 1) { mode = QLatin1String("heat"); }
else
{
return;
}
ResourceItem *item = sensorNode->item(RConfigMode);
if (item && item->toString() != mode)
{
item->setValue(mode);
enqueueEvent(Event(RSensors, RConfigMode, sensorNode->id(), item));
}
}
break;
case 0x0107 : // Childlock status
{
bool locked = (data == 0) ? false : true;
ResourceItem *item = sensorNode->item(RConfigLocked);
if (item && item->toBool() != locked)
{
item->setValue(locked);
Event e(RSensors, RConfigLocked, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0112 : // Window open status
{
bool winopen = (data == 0) ? false : true;
ResourceItem *item = sensorNode->item(RConfigWindowOpen);
if (item && item->toBool() != winopen)
{
item->setValue(winopen);
Event e(RSensors, RConfigWindowOpen, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0114: // Valve state on / off
{
bool onoff = false;
if (data == 1) { onoff = true; }
ResourceItem *item = sensorNode->item(RConfigSetValve);
if (item && item->toBool() != onoff)
{
item->setValue(onoff);
Event e(RSensors, RConfigSetValve, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x0128 : // Childlock status for moe
{
bool locked = (data == 0) ? false : true;
ResourceItem *item = sensorNode->item(RConfigLocked);
if (item && item->toBool() != locked)
{
item->setValue(locked);
Event e(RSensors, RConfigLocked, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0165: // off / on > [off = off, on = heat]
{
QString mode;
if (data == 0) { mode = QLatin1String("off"); }
else if (data == 1) { mode = QLatin1String("manu"); }
else
{
return;
}
ResourceItem *item = sensorNode->item(RConfigMode);
if (item && item->toString() != mode && data == 0) // Only change if off
{
item->setValue(mode);
enqueueEvent(Event(RSensors, RConfigMode, sensorNode->id(), item));
}
}
break;
case 0x016A: // Away mode
{
//bool away = false;
//if (data == 1) { away = true; }
}
break;
case 0x016c: // manual / auto
{
QString mode;
if (data == 0) { mode = QLatin1String("heat"); } // was "manu"
else if (data == 1) { mode = QLatin1String("auto"); } // back to "auto"
else
{
return;
}
ResourceItem *item = sensorNode->item(RConfigMode);
if (item && item->toString() != mode)
{
item->setValue(mode);
enqueueEvent(Event(RSensors, RConfigMode, sensorNode->id(), item));
}
}
break;
case 0x016E: // Low battery
{
bool bat = false;
if (data == 1) { bat = true; }
ResourceItem *item = sensorNode->item(RStateLowBattery);
if (item && item->toBool() != bat)
{
item->setValue(bat);
Event e(RSensors, RStateLowBattery, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x0202: // Thermostat heatsetpoint
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10;
ResourceItem *item = sensorNode->item(RConfigHeatSetpoint);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RConfigHeatSetpoint, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0203: // Thermostat current temperature
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10;
ResourceItem *item = sensorNode->item(RStateTemperature);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RStateTemperature, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x0210: // Thermostat heatsetpoint for moe
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 100;
ResourceItem *item = sensorNode->item(RConfigHeatSetpoint);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RConfigHeatSetpoint, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x0215: // battery
{
quint8 bat = static_cast<qint8>(data & 0xFF);
if (bat > 100) { bat = 100; }
ResourceItem *item = sensorNode->item(RConfigBattery);
if (!item && bat > 0) // valid value: create resource item
{
item = sensorNode->addItem(DataTypeUInt8, RConfigBattery);
}
if (item && item->toNumber() != bat)
{
item->setValue(bat);
Event e(RSensors, RConfigBattery, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0218: // Thermostat current temperature for moe
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10;
ResourceItem *item = sensorNode->item(RStateTemperature);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RStateTemperature, sensorNode->id(), item);
enqueueEvent(e);
update = true;
}
}
break;
case 0x022c : // temperature calibration (offset)
{
qint16 temp = static_cast<qint16>(data & 0xFFFF) * 10;
ResourceItem *item = sensorNode->item(RConfigOffset);
if (item && item->toNumber() != temp)
{
item->setValue(temp);
Event e(RSensors, RConfigOffset, sensorNode->id(), item);
enqueueEvent(e);
}
}
break;
case 0x0266: // min temperature limit
{
//Can be Temperature for some device
if (sensorNode->manufacturer().endsWith(QLatin1String("GbxAXL2")) ||