forked from sampsyo/wideq
-
Notifications
You must be signed in to change notification settings - Fork 10
/
wideq.py
3446 lines (2743 loc) · 109 KB
/
wideq.py
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
import requests
from urllib.parse import urljoin, urlencode, urlparse, parse_qs
import uuid
import base64
import json
import hashlib
import hmac
from datetime import datetime, timedelta
from collections import namedtuple
import enum
import time
GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList'
APP_KEY = 'wideq'
SECURITY_KEY = 'nuts_securitykey'
DATA_ROOT = 'lgedmRoot'
COUNTRY = 'KR'
LANGUAGE = 'ko-KR'
SVC_CODE = 'SVC202'
CLIENT_ID = 'LGAO221A02'
OAUTH_SECRET_KEY = 'c053c2a6ddeb7ad97cb0eed0dcb31cf8'
OAUTH_CLIENT_KEY = 'LGAO221A02'
DATE_FORMAT = '%a, %d %b %Y %H:%M:%S +0000'
"""HVAC STATE"""
STATE_COOL = '냉방'
STATE_DRY = '제습'
STATE_HEAT = '난방'
STATE_AI = '인공지능'
STATE_FAN = '송풍'
STATE_AIRCLEAN = '공기청정'
STATE_MODE_ON = 'ON'
STATE_MODE_OFF = 'OFF'
STATE_LOW = '약풍'
STATE_MID = '중풍'
STATE_HIGH = '강풍'
STATE_AUTO = '자동'
STATE_POWER = '파워'
STATE_COOLPOWER = '쿨파워'
STATE_LONGPOWER = '롱파워'
STATE_RIGHT_LOW_LEFT_MID = '우약풍/좌중풍'
STATE_RIGHT_LOW_LEFT_HIGH = '우약풍/좌강풍'
STATE_RIGHT_MID_LEFT_LOW = '우중풍/좌약풍'
STATE_RIGHT_MID_LEFT_HIGH = '우중풍/좌강풍'
STATE_RIGHT_HIGH_LEFT_LOW = '우강풍/좌약풍'
STATE_RIGHT_HIGH_LEFT_MID = '우강풍/좌중풍'
STATE_RIGHT_ONLY_LOW = '우약풍'
STATE_RIGHT_ONLY_MID = '우중풍'
STATE_RIGHT_ONLY_HIGH = '우강풍'
STATE_LEFT_ONLY_LOW = '좌약풍'
STATE_LEFT_ONLY_MID = '좌중풍'
STATE_LEFT_ONLY_HIGH = '좌강풍'
STATE_LEFT_RIGHT = '좌/우'
STATE_LEFT_RIGHT_ON = '좌/우'
STATE_RIGHTSIDE_LEFT_RIGHT = '우측 좌/우'
STATE_LEFTSIDE_LEFT_RIGHT = '좌측 좌/우'
STATE_LEFT_RIGHT_STOP = '정지'
STATE_WDIRVSTEP_OFF = '꺼짐'
STATE_WDIRVSTEP_FIRST = '1단계'
STATE_WDIRVSTEP_SECOND = '2단계'
STATE_WDIRVSTEP_THIRD = '3단계'
STATE_WDIRVSTEP_FOURTH = '4단계'
STATE_WDIRVSTEP_FIFTH = '5단계'
STATE_WDIRVSTEP_SIXTH = '6단계'
STATE_WDIRVSTEP_AUTO = '자동'
STATE_WDIRHSTEP_OFF = '꺼짐'
STATE_WDIRHSTEP_FIRST = '1단계'
STATE_WDIRHSTEP_SECOND = '2단계'
STATE_WDIRHSTEP_THIRD = '3단계'
STATE_WDIRHSTEP_FOURTH = '4단계'
STATE_WDIRHSTEP_FIFTH = '5단계'
STATE_WDIRHSTEP_THIRTEENTH = '좌측'
STATE_WDIRHSTEP_THIRTYFIFTH = '우측'
STATE_WDIRHSTEP_AUTO = '자동'
"""REFRIGERATOR STATE"""
STATE_ICE_PLUS_ON = '켜짐'
STATE_ICE_PLUS_OFF = '꺼짐'
STATE_ICE_PLUS_FREEZE = '급속 냉동'
STATE_ICE_PLUS = '특급 냉동'
STATE_REF_MODE_OFF = '꺼짐'
STATE_FRESH_AIR_FILTER_REPLACE_FILTER = '필터교체필요'
STATE_FRESH_AIR_FILTER_SMART_CARE_ON = '켜짐'
STATE_FRESH_AIR_FILTER_SMART_CARE_OFF = '꺼짐'
STATE_FRESH_AIR_FILTER_SMART_CARE_WAIT = '대기'
STATE_FRESH_AIR_FILTER_POWER = '파워'
STATE_FRESH_AIR_FILTER_AUTO = '자동'
STATE_FRESH_AIR_FILTER_OFF = '꺼짐'
STATE_SMART_SAVING_NIGHT = 'NIGHT'
STATE_SMART_SAVING_CUSTOM = 'CUSTOM'
STATE_SMART_SAVING_OFF = 'OFF'
STATE_REF_WATERFILTER_OK = '정상'
STATE_REF_WATERFILTER_REPLACE = '교체필요'
STATE_REF_WATERFILTER_NO_FILTER = '정수기없음'
STATE_REF_ACTIVESAVING_ZERO = '0'
STATE_REF_ACTIVESAVING_ONE = '1'
STATE_REF_ACTIVESAVING_TWO = '2'
STATE_REF_ACTIVESAVING_THREE = '3'
"""DRYER STATE"""
STATE_DRYER_POWER_OFF = '꺼짐'
STATE_DRYER_INITIAL = '코스선택'
STATE_DRYER_RUNNING = '가동중'
STATE_DRYER_PAUSE = '일시정지'
STATE_DRYER_END = '종료'
STATE_DRYER_ERROR = '에러'
STATE_DRYER_PROCESS_DETECTING = '세탁물감지중'
STATE_DRYER_PROCESS_STEAM = '스팀중'
STATE_DRYER_PROCESS_DRY = '건조중'
STATE_DRYER_PROCESS_COOLING = '송풍'
STATE_DRYER_PROCESS_ANTI_CREASE = '구김방지'
STATE_DRYER_PROCESS_END = '종료'
STATE_DRY_LEVEL_IRON = '약'
STATE_DRY_LEVEL_CUPBOARD = '표준'
STATE_DRY_LEVEL_EXTRA = '강력'
STATE_ECOHYBRID_ECO = '에너지'
STATE_ECOHYBRID_NORMAL = '표준'
STATE_ECOHYBRID_TURBO = '스피드'
STATE_COURSE_COTTON_SOFT = '타월'
STATE_COURSE_BULKY_ITEM = '이불'
STATE_COURSE_EASY_CARE = '셔츠'
STATE_COURSE_COTTON = '표준'
STATE_COURSE_SPORTS_WEAR = '기능성의류'
STATE_COURSE_QUICK_DRY = '소량급속'
STATE_COURSE_WOOL = '울/섬세'
STATE_COURSE_RACK_DRY = '선반건조'
STATE_COURSE_COOL_AIR = '송풍'
STATE_COURSE_WARM_AIR = '온풍'
STATE_COURSE_BEDDING_BRUSH = '침구털기'
STATE_COURSE_STERILIZATION = '살균'
STATE_COURSE_REFRESH = '리프레쉬'
STATE_COURSE_POWER = '강력'
STATE_SMARTCOURSE_GYM_CLOTHES = '운동복'
STATE_SMARTCOURSE_RAINY_SEASON = '장마철'
STATE_SMARTCOURSE_DEODORIZATION = '리프레쉬'
STATE_SMARTCOURSE_SMALL_LOAD = '소량 건조'
STATE_SMARTCOURSE_LINGERIE = '란제리'
STATE_SMARTCOURSE_EASY_IRON = '촉촉 건조'
STATE_SMARTCOURSE_SUPER_DRY = '강력 건조'
STATE_SMARTCOURSE_ECONOMIC_DRY = '절약 건조'
STATE_SMARTCOURSE_BIG_SIZE_ITEM = '큰 빨래 건조'
STATE_SMARTCOURSE_MINIMIZE_WRINKLES = '구김 완화 건조'
STATE_SMARTCOURSE_FULL_SIZE_LOAD = '다량건조'
STATE_SMARTCOURSE_JEAN = '청바지'
STATE_ERROR_DOOR = '문열림 에러 - 문이 닫혔는지 확인하세요'
STATE_ERROR_DRAINMOTOR = '배수펌프 에러 - 배수라인이 동결되었는지 확인하세요'
STATE_ERROR_LE1 = '과부하 에러 - 세탁물 양을 확인하세요'
STATE_ERROR_TE1 = '온도센서 에러 - 서비스 센터에 문의하세요'
STATE_ERROR_TE2 = '온도센서 에러 - 서비스 센터에 문의하세요'
STATE_ERROR_F1 = '과온 에러 - 서비스 센터에 문의하세요'
STATE_ERROR_LE2 = '컴프레서 에러 - 서비스 센터에 문의하세요'
STATE_ERROR_AE = '컴프레서 에러 - 서비스 센터에 문의하세요'
STATE_ERROR_dE4 = 'ERROR_dE4'
STATE_ERROR_NOFILTER = '필터 없음 - 필터를 삽입해 주세요'
STATE_ERROR_EMPTYWATER = '물통 가득참 - 물통을 비워주세요'
STATE_ERROR_CE1 = 'ERROR_CE1'
STATE_NO_ERROR = '정상'
STATE_OPTIONITEM_ON = '켜짐'
STATE_OPTIONITEM_OFF = '꺼짐'
"""WASHER STATE"""
STATE_WASHER_POWER_OFF = '꺼짐'
STATE_WASHER_INITIAL = '코스선택'
STATE_WASHER_PAUSE = '일시정지'
STATE_WASHER_ERROR_AUTO_OFF = '에러_자동종료'
STATE_WASHER_RESERVE = '예약중'
STATE_WASHER_DETECTING = '세탁물 감지 중'
STATE_WASHER_SOAK = "불림"
STATE_WASHER_ADD_DRAIN = 'ADD_DRAIN'
STATE_WASHER_DETERGENT_AMOUT = '세제량'
STATE_WASHER_RUNNING = '세탁 중'
STATE_WASHER_PREWASH = '애벌세탁 중'
STATE_WASHER_RINSING = '헹굼 중'
STATE_WASHER_RINSE_HOLD = '헹굼 대기'
STATE_WASHER_SPINNING = '탈수 중'
STATE_WASHER_DRYING = '건조 중'
STATE_WASHER_END = '종료'
STATE_WASHER_FRESHCARE = 'FreshCare'
STATE_WASHER_TCL_ALARM_NORMAL = '통세척'
STATE_WASHER_FROZEN_PREVENT_INITIAL = '동파방지_초기화'
STATE_WASHER_FROZEN_PREVENT_RUNNING = '동파방지_동작중'
STATE_WASHER_FROZEN_PREVENT_PAUSE = '동파방지_일시정지'
STATE_WASHER_ERROR = '에러'
STATE_WASHER_SOILLEVEL_LIGHT = '적은때'
STATE_WASHER_SOILLEVEL_NORMAL = '표준'
STATE_WASHER_SOILLEVEL_HEAVY = '강력'
STATE_WASHER_SOILLEVEL_PRE_WASH = '애벌세탁'
STATE_WASHER_SOILLEVEL_SOAKING = '불림'
STATE_WASHER_SOILLEVEL_THREE = "3분"
STATE_WASHER_SOILLEVEL_SIX = "6분"
STATE_WASHER_SOILLEVEL_TEN = "10분"
STATE_WASHER_SOILLEVEL_TWELVE = "12분"
STATE_WASHER_SOILLEVEL_FOURTEEN = "14분"
STATE_WASHER_SOILLEVEL_SEVENTEEN = "17분"
STATE_WASHER_SOILLEVEL_NINETEEN = "19분"
STATE_WASHER_SOILLEVEL_TWENTYONE = "21분"
STATE_WASHER_SOILLEVEL_TWENTYTHREE = "23분"
STATE_WASHER_SOILLEVEL_TWENTYFIVE = "25분"
STATE_WASHER_WATERTEMP_COLD = '냉수'
STATE_WASHER_WATERTEMP_WARM = "온수"
STATE_WASHER_WATERTEMP_NORMAL = "미온수"
STATE_WASHER_WATERTEMP_COLD_WARM = "냉온수"
STATE_WASHER_WATERTEMP_30 = '30℃'
STATE_WASHER_WATERTEMP_40 = '40℃'
STATE_WASHER_WATERTEMP_60 = '60℃'
STATE_WASHER_WATERTEMP_95 = '95℃'
STATE_WASHER_WATERTEMP_90 = '90℃'
STATE_WASHER_WATERTEMP_35 = '35℃'
STATE_WASHER_WATERTEMP_38 = '38℃'
STATE_WASHER_SPINSPEED_EXTRA_LOW = '섬세'
STATE_WASHER_SPINSPEED_LOW = '약'
STATE_WASHER_SPINSPEED_MEDIUM = '중'
STATE_WASHER_SPINSPEED_HIGH = '강'
STATE_WASHER_SPINSPEED_EXTRA_HIGH = '건조맞춤'
STATE_WASHER_SPINSPEED_ON = '켜짐'
STATE_WASHER_SPINSPEED_OFF = '꺼짐'
STATE_WASHER_SPINSPEED_ULTRA = "Ultra"
STATE_WASHER_SPINSPEED_DRYFIT = "맞춤건조"
STATE_WASHER_SPINSPEED_DELICACY = "섬세"
STATE_WASHER_RINSECOUNT_1 = '1회'
STATE_WASHER_RINSECOUNT_2 = '2회'
STATE_WASHER_RINSECOUNT_3 = '3회'
STATE_WASHER_RINSECOUNT_4 = '4회'
STATE_WASHER_RINSECOUNT_5 = '5회'
STATE_WASHER_RINSECOUNT_6 = '6회'
STATE_WASHER_RINSECOUNT_OFF = '꺼짐'
STATE_WASHER_RINSECOUNT_1_INTENSIVE = "1 안심헹굼"
STATE_WASHER_RINSECOUNT_2_INTENSIVE = "2 안심헹굼"
STATE_WASHER_RINSECOUNT_3_INTENSIVE = "3 안심헹굼"
STATE_WASHER_RINSECOUNT_4_INTENSIVE = "4 안심헹굼"
STATE_WASHER_RINSECOUNT_5_INTENSIVE = "5 안심헹굼"
STATE_WASHER_DRYLEVEL_WIND = '바람건조'
STATE_WASHER_DRYLEVEL_TURBO = '터보건조'
STATE_WASHER_DRYLEVEL_TIME_30 = '시간건조_30분'
STATE_WASHER_DRYLEVEL_TIME_60 = '시간건조_60분'
STATE_WASHER_DRYLEVEL_TIME_90 = '시간건조_90분'
STATE_WASHER_DRYLEVEL_TIME_120 = '시간건조_120분'
STATE_WASHER_DRYLEVEL_TIME_150 = '시간건조_150분'
STATE_WASHER_NO_ERROR = '정상'
STATE_WASHER_ERROR_dE2 = '문 잠금 에러 - 세탁기 문이 잠기지 않았습니다. 세탁기 문을 여닫는 부분에 이물질이 있는지 확인해주세요.'
STATE_WASHER_ERROR_IE = '급수 에러 - 급수가 되지 않습니다. 수도꼭지가 잠겨 있는지 확인해주세요. 수압이 낮은지 확인해주세요. 급수구가 막혀있는지 확인해주세요. 급수 호스가 연결되어 있는지 확인해주세요.'
STATE_WASHER_ERROR_OE = '배수 에러 - 배수가 잘 되지 않습니다. 배수 호스가 높이 설치되어 있는지 확인해주세요. 배수 호스가 꺾이거나 막혀있는지 확인해주세요. 배수 호스가 얼었는지 확인해주세요.'
STATE_WASHER_ERROR_UE = '탈수 에러 - 탈수가 되지 않아 진동과 소음이 심합니다. 세탁물이 한쪽으로 치우쳐 있는지 확인해주세요. 세탁기가 수평 상태인지 확인해주세요.'
STATE_WASHER_ERROR_FE = '물 수위 에러 - 세탁통의 물 수위가 높습니다. 급수 밸브를 잠근 후 LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_PE = '물 수위 센서 에러 - 물 수위 센서가 제대로 작동하지 않습니다.'
STATE_WASHER_ERROR_LE = '드라이버 모터 에러 세탁기 내부 모터에 문제가 발생하였습니다. 세탁량을 줄이고 다시 시도해주세요.'
STATE_WASHER_ERROR_tE = '온도 센서 에러 - 온도 센서가 제대로 작동하지 않습니다.'
STATE_WASHER_ERROR_dHE = 'dHE 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_CE = 'CE 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_PF = 'PF 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_FF = '동결 감지 에러 - 세탁 시작 시 수온이 3 ℃ 이하이거나 세탁기가 얼어 있습니다. 사용 설명서를 확인하여 얼어있는 부품을 녹인 후 사용해주세요.'
STATE_WASHER_ERROR_dCE = 'dCE 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_EE = 'EE 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_PS = '알 수 없는 에러 - LG전자 서비스 센터로 연락해주세요.'
STATE_WASHER_ERROR_dE1 = '문 열림 에러 - 세탁기 문이 열려 있습니다. 세탁기 문을 닫아주세요.'
STATE_WASHER_ERROR_LOE = '세제 투입구 열림 에러 - 세제 투입구가 열려있습니다. 세제 투입구를 닫아주세요. 건조 기능을 사용할 때는 세제 투입구를 항상 닫아주세요.'
STATE_WASHER_ERROR_TL_DO_W = '세탁통 뚜껑 열림 에러 - 세탁통의 뚜껑을 딸깍 소리가 날 때까지 닫으세요.'
STATE_WASHER_ERROR_TL_LE = '과부하 에러 - 세탁기 모터 또는 컴프레서에 문제가 발생하였습니다. 세탁물의 양을 줄이고 다시 시도해도 에러가 지속될 시 서비스 센터에 연락해주세요.'
STATE_WASHER_ERROR_TL_AE = '클러치 에러 - LG전자 서비스 센터 또는 대리점에 연락해주세요.'
STATE_WASHER_ERROR_E7 = '메인 세탁기 감지 스위치 에러 - 미니워시 상단에 트롬이 감지되지 않습니다. 미니워시의 전원을 끄고 서비스 센터에 연락하세요.'
STATE_WASHER_ERROR_LE1 = '동전 끼임 에러 - 세탁통 안쪽 바닥에 동전 및 이물질이 끼여있는지 확인해주세요.'
STATE_WASHER_ERROR_DL = '문 잠금 에러 - 세탁기 문이 잠기지 않았습니다. 세탁기 문을 여닫는 부분에 이물질이 있는지 확인해주세요.'
STATE_WASHER_ERROR_E3 = '배수 밸브 에러 - LG전자 서비스 센터 또는 대리점에 연락해주세요.'
STATE_WASHER_WATERLEVEL_1 = "1단계"
STATE_WASHER_WATERLEVEL_2 = "2단계"
STATE_WASHER_WATERLEVEL_3 = "3단계"
STATE_WASHER_WATERLEVEL_4 = "4단계"
STATE_WASHER_WATERLEVEL_5 = "5단계"
STATE_WASHER_WATERLEVEL_6 = "6단계"
STATE_WASHER_WATERLEVEL_7 = "7단계"
STATE_WASHER_WATERLEVEL_8 = "8단계"
STATE_WASHER_WATERLEVEL_9 = "9단계"
STATE_WASHER_WATERLEVEL_10 = "10단계"
STATE_WASHER_WATERFLOW_DELICATE = "약"
STATE_WASHER_WATERFLOW_MEDIUM = "중"
STATE_WASHER_WATERFLOW_HIGH = "강"
STATE_WASHER_SOAK_FIFTEEN = "15분"
STATE_WASHER_SOAK_THIRTY = "30분"
STATE_WASHER_SOAK_FOURTY = "40분"
STATE_WASHER_SOAK_FOURTYFIVE = "45분"
STATE_WASHER_SOAK_FIFTY = "50분"
STATE_WASHER_SOAK_SIXTY = "60분"
STATE_WASHER_SOAK_ONETWENTY = "120분"
STATE_WASHER_SOAK_ONEEIGHTY = "180분"
STATE_WASHER_SOAK_TWOFOURTY = "240분"
STATE_WASHER_SOAK_THREEHUNDRED = "300분"
STATE_WASHER_SOAK_THREESIXTY = "360분"
STATE_WASHER_SOAK_FOUREIGHTY = "480분"
STATE_WASHER_SOAK_SIXHUNDRED = "600분"
STATE_WASHER_APCOURSE_COTTON = '표준세탁'
STATE_WASHER_APCOURSE_SPEEDWASH_DRY = '스피드워시+건조'
STATE_WASHER_APCOURSE_SPEEDWASH = '스피드워시'
STATE_WASHER_APCOURSE_SINGLE_SHIRT_DRY = '셔츠한벌건조'
STATE_WASHER_APCOURSE_RINSESPIN = '헹굼+탈수'
STATE_WASHER_APCOURSE_SPEEDBOIL = '알뜰삶음'
STATE_WASHER_APCOURSE_ALLERGYCARE = '알러지케어'
STATE_WASHER_APCOURSE_STEAMCLEANING = '스팀클리닝'
STATE_WASHER_APCOURSE_BABYWEAR = '아기옷'
STATE_WASHER_APCOURSE_BLANKET_ROB = '이불살균털기'
STATE_WASHER_APCOURSE_UTILITY = '기능성의류'
STATE_WASHER_APCOURSE_BLANKET = '이불'
STATE_WASHER_APCOURSE_LINGERIE_WOOL = '란제리/울'
STATE_WASHER_APCOURSE_COLDWASH = '찬물세탁'
STATE_WASHER_APCOURSE_TUBCLEAN_SANITARY = '통살균'
STATE_WASHER_APCOURSE_DOWNLOAD_COUSE = '다운로드코스'
STATE_WASHER_COURSE_SMALL_LOAD = '소량세탁'
STATE_WASHER_COURSE_UNDERWEAR = '면 속옷'
STATE_WASHER_COURSE_WOOL = '란제리/울'
STATE_WASHER_COURSE_BOILING = '소량삶음'
STATE_WASHER_COURSE_BABYCARE = '아기옷'
STATE_WASHER_COURSE_RINSE_SPIN = '헹굼+탈수'
STATE_WASHER_COURSE_TUBCLEAN = '통살균'
STATE_WASHER_COURSE_NORMAL = "표준"
STATE_WASHER_COURSE_WOOL_DELICATE = "울/섬세"
STATE_WASHER_COURSE_BEDDING = "이불"
STATE_WASHER_COURSE_TOWEL = "타월"
STATE_WASHER_COURSE_PREWASH_NORMAL = "애벌 + 표준"
STATE_WASHER_COURSE_SAFETY_NORMAL = "안심 표준"
STATE_WASHER_SMARTCOURSE_SILENT = '조용조용'
STATE_WASHER_SMARTCOURSE_SMALL_LOAD = '소량 세탁'
STATE_WASHER_SMARTCOURSE_SKIN_CARE = '스킨 케어'
STATE_WASHER_SMARTCOURSE_RAINY_SEASON = '장마철 세탁'
STATE_WASHER_SMARTCOURSE_SWEAT_STAIN = '땀얼룩 제거'
STATE_WASHER_SMARTCOURSE_SINGLE_GARMENT = '한벌 세탁'
STATE_WASHER_SMARTCOURSE_SCHOOL_UNIFORM = '교복'
STATE_WASHER_SMARTCOURSE_STATIC_REMOVAL = '정전기 제거'
STATE_WASHER_SMARTCOURSE_COLOR_CARE = '컬러 케어'
STATE_WASHER_SMARTCOURSE_SPIN_ONLY = '탈수 단독'
STATE_WASHER_SMARTCOURSE_DEODORIZATION = '냄새 제거'
STATE_WASHER_SMARTCOURSE_BEDDING_CARE = '침구 케어'
STATE_WASHER_SMARTCOURSE_CLOTH_CARE = '옷감 보호'
STATE_WASHER_SMARTCOURSE_SMART_RINSE = '안심 헹굼'
STATE_WASHER_SMARTCOURSE_ECO_WASH = '알뜰 세탁'
STATE_WASHER_SMARTCOURSE_COLD_WASH = '찬물 세탁'
STATE_WASHER_SMARTCOURSE_SOILED_ITEMS = '적은때 세탁'
STATE_WASHER_SMARTCOURSE_SINGLE_SPEED = '한벌 스피드'
STATE_WASHER_SMARTCOURSE_COLOR_PROTECT = '컬러 보호'
STATE_WASHER_SMARTCOURSE_CHILDREN_WEAR = "어린이 의류 세탁"
STATE_WASHER_SMARTCOURSE_SWIN_WEAR = "수영복"
STATE_WASHER_SMARTCOURSE_CURTAINS = "창문 커튼"
STATE_WASHER_SMARTCOURSE_JEAN = "청바지"
STATE_WASHER_SMARTCOURSE_LINGERIE = "란제리"
STATE_WASHER_SMARTCOURSE_FOOD_WASTE = "음식물 얼룩 세탁"
STATE_WASHER_SMARTCOURSE_HEAVY_SPIN = "강력 탈수 세탁"
STATE_WASHER_SMARTCOURSE_BIG_LOAD = "다량 세탁"
STATE_WASHER_TERM_NO_SELECT = '선택 안함'
STATE_WASHER_NOT_SUPPORTED = '지원 안함'
STATE_WASHER_OPTIONITEM_ON = '켜짐'
STATE_WASHER_OPTIONITEM_OFF = '꺼짐'
"""DEHUMIDIFIER STATE"""
STATE_DEHUM_ON = '동작 중'
STATE_DEHUM_OFF = '꺼짐'
STATE_DEHUM_OPMODE_SMART_DEHUM = '스마트제습'
STATE_DEHUM_OPMODE_FAST_DEHUM = '쾌속제습'
STATE_DEHUM_OPMODE_SILENT_DEHUM = '저소음제습'
STATE_DEHUM_OPMODE_CONCENTRATION_DRY = '집중건조'
STATE_DEHUM_OPMODE_CLOTHING_DRY = '의류건조'
STATE_DEHUM_OPMODE_IONIZER = '공기제균'
STATE_DEHUM_WINDSTRENGTH_LOW = '약풍'
STATE_DEHUM_WIDESTRENGTH_HIGH = '강풍'
STATE_DEHUM_AIRREMOVAL_ON = '켜짐'
STATE_DEHUM_AIRREMOVAL_OFF = '꺼짐'
"""WATERPURIFIER STATE"""
STATE_WATERPURIFIER_COCKCLEAN_WAIT = '셀프케어 대기 중'
STATE_WATERPURIFIER_COCKCLEAN_ON = '셀프케어 진행 중'
"""AIRPURIFIER STATE"""
STATE_AIRPURIFIER_ON = '켜짐'
STATE_AIRPURIFIER_OFF = '꺼짐'
STATE_AIRPURIFIER_CIRCULATOR_CLEAN = '클린부스터'
STATE_AIRPURIFIER_BABY_CARE = '싱글청정'
STATE_AIRPURIFIER_CLEAN = '청정모드'
STATE_AIRPURIFIER_DUAL_CLEAN = '듀얼청정'
STATE_AIRPURIFIER_AUTO_MODE = '오토모드'
STATE_AIRPURIFIER_LOWST_LOW = '최약'
STATE_AIRPURIFIER_LOWST = '미약'
STATE_AIRPURIFIER_LOW = '약'
STATE_AIRPURIFIER_LOW_MID = '중약'
STATE_AIRPURIFIER_MID = '중'
STATE_AIRPURIFIER_MID_HIGH = '중강'
STATE_AIRPURIFIER_HIGH = '강'
STATE_AIRPURIFIER_POWER = '파워'
STATE_AIRPURIFIER_AUTO = '자동'
STATE_AIRPURIFIER_LONGPOWER = '롱파워'
STATE_AIRPURIFIER_SHOWER = '샤워풍'
STATE_AIRPURIFIER_FOREST = '숲바람'
STATE_AIRPURIFIER_TURBO = '터보'
STATE_AIRPURIFIER_FASTWIND = '빠른바람'
STATE_AIRPURIFIER_CIR_LOWST_LOW = '청정세기_최약'
STATE_AIRPURIFIER_CIR_LOWST = '청정세기_미약'
STATE_AIRPURIFIER_CIR_LOW = '청정세기_약'
STATE_AIRPURIFIER_CIR_LOW_MID = '청정세기_중약'
STATE_AIRPURIFIER_CIR_MID = '청정세기_중'
STATE_AIRPURIFIER_CIR_MID_HIGH = '청정세기_중강'
STATE_AIRPURIFIER_CIR_HIGH = '청정세기_강'
STATE_AIRPURIFIER_CIR_POWER = '청정세기_파워'
STATE_AIRPURIFIER_CIR_AUTO = '청정세기_자동'
STATE_AIRPURIFIER_CIR_LINK = '청정세기_링크'
STATE_AIRPURIFIER_TOTALAIRPOLUTION_GOOD = '좋음'
STATE_AIRPURIFIER_TOTALAIRPOLUTION_NORMAL = '보통'
STATE_AIRPURIFIER_TOTALAIRPOLUTION_BAD = '나쁨'
STATE_AIRPURIFIER_TOTALAIRPOLUTION_VERYBAD = '매우나쁨'
STATE_AIRPURIFIER_SMELL_WEEK = '약함'
STATE_AIRPURIFIER_SMELL_NORMAL = '보통'
STATE_AIRPURIFIER_SMELL_STRONG = '강함'
STATE_AIRPURIFIER_SMELL_VERYSTRONG = '매우강함'
STATE_AIRPURIFIER_NOT_SUPPORTED = '지원안함'
def gen_uuid():
return str(uuid.uuid4())
def oauth2_signature(message, secret):
"""Get the base64-encoded SHA-1 HMAC digest of a string, as used in
OAauth2 request signatures.
Both the `secret` and `message` are given as text strings. We use
their UTF-8 equivalents.
"""
secret_bytes = secret.encode('utf8')
hashed = hmac.new(secret_bytes, message.encode('utf8'), hashlib.sha1)
digest = hashed.digest()
return base64.b64encode(digest)
def as_list(obj):
"""Wrap non-lists in lists.
If `obj` is a list, return it unchanged. Otherwise, return a
single-element list containing it.
"""
if isinstance(obj, list):
return obj
else:
return [obj]
class APIError(Exception):
"""An error reported by the API."""
def __init__(self, code, message):
self.code = code
self.message = message
class NotLoggedInError(APIError):
"""The session is not valid or expired."""
def __init__(self):
pass
class TokenError(APIError):
"""An authentication token was rejected."""
def __init__(self):
pass
class MonitorError(APIError):
"""Monitoring a device failed, possibly because the monitoring
session failed and needs to be restarted.
"""
def __init__(self, device_id, code):
self.device_id = device_id
self.code = code
class NotConnectError(APIError):
"""The session is not valid or expired."""
def __init__(self):
pass
def lgedm_post(url, data=None, access_token=None, session_id=None):
"""Make an HTTP request in the format used by the API servers.
In this format, the request POST data sent as JSON under a special
key; authentication sent in headers. Return the JSON data extracted
from the response.
The `access_token` and `session_id` are required for most normal,
authenticated requests. They are not required, for example, to load
the gateway server data or to start a session.
"""
headers = {
'x-thinq-application-key': APP_KEY,
'x-thinq-security-key': SECURITY_KEY,
'Accept': 'application/json',
}
if access_token:
headers['x-thinq-token'] = access_token
if session_id:
headers['x-thinq-jsessionId'] = session_id
res = requests.post(url, json={DATA_ROOT: data}, headers=headers)
out = res.json()[DATA_ROOT]
# Check for API errors.
if 'returnCd' in out:
code = out['returnCd']
if code != '0000':
message = out['returnMsg']
if code == "0102":
raise NotLoggedInError()
elif code == "0106":
raise NotConnectError()
elif code == "0010":
return out
else:
raise APIError(code, message)
return out
def gateway_info():
"""Load information about the hosts to use for API interaction.
"""
return lgedm_post(
GATEWAY_URL,
{'countryCode': COUNTRY, 'langCode': LANGUAGE},
)
def oauth_url(auth_base):
"""Construct the URL for users to log in (in a browser) to start an
authenticated session.
"""
url = urljoin(auth_base, 'login/sign_in')
query = urlencode({
'country': COUNTRY,
'language': LANGUAGE,
'svcCode': SVC_CODE,
'authSvr': 'oauth2',
'client_id': CLIENT_ID,
'division': 'ha',
'grant_type': 'password',
})
return '{}?{}'.format(url, query)
def parse_oauth_callback(url):
"""Parse the URL to which an OAuth login redirected to obtain two
tokens: an access token for API credentials, and a refresh token for
getting updated access tokens.
"""
params = parse_qs(urlparse(url).query)
return params['access_token'][0], params['refresh_token'][0]
def login(api_root, access_token):
"""Use an access token to log into the API and obtain a session and
return information about the session.
"""
url = urljoin(api_root + '/', 'member/login')
data = {
'countryCode': COUNTRY,
'langCode': LANGUAGE,
'loginType': 'EMP',
'token': access_token,
}
return lgedm_post(url, data)
def refresh_auth(oauth_root, refresh_token):
"""Get a new access_token using a refresh_token.
May raise a `TokenError`.
"""
token_url = urljoin(oauth_root, '/oauth2/token')
data = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
}
# The timestamp for labeling OAuth requests can be obtained
# through a request to the date/time endpoint:
# https://us.lgeapi.com/datetime
# But we can also just generate a timestamp.
timestamp = datetime.utcnow().strftime(DATE_FORMAT)
# The signature for the requests is on a string consisting of two
# parts: (1) a fake request URL containing the refresh token, and (2)
# the timestamp.
req_url = ('/oauth2/token?grant_type=refresh_token&refresh_token=' +
refresh_token)
sig = oauth2_signature('{}\n{}'.format(req_url, timestamp),
OAUTH_SECRET_KEY)
headers = {
'lgemp-x-app-key': OAUTH_CLIENT_KEY,
'lgemp-x-signature': sig,
'lgemp-x-date': timestamp,
'Accept': 'application/json',
}
res = requests.post(token_url, data=data, headers=headers)
res_data = res.json()
if res_data['status'] != 1:
raise TokenError()
return res_data['access_token']
class Gateway(object):
def __init__(self, auth_base, api_root, oauth_root):
self.auth_base = auth_base
self.api_root = api_root
self.oauth_root = oauth_root
@classmethod
def discover(cls):
gw = gateway_info()
return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'])
def oauth_url(self):
return oauth_url(self.auth_base)
class Auth(object):
def __init__(self, gateway, access_token, refresh_token):
self.gateway = gateway
self.access_token = access_token
self.refresh_token = refresh_token
@classmethod
def from_url(cls, gateway, url):
"""Create an authentication using an OAuth callback URL.
"""
access_token, refresh_token = parse_oauth_callback(url)
return cls(gateway, access_token, refresh_token)
def start_session(self):
"""Start an API session for the logged-in user. Return the
Session object and a list of the user's devices.
"""
session_info = login(self.gateway.api_root, self.access_token)
session_id = session_info['jsessionId']
return Session(self, session_id), as_list(session_info['item'])
def refresh(self):
"""Refresh the authentication, returning a new Auth object.
"""
new_access_token = refresh_auth(self.gateway.oauth_root,
self.refresh_token)
return Auth(self.gateway, new_access_token, self.refresh_token)
class Session(object):
def __init__(self, auth, session_id):
self.auth = auth
self.session_id = session_id
def post(self, path, data=None):
"""Make a POST request to the API server.
This is like `lgedm_post`, but it pulls the context for the
request from an active Session.
"""
url = urljoin(self.auth.gateway.api_root + '/', path)
return lgedm_post(url, data, self.auth.access_token, self.session_id)
def get_devices(self):
"""Get a list of devices associated with the user's account.
Return a list of dicts with information about the devices.
"""
return as_list(self.post('device/deviceList')['item'])
def monitor_start(self, device_id):
"""Begin monitoring a device's status.
Return a "work ID" that can be used to retrieve the result of
monitoring.
"""
res = self.post('rti/rtiMon', {
'cmd': 'Mon',
'cmdOpt': 'Start',
'deviceId': device_id,
'workId': gen_uuid(),
})
return res['workId']
def monitor_poll(self, device_id, work_id):
"""Get the result of a monitoring task.
`work_id` is a string ID retrieved from `monitor_start`. Return
a status result, which is a bytestring, or None if the
monitoring is not yet ready.
May raise a `MonitorError`, in which case the right course of
action is probably to restart the monitoring task.
"""
work_list = [{'deviceId': device_id, 'workId': work_id}]
res = self.post('rti/rtiResult', {'workList': work_list})['workList']
# The return data may or may not be present, depending on the
# monitoring task status.
if 'returnData' in res:
# The main response payload is base64-encoded binary data in
# the `returnData` field. This sometimes contains JSON data
# and sometimes other binary data.
return base64.b64decode(res['returnData'])
else:
return None
# Check for errors.
code = res.get('returnCode') # returnCode can be missing.
if code != '0000':
raise MonitorError(device_id, code)
def monitor_stop(self, device_id, work_id):
"""Stop monitoring a device."""
self.post('rti/rtiMon', {
'cmd': 'Mon',
'cmdOpt': 'Stop',
'deviceId': device_id,
'workId': work_id,
})
def set_device_operation(self, device_id, values):
"""Control a device's settings.
`values` is a key/value map containing the settings to update.
"""
return self.post('rti/rtiControl', {
'cmd': 'Control',
'cmdOpt': 'Operation',
'value': values,
'deviceId': device_id,
'workId': gen_uuid(),
'data': '',
})
def set_device_controls(self, device_id, values):
"""Control a device's settings.
`values` is a key/value map containing the settings to update.
"""
return self.post('rti/rtiControl', {
'cmd': 'Control',
'cmdOpt': 'Set',
'value': values,
'deviceId': device_id,
'workId': gen_uuid(),
'data': '',
})
def get_device_config(self, device_id, key, category='Config'):
"""Get a device configuration option.
The `category` string should probably either be "Config" or
"Control"; the right choice appears to depend on the key.
"""
res = self.post('rti/rtiControl', {
'cmd': category,
'cmdOpt': 'Get',
'value': key,
'deviceId': device_id,
'workId': gen_uuid(),
'data': '',
})
return res['returnData']
def delete_permission(self, device_id):
self.post('rti/delControlPermission', {
'deviceId': device_id,
})
def get_power_data(self, device_id, period):
res = self.post('aircon/inquiryPowerData', {
'deviceId': device_id,
'period': period,
})
code = res.get('returnCd') # returnCode can be missing.
if code == '0000':
return res['powerData']
elif code == '0010':
return '0'
else:
raise MonitorError(device_id, code)
def get_water_usage(self, device_id, typeCode, sDate, eDate):
res = self.post('rms/inquiryWaterConsumptionInfo', {
'deviceId': device_id,
'type': typeCode,
'startDate': sDate,
'endDate': eDate,
})
code = res.get('returnCd') # returnCode can be missing.
if code != '0000':
raise MonitorError(device_id, code)
else:
return res['item']
def get_outdoor_weather(self, area):
res = self.post('weather/weatherNewsData',{
'area': area
})
code = res.get('returnCd') # returnCode can be missing.
if code != '0000':
raise MonitorError(device_id, code)
else:
return res
def get_dustsensor_data(self):
res = self.post('v2/devices/97b2fc516b00b58c376cd8123f56cc8f/data?data=sensor.pm25%2Bsensor.pm10%2Bsensor.pm1&type=last')
"""
code = res.get('returnCd') # returnCode can be missing.
if code != '0000':
raise MonitorError(device_id, code)
else:
"""
print(res)
with open('/config/wideq-1/dust_sensor_data.json','w', encoding="utf-8") as dumpfile:
json.dump(res, dumpfile, ensure_ascii=False, indent="\t")
return res
class Monitor(object):
"""A monitoring task for a device.
This task is robust to some API-level failures. If the monitoring
task expires, it attempts to start a new one automatically. This
makes one `Monitor` object suitable for long-term monitoring.
"""
def __init__(self, session, device_id):
self.session = session
self.device_id = device_id
def start(self):
self.work_id = self.session.monitor_start(self.device_id)
def stop(self):
self.session.monitor_stop(self.device_id, self.work_id)
def poll(self):
"""Get the current status data (a bytestring) or None if the
device is not yet ready.
"""
self.work_id = self.session.monitor_start(self.device_id)
try:
return self.session.monitor_poll(self.device_id, self.work_id)
except MonitorError:
# Try to restart the task.
self.stop()
self.start()
return None
@staticmethod
def decode_json(data):
"""Decode a bytestring that encodes JSON status data."""
return json.loads(data.decode('utf8'))
def poll_json(self):
"""For devices where status is reported via JSON data, get the
decoded status result (or None if status is not available).
"""
data = self.poll()
return self.decode_json(data) if data else None
def __enter__(self):
self.start()
return self
def __exit__(self, type, value, tb):
self.stop()
class Client(object):
"""A higher-level API wrapper that provides a session more easily
and allows serialization of state.
"""
def __init__(self, gateway=None, auth=None, session=None):
# The three steps required to get access to call the API.
self._gateway = gateway
self._auth = auth
self._session = session
# The last list of devices we got from the server. This is the
# raw JSON list data describing the devices.
self._devices = None
# Cached model info data. This is a mapping from URLs to JSON
# responses.
self._model_info = {}
@property
def gateway(self):
if not self._gateway:
self._gateway = Gateway.discover()
return self._gateway
@property
def auth(self):
if not self._auth:
assert False, "unauthenticated"
return self._auth
@property
def session(self):
if not self._session:
self._session, self._devices = self.auth.start_session()
return self._session
@property
def devices(self):
"""DeviceInfo objects describing the user's devices.
"""
if not self._devices:
self._devices = self.session.get_devices()
return (DeviceInfo(d) for d in self._devices)
def get_device(self, device_id):
"""Look up a DeviceInfo object by device ID.
Return None if the device does not exist.
"""
for device in self.devices:
if device.id == device_id:
return device
return None
@classmethod
def load(cls, state):
"""Load a client from serialized state.
"""
client = cls()