mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-10-15 10:48:26 +00:00
feat: fallback to cloud control when lua script encounter error.
This commit is contained in:
@@ -140,8 +140,13 @@ class MiedaDevice(threading.Thread):
|
|||||||
for attr in self._centralized:
|
for attr in self._centralized:
|
||||||
new_status[attr] = self._attributes.get(attr)
|
new_status[attr] = self._attributes.get(attr)
|
||||||
new_status[attribute] = value
|
new_status[attribute] = value
|
||||||
if set_cmd := self._lua_runtime.build_control(new_status):
|
try:
|
||||||
await self._build_send(set_cmd)
|
if set_cmd := self._lua_runtime.build_control(new_status):
|
||||||
|
await self._build_send(set_cmd)
|
||||||
|
except Exception as e:
|
||||||
|
cloud = self._cloud
|
||||||
|
if cloud and hasattr(cloud, "send_device_control"):
|
||||||
|
await cloud.send_device_control(self._device_id, control=new_status, status=self._attributes)
|
||||||
|
|
||||||
async def set_attributes(self, attributes):
|
async def set_attributes(self, attributes):
|
||||||
new_status = {}
|
new_status = {}
|
||||||
@@ -153,8 +158,13 @@ class MiedaDevice(threading.Thread):
|
|||||||
has_new = True
|
has_new = True
|
||||||
new_status[attribute] = value
|
new_status[attribute] = value
|
||||||
if has_new:
|
if has_new:
|
||||||
if set_cmd := self._lua_runtime.build_control(new_status):
|
try:
|
||||||
await self._build_send(set_cmd)
|
if set_cmd := self._lua_runtime.build_control(new_status):
|
||||||
|
await self._build_send(set_cmd)
|
||||||
|
except Exception as e:
|
||||||
|
cloud = self._cloud
|
||||||
|
if cloud and hasattr(cloud, "send_device_control"):
|
||||||
|
await cloud.send_device_control(self._device_id, control=new_status, status=self._attributes)
|
||||||
|
|
||||||
def set_ip_address(self, ip_address):
|
def set_ip_address(self, ip_address):
|
||||||
MideaLogger.debug(f"Update IP address to {ip_address}")
|
MideaLogger.debug(f"Update IP address to {ip_address}")
|
||||||
|
@@ -6,7 +6,7 @@ from .logger import MideaLogger
|
|||||||
|
|
||||||
class LuaRuntime:
|
class LuaRuntime:
|
||||||
def __init__(self, file):
|
def __init__(self, file):
|
||||||
self._runtimes = lupa.LuaRuntime()
|
self._runtimes = lupa.lua51.LuaRuntime()
|
||||||
string = f'dofile("{file}")'
|
string = f'dofile("{file}")'
|
||||||
self._runtimes.execute(string)
|
self._runtimes.execute(string)
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
|
Reference in New Issue
Block a user