mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-11-12 07:51:54 +00:00
readability optimization
This commit is contained in:
@@ -97,22 +97,22 @@ async def load_device_config(hass: HomeAssistant, device_type, sn8):
|
|||||||
# # 如果像映射体(包含 entities/centralized 等关键字段),直接使用
|
# # 如果像映射体(包含 entities/centralized 等关键字段),直接使用
|
||||||
# if any(k in raw for k in ["entities", "centralized", "queries", "manufacturer"]):
|
# if any(k in raw for k in ["entities", "centralized", "queries", "manufacturer"]):
|
||||||
# json_data = raw
|
# json_data = raw
|
||||||
if not json_data:
|
# if not json_data:
|
||||||
device_path = f".device_mapping.{'T0x%02X' % device_type}"
|
device_path = f".device_mapping.{'T0x%02X' % device_type}"
|
||||||
try:
|
try:
|
||||||
mapping_module = import_module(device_path, __package__)
|
mapping_module = import_module(device_path, __package__)
|
||||||
for key, config in mapping_module.DEVICE_MAPPING.items():
|
for key, config in mapping_module.DEVICE_MAPPING.items():
|
||||||
# support tuple & regular expression pattern to support multiple sn8 sharing one mapping
|
# support tuple & regular expression pattern to support multiple sn8 sharing one mapping
|
||||||
if (key == sn8) or (isinstance(key, tuple) and sn8 in key) or (isinstance(key, str) and re.match(key, sn8)):
|
if (key == sn8) or (isinstance(key, tuple) and sn8 in key) or (isinstance(key, str) and re.match(key, sn8)):
|
||||||
json_data = config
|
json_data = config
|
||||||
break
|
break
|
||||||
|
if not json_data:
|
||||||
|
if "default" in mapping_module.DEVICE_MAPPING:
|
||||||
|
json_data = mapping_module.DEVICE_MAPPING["default"]
|
||||||
else:
|
else:
|
||||||
if "default" in mapping_module.DEVICE_MAPPING:
|
MideaLogger.warning(f"No mapping found for sn8 {sn8} in type {'T0x%02X' % device_type}")
|
||||||
json_data = mapping_module.DEVICE_MAPPING["default"]
|
except ModuleNotFoundError:
|
||||||
else:
|
MideaLogger.warning(f"Can't load mapping file for type {'T0x%02X' % device_type}")
|
||||||
MideaLogger.warning(f"No mapping found for sn8 {sn8} in type {'T0x%02X' % device_type}")
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
MideaLogger.warning(f"Can't load mapping file for type {'T0x%02X' % device_type}")
|
|
||||||
|
|
||||||
save_data = {sn8: json_data}
|
save_data = {sn8: json_data}
|
||||||
# offload save_json as well
|
# offload save_json as well
|
||||||
|
|||||||
Reference in New Issue
Block a user