From b87729d016d3999542b728652cf9b066ed0a6fdc Mon Sep 17 00:00:00 2001 From: sususweet Date: Sat, 11 Oct 2025 23:52:54 +0800 Subject: [PATCH] fix: resolve error when lua file is none --- .../midea_auto_cloud/core/cloud.py | 4 +- .../midea_auto_cloud/core/device.py | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/custom_components/midea_auto_cloud/core/cloud.py b/custom_components/midea_auto_cloud/core/cloud.py index d81bfff..fe84257 100644 --- a/custom_components/midea_auto_cloud/core/cloud.py +++ b/custom_components/midea_auto_cloud/core/cloud.py @@ -304,11 +304,11 @@ class MeijuCloud(MideaCloud): return appliances return None - async def get_device_status(self, appliance_code: int) -> dict | None: + async def get_device_status(self, appliance_code: int, query: dict) -> dict | None: data = { "applianceCode": str(appliance_code), "command": { - "query": {} + "query": query } } if response := await self._api_request( diff --git a/custom_components/midea_auto_cloud/core/device.py b/custom_components/midea_auto_cloud/core/device.py index f66fc3c..adf8bcb 100644 --- a/custom_components/midea_auto_cloud/core/device.py +++ b/custom_components/midea_auto_cloud/core/device.py @@ -166,14 +166,15 @@ class MiedaDevice(threading.Thread): # Convert dot-notation attributes to nested structure for transmission nested_status = self._convert_to_nested_structure(new_status) - - try: - if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes): - await self._build_send(set_cmd) - return - except Exception as e: - MideaLogger.debug(f"LuaRuntimeError in set_attribute {nested_status}: {repr(e)}") - traceback.print_exc() + + if self._lua_runtime is not None: + try: + if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes): + await self._build_send(set_cmd) + return + except Exception as e: + MideaLogger.debug(f"LuaRuntimeError in set_attribute {nested_status}: {repr(e)}") + traceback.print_exc() cloud = self._cloud if cloud and hasattr(cloud, "send_device_control"): @@ -193,13 +194,14 @@ class MiedaDevice(threading.Thread): nested_status = self._convert_to_nested_structure(new_status) if has_new: - try: - if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes): - await self._build_send(set_cmd) - return - except Exception as e: - MideaLogger.debug(f"LuaRuntimeError in set_attributes {nested_status}: {repr(e)}") - traceback.print_exc() + if self._lua_runtime is not None: + try: + if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes): + await self._build_send(set_cmd) + return + except Exception as e: + MideaLogger.debug(f"LuaRuntimeError in set_attributes {nested_status}: {repr(e)}") + traceback.print_exc() cloud = self._cloud if cloud and hasattr(cloud, "send_device_control"): @@ -267,8 +269,13 @@ class MiedaDevice(threading.Thread): async def refresh_status(self): for query in self._queries: - if query_cmd := self._lua_runtime.build_query(query): - await self._build_send(query_cmd) + if self._lua_runtime is not None: + if query_cmd := self._lua_runtime.build_query(query): + await self._build_send(query_cmd) + else: + cloud = self._cloud + if cloud and hasattr(cloud, "get_device_status"): + await cloud.get_device_status(self._device_id, query=query) def _parse_cloud_message(self, decrypted): # MideaLogger.debug(f"Received: {decrypted}")