mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-17 09:55:51 +00:00
fix:remove plugin download in msmart app.
This commit is contained in:
@@ -734,93 +734,6 @@ class MSmartHomeCloud(MideaCloud):
|
||||
await fp.write(stream)
|
||||
return fnm
|
||||
|
||||
async def download_plugin(
|
||||
self, path: str,
|
||||
appliance_code: str,
|
||||
smart_product_id: str,
|
||||
device_type: int,
|
||||
sn: str,
|
||||
sn8: str,
|
||||
model_number: str | None,
|
||||
manufacturer_code: str = "0000",
|
||||
):
|
||||
# 构建 applianceList,根据传入的参数动态生成
|
||||
appliance_info = {
|
||||
"appModel": sn8,
|
||||
"appEnterprise": manufacturer_code,
|
||||
"appType": f"0x{device_type:02X}",
|
||||
"applianceCode": str(appliance_code) if isinstance(appliance_code, int) else appliance_code,
|
||||
"smartProductId": str(smart_product_id) if isinstance(smart_product_id, int) else smart_product_id,
|
||||
"modelNumber": model_number or "0",
|
||||
"versionCode": 0
|
||||
}
|
||||
appliance_list = [appliance_info]
|
||||
data = {
|
||||
"applianceList": json.dumps(appliance_list),
|
||||
"iotAppId": self.APP_ID,
|
||||
"match": "1",
|
||||
"clientType": "1",
|
||||
"clientVersion": 201
|
||||
}
|
||||
fnm = None
|
||||
if response := await self._api_request(
|
||||
endpoint="/v1/plugin/update/getPluginV3",
|
||||
data=data
|
||||
):
|
||||
# response 是 {"list": [...]}
|
||||
plugin_list = response.get("list", [])
|
||||
if not plugin_list:
|
||||
MideaLogger.warning(f"No plugin found for device type 0x{device_type:02X}, sn: {sn}")
|
||||
return None
|
||||
|
||||
# 找到匹配的设备(优先匹配 applianceCode,其次匹配 appType)
|
||||
matched_plugin = None
|
||||
# 首先尝试精确匹配 applianceCode
|
||||
for plugin in plugin_list:
|
||||
if plugin.get("applianceCode") == sn and plugin.get("appType") == f"0x{device_type:02X}":
|
||||
matched_plugin = plugin
|
||||
break
|
||||
|
||||
# 如果没有精确匹配,使用第一个匹配 appType 的
|
||||
if not matched_plugin:
|
||||
for plugin in plugin_list:
|
||||
if plugin.get("appType") == f"0x{device_type:02X}":
|
||||
matched_plugin = plugin
|
||||
break
|
||||
|
||||
if not matched_plugin:
|
||||
MideaLogger.warning(f"No matching plugin found for device type 0x{device_type:02X}, sn: {sn}")
|
||||
return None
|
||||
|
||||
# 下载 zip 文件
|
||||
zip_url = matched_plugin.get("url")
|
||||
zip_title = matched_plugin.get("title", f"plugin_0x{device_type:02X}.zip")
|
||||
|
||||
if not zip_url:
|
||||
MideaLogger.warning(f"No download URL found for plugin: {zip_title}")
|
||||
return None
|
||||
|
||||
try:
|
||||
# 确保目录存在
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
||||
res = await self._session.get(zip_url)
|
||||
if res.status == 200:
|
||||
zip_data = await res.read()
|
||||
if zip_data:
|
||||
fnm = f"{path}/{zip_title}"
|
||||
async with aiofiles.open(fnm, "wb") as fp:
|
||||
await fp.write(zip_data)
|
||||
MideaLogger.info(f"Downloaded plugin file: {fnm}")
|
||||
else:
|
||||
MideaLogger.warning(f"Downloaded zip file is empty: {zip_url}")
|
||||
else:
|
||||
MideaLogger.warning(f"Failed to download plugin, status: {res.status}, url: {zip_url}")
|
||||
except Exception as e:
|
||||
MideaLogger.error(f"Error downloading plugin: {e}")
|
||||
traceback.print_exc()
|
||||
return fnm
|
||||
|
||||
async def send_cloud(self, appliance_code: int, data: bytearray):
|
||||
appliance_code = str(appliance_code)
|
||||
params = {
|
||||
|
||||
Reference in New Issue
Block a user