@@ -209,7 +209,7 @@ async def _api_request(
209
209
)
210
210
raw = await r .read ()
211
211
_LOGGER .debug (
212
- "Midea cloud API url: %s, data: %s, response: %s" ,
212
+ "Midea cloud API url: %s, \n data: %s, \n response: %s" ,
213
213
url ,
214
214
_redact_data (str (data )),
215
215
_redact_data (str (raw )),
@@ -306,6 +306,15 @@ async def download_lua(
306
306
"""Download lua integration."""
307
307
raise NotImplementedError
308
308
309
+ async def download_plugin (
310
+ self ,
311
+ path : str ,
312
+ device_type : int ,
313
+ sn : str ,
314
+ ) -> str | None :
315
+ """Download lua integration."""
316
+ raise NotImplementedError
317
+
309
318
310
319
class MeijuCloud (MideaCloud ):
311
320
"""Meiju Cloud."""
@@ -333,6 +342,20 @@ def __init__(
333
342
api_url = cloud_data ["api_url" ],
334
343
)
335
344
345
+ def _make_general_data (self ) -> dict [str , Any ]:
346
+ return {
347
+ "src" : self ._app_id ,
348
+ "format" : "2" ,
349
+ "stamp" : datetime .now (tz = UTC ).strftime ("%Y%m%d%H%M%S" ),
350
+ "platformId" : "1" ,
351
+ "deviceId" : self ._device_id ,
352
+ "reqId" : token_hex (16 ),
353
+ "uid" : self ._uid ,
354
+ "clientType" : "1" ,
355
+ "appId" : self ._app_id ,
356
+ "language" : "en_US" ,
357
+ }
358
+
336
359
async def login (self ) -> bool :
337
360
"""Authenticate to Meiju Cloud."""
338
361
if login_id := await self ._get_login_id ():
@@ -539,6 +562,46 @@ async def download_lua(
539
562
await fp .write (stream )
540
563
return str (fnm ) if fnm else None
541
564
565
+ async def download_plugin (
566
+ self ,
567
+ path : str ,
568
+ device_type : int ,
569
+ sn : str ,
570
+ ) -> str | None :
571
+ """Download lua integration."""
572
+ data = self ._make_general_data ()
573
+ data .update (
574
+ {
575
+ "clientVersion" : "201" ,
576
+ "match" : "1" ,
577
+ "applianceList" : [
578
+ {
579
+ "appModel" : sn [9 :17 ],
580
+ "appType" : hex (device_type ),
581
+ "modelNumber" : "0" ,
582
+ },
583
+ ],
584
+ },
585
+ )
586
+ fnm = None
587
+ if response := await self ._api_request (
588
+ endpoint = "/v1/plugin/update/getplugin" ,
589
+ data = data ,
590
+ ):
591
+ # get file name from url
592
+ _LOGGER .debug ("response: %s, type: %s" , response , type (response ))
593
+ file_name = response ["list" ][0 ]["url" ].split ("/" )[- 1 ]
594
+ # download plugin from url
595
+ res = await self ._session .get (response ["list" ][0 ]["url" ])
596
+ if res .status == HTTPStatus .OK :
597
+ # get the file content in binary mode
598
+ plugin = await res .read ()
599
+ if plugin :
600
+ fnm = f"{ path } /{ file_name } "
601
+ async with aiofiles .open (fnm , "wb" ) as fp :
602
+ await fp .write (plugin )
603
+ return str (fnm ) if fnm else None
604
+
542
605
543
606
class SmartHomeCloud (MideaCloud ):
544
607
"""MSmart Home Cloud."""
@@ -582,6 +645,7 @@ def _make_general_data(self) -> dict[str, Any]:
582
645
"uid" : self ._uid ,
583
646
"clientType" : "1" ,
584
647
"appId" : self ._app_id ,
648
+ "language" : "en_US" ,
585
649
}
586
650
587
651
async def _api_request (
@@ -699,20 +763,18 @@ async def download_lua(
699
763
manufacturer_code : str = "0000" ,
700
764
) -> str | None :
701
765
"""Download lua integration."""
702
- data = {
703
- "clientType" : "1" ,
704
- "appId" : self ._app_id ,
705
- "format" : "2" ,
706
- "deviceId" : self ._device_id ,
707
- "iotAppId" : self ._app_id ,
708
- "applianceMFCode" : manufacturer_code ,
709
- "applianceType" : hex (device_type ),
710
- "applianceSn" : self ._security .aes_encrypt_with_fixed_key (
711
- sn .encode ("ascii" ),
712
- ).hex (),
713
- "version" : "0" ,
714
- "encryptedType " : "2" ,
715
- }
766
+ data = self ._make_general_data ()
767
+ data .update (
768
+ {
769
+ "applianceMFCode" : manufacturer_code ,
770
+ "applianceType" : hex (device_type ),
771
+ "applianceSn" : self ._security .aes_encrypt_with_fixed_key (
772
+ sn .encode ("ascii" ),
773
+ ).hex (),
774
+ "version" : "0" ,
775
+ "encryptedType " : "2" ,
776
+ },
777
+ )
716
778
if model_number is not None :
717
779
data ["modelNumber" ] = model_number
718
780
fnm = None
@@ -734,6 +796,45 @@ async def download_lua(
734
796
await fp .write (stream )
735
797
return str (fnm ) if fnm else None
736
798
799
+ async def download_plugin (
800
+ self ,
801
+ path : str ,
802
+ device_type : int ,
803
+ sn : str ,
804
+ ) -> str | None :
805
+ """Download lua integration."""
806
+ data = self ._make_general_data ()
807
+ data .update (
808
+ {
809
+ "clientVersion" : "0" ,
810
+ "applianceList" : [
811
+ {
812
+ "appModel" : sn [9 :17 ],
813
+ "appType" : hex (device_type ),
814
+ "modelNumber" : "0" ,
815
+ },
816
+ ],
817
+ },
818
+ )
819
+ fnm = None
820
+ if response := await self ._api_request (
821
+ endpoint = "/v1/plugin/update/overseas/get" ,
822
+ data = data ,
823
+ ):
824
+ # get file name from url
825
+ _LOGGER .debug ("response: %s, type: %s" , response , type (response ))
826
+ file_name = response ["result" ][0 ]["url" ].split ("/" )[- 1 ]
827
+ # download plugin from url
828
+ res = await self ._session .get (response ["result" ][0 ]["url" ])
829
+ if res .status == HTTPStatus .OK :
830
+ # get the file content in binary mode
831
+ plugin = await res .read ()
832
+ if plugin :
833
+ fnm = f"{ path } /{ file_name } "
834
+ async with aiofiles .open (fnm , "wb" ) as fp :
835
+ await fp .write (plugin )
836
+ return str (fnm ) if fnm else None
837
+
737
838
738
839
class MideaAirCloud (MideaCloud ):
739
840
"""Midea Air Cloud."""
0 commit comments