Merge remote-tracking branch 'origin/dev' into fork/q434343/device_visualization

This commit is contained in:
wznln
2025-05-01 16:33:51 +08:00
10 changed files with 206 additions and 88 deletions

View File

@@ -13,7 +13,7 @@ ilabos_dir = os.path.dirname(os.path.dirname(current_dir))
if ilabos_dir not in sys.path:
sys.path.append(ilabos_dir)
from unilabos.config.config import load_config, BasicConfig
from unilabos.config.config import load_config, BasicConfig, _update_config_from_env
from unilabos.utils.banner_print import print_status, print_unilab_banner
from unilabos.device_mesh.resource_visalization import ResourceVisualization
@@ -86,8 +86,10 @@ def main():
args = parse_args()
args_dict = vars(args)
# 加载配置文件 - 这里保持最先加载配置的逻辑
# 加载配置文件优先加载config然后从env读取
config_path = args_dict.get("config")
if config_path is None:
config_path = os.environ.get("UNILABOS.BASICCONFIG.CONFIG_PATH", None)
if config_path:
if not os.path.exists(config_path):
print_status(f"配置文件 {config_path} 不存在", "error")
@@ -102,6 +104,9 @@ def main():
# 设置BasicConfig参数
BasicConfig.is_host_mode = not args_dict.get("without_host", False)
BasicConfig.slave_no_host = args_dict.get("slave_no_host", False)
machine_name = os.popen("hostname").read().strip()
machine_name = "".join([c if c.isalnum() or c == "_" else "_" for c in machine_name])
BasicConfig.machine_name = machine_name
from unilabos.resources.graphio import (
read_node_link_json,

View File

@@ -168,11 +168,8 @@ class MQTTClient:
if self.mqtt_disable:
return
address = f"labs/{MQConfig.lab_id}/actions/"
action_type_name = action_info["title"]
action_info["title"] = action_id
action_data = json.dumps({action_type_name: action_info}, ensure_ascii=False)
self.client.publish(address, action_data, qos=2)
logger.debug(f"Action data published: address: {address}, {action_data}")
self.client.publish(address, json.dumps(action_info), qos=2)
logger.debug(f"Action data published: address: {address}, {action_id}, {action_info}")
mqtt_client = MQTTClient()

View File

@@ -333,8 +333,13 @@
<tr id="device-info-{{ loop.index }}" class="detail-row" style="display: none;">
<td colspan="5">
<div class="content-full">
<pre>{{ device.class|tojson(indent=4) }}</pre>
{% if device.class %}
<pre>{{ device.class | tojson(indent=4) }}</pre>
{% else %}
<!-- 这里可以放占位内容,比如 -->
<pre>// No data</pre>
{% endif %}
{% if device.is_online %}
<div class="status-badge"><span class="online-status">在线</span></div>
{% endif %}
@@ -366,7 +371,12 @@
<button class="copy-btn" onclick="copyToClipboard(this.previousElementSibling.textContent, event)">复制</button>
<button class="debug-btn" onclick="toggleDebugInfo(this, event)">调试</button>
<div class="debug-info" style="display:none;">
<pre>{{ action_info|tojson(indent=2) }}</pre>
{% if action_info %}
<pre>{{ action_info | tojson(indent=4) }}</pre>
{% else %}
<!-- 这里可以放占位内容,比如 -->
<pre>// No data</pre>
{% endif %}
</div>
</div>

View File

@@ -30,13 +30,13 @@ def get_host_node_info() -> Dict[str, Any]:
return host_info
host_info["available"] = True
host_info["devices"] = {
device_id: {
edge_device_id: {
"namespace": namespace,
"is_online": f"{namespace}/{device_id}" in host_node._online_devices,
"key": f"{namespace}/{device_id}" if namespace.startswith("/") else f"/{namespace}/{device_id}",
"machine_name": host_node.device_machine_names.get(device_id, "未知"),
"is_online": f"{namespace}/{edge_device_id}" in host_node._online_devices,
"key": f"{namespace}/{edge_device_id}" if namespace.startswith("/") else f"/{namespace}/{edge_device_id}",
"machine_name": host_node.device_machine_names.get(edge_device_id, "未知"),
}
for device_id, namespace in host_node.devices_names.items()
for edge_device_id, namespace in host_node.devices_names.items()
}
# 获取已订阅的主题
host_info["subscribed_topics"] = sorted(list(host_node._subscribed_topics))