mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-17 18:05:51 +00:00
fix: refresh status fallback to lua when cloud api is down. Fixes #52.
This commit is contained in:
@@ -291,32 +291,34 @@ class MiedaDevice(threading.Thread):
|
|||||||
|
|
||||||
async def refresh_status(self):
|
async def refresh_status(self):
|
||||||
for query in self._queries:
|
for query in self._queries:
|
||||||
# try:
|
|
||||||
# if self._lua_runtime is not None:
|
|
||||||
# if query_cmd := self._lua_runtime.build_query(query):
|
|
||||||
# await self._build_send(query_cmd)
|
|
||||||
# return
|
|
||||||
# except Exception as e:
|
|
||||||
# traceback.print_exc()
|
|
||||||
|
|
||||||
cloud = self._cloud
|
cloud = self._cloud
|
||||||
if cloud and hasattr(cloud, "get_device_status"):
|
if cloud and hasattr(cloud, "get_device_status"):
|
||||||
if isinstance(cloud, MSmartHomeCloud):
|
if isinstance(cloud, MSmartHomeCloud):
|
||||||
status = await cloud.get_device_status(
|
if status := await cloud.get_device_status(
|
||||||
appliance_code=self._device_id,
|
appliance_code=self._device_id,
|
||||||
device_type=self.device_type,
|
device_type=self.device_type,
|
||||||
sn=self.sn,
|
sn=self.sn,
|
||||||
model_number=self.subtype,
|
model_number=self.subtype,
|
||||||
manufacturer_code=self._manufacturer_code,
|
manufacturer_code=self._manufacturer_code,
|
||||||
query=query
|
query=query
|
||||||
)
|
):
|
||||||
self._parse_cloud_message(status)
|
self._parse_cloud_message(status)
|
||||||
|
else:
|
||||||
|
if self._lua_runtime is not None:
|
||||||
|
if query_cmd := self._lua_runtime.build_query(query):
|
||||||
|
await self._build_send(query_cmd)
|
||||||
|
|
||||||
elif isinstance(cloud, MeijuCloud):
|
elif isinstance(cloud, MeijuCloud):
|
||||||
status = await cloud.get_device_status(
|
if status := await cloud.get_device_status(
|
||||||
appliance_code=self._device_id,
|
appliance_code=self._device_id,
|
||||||
query=query
|
query=query
|
||||||
)
|
):
|
||||||
self._parse_cloud_message(status)
|
self._parse_cloud_message(status)
|
||||||
|
else:
|
||||||
|
if self._lua_runtime is not None:
|
||||||
|
if query_cmd := self._lua_runtime.build_query(query):
|
||||||
|
await self._build_send(query_cmd)
|
||||||
|
|
||||||
|
|
||||||
def _parse_cloud_message(self, status):
|
def _parse_cloud_message(self, status):
|
||||||
# MideaLogger.debug(f"Received: {decrypted}")
|
# MideaLogger.debug(f"Received: {decrypted}")
|
||||||
@@ -415,13 +417,7 @@ class MiedaDevice(threading.Thread):
|
|||||||
return ParseMessageResult.SUCCESS
|
return ParseMessageResult.SUCCESS
|
||||||
|
|
||||||
async def _send_message(self, data):
|
async def _send_message(self, data):
|
||||||
reply = None
|
if reply := await self._cloud.send_cloud(self._device_id, data):
|
||||||
if isinstance(self._cloud, MSmartHomeCloud):
|
|
||||||
reply = await self._cloud.send_cloud(self._device_id, data)
|
|
||||||
elif isinstance(self._cloud, MeijuCloud):
|
|
||||||
reply = await self._cloud.send_cloud(self._device_id, data)
|
|
||||||
|
|
||||||
if reply is not None:
|
|
||||||
if reply_dec := self._lua_runtime.decode_status(dec_string_to_bytes(reply).hex()):
|
if reply_dec := self._lua_runtime.decode_status(dec_string_to_bytes(reply).hex()):
|
||||||
MideaLogger.debug(f"Decoded: {reply_dec}")
|
MideaLogger.debug(f"Decoded: {reply_dec}")
|
||||||
result = self._parse_cloud_message(reply_dec)
|
result = self._parse_cloud_message(reply_dec)
|
||||||
|
|||||||
Reference in New Issue
Block a user