mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-11-12 16:01:54 +00:00
fix: fix lua library error.
This commit is contained in:
@@ -57,7 +57,9 @@ PLATFORMS: list[Platform] = [
|
||||
Platform.WATER_HEATER,
|
||||
Platform.FAN,
|
||||
Platform.LIGHT,
|
||||
Platform.HUMIDIFIER
|
||||
Platform.HUMIDIFIER,
|
||||
Platform.NUMBER,
|
||||
Platform.BUTTON
|
||||
]
|
||||
|
||||
|
||||
@@ -138,20 +140,48 @@ async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
cjson = os.getcwd() + "/cjson.lua"
|
||||
bit = os.getcwd() + "/bit.lua"
|
||||
# if not os.path.exists(cjson):
|
||||
from .const import CJSON_LUA
|
||||
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
# if not os.path.exists(bit):
|
||||
from .const import BIT_LUA
|
||||
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
return True
|
||||
|
||||
# 使用Home Assistant配置目录而不是当前工作目录
|
||||
config_dir = hass.config.path(DOMAIN)
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
|
||||
cjson = os.path.join(config_dir, "cjson.lua")
|
||||
bit = os.path.join(config_dir, "bit.lua")
|
||||
|
||||
# 只有文件不存在时才创建
|
||||
if not os.path.exists(cjson):
|
||||
from .const import CJSON_LUA
|
||||
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
||||
try:
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
except PermissionError as e:
|
||||
MideaLogger.error(f"Failed to create cjson.lua at {cjson}: {e}")
|
||||
# 如果无法创建文件,尝试使用临时目录
|
||||
import tempfile
|
||||
temp_dir = tempfile.gettempdir()
|
||||
cjson = os.path.join(temp_dir, "cjson.lua")
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
MideaLogger.warning(f"Using temporary file for cjson.lua: {cjson}")
|
||||
|
||||
if not os.path.exists(bit):
|
||||
from .const import BIT_LUA
|
||||
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
||||
try:
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
except PermissionError as e:
|
||||
MideaLogger.error(f"Failed to create bit.lua at {bit}: {e}")
|
||||
# 如果无法创建文件,尝试使用临时目录
|
||||
import tempfile
|
||||
temp_dir = tempfile.gettempdir()
|
||||
bit = os.path.join(temp_dir, "bit.lua")
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
MideaLogger.warning(f"Using temporary file for bit.lua: {bit}")
|
||||
|
||||
return True
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
device_type = config_entry.data.get(CONF_TYPE)
|
||||
|
||||
Reference in New Issue
Block a user