diff --git a/README.md b/README.md index 20ed444..5543d35 100644 --- a/README.md +++ b/README.md @@ -111,10 +111,22 @@ sigmesh_gateway: ### 添加 Lovelace 面板 -1. **复制前端文件** +**方式一:手动部署(推荐)** + +1. **运行部署脚本** ```bash - mkdir -p /config/www/sigmesh_gateway - cp custom_components/sigmesh_gateway/sigmesh-gateway-panel.js /config/www/sigmesh_gateway/ + chmod +x deploy.sh + ./deploy.sh + ``` + + 或者手动执行: + ```bash + # 复制集成文件 + cp -r custom_components/sigmesh_gateway ~/.homeassistant/custom_components/ + + # 复制 Lovelace 卡片文件 + mkdir -p ~/.homeassistant/www/sigmesh_gateway + cp custom_components/sigmesh_gateway/sigmesh-gateway-panel.js ~/.homeassistant/www/sigmesh_gateway/ ``` 2. **配置 frontend** @@ -127,11 +139,28 @@ sigmesh_gateway: ``` 3. **重启 Home Assistant** + ```bash + ha core restart + ``` 4. **添加卡片到 Dashboard** - 编辑仪表板 → 添加卡片 → 自定义卡片 - 输入:`custom:sigmesh-gateway-panel` +**方式二:通过 HACS 安装** + +通过 HACS 安装后,前端模块会自动加载。 + +### 常见问题 + +**错误:Custom element not found: sigmesh-gateway-panel** + +解决方法: +1. 确认卡片文件已复制到正确位置:`~/.homeassistant/www/sigmesh_gateway/sigmesh-gateway-panel.js` +2. 确认 `configuration.yaml` 中配置了 `extra_module_url` +3. 清除浏览器缓存或硬刷新(Ctrl+Shift+R) +4. 检查浏览器控制台是否有加载错误 + ### Web UI 功能 - 📡 **设备扫描** - 扫描可用的 Bluetooth Mesh 设备 diff --git a/custom_components/sigmesh_gateway/sigmesh-gateway-panel.js b/custom_components/sigmesh_gateway/sigmesh-gateway-panel.js index dffabb0..c14fb9a 100644 --- a/custom_components/sigmesh_gateway/sigmesh-gateway-panel.js +++ b/custom_components/sigmesh_gateway/sigmesh-gateway-panel.js @@ -2,18 +2,31 @@ * SigMesh Gateway 配网控制面板 - Lovelace 自定义卡片 * * 使用方法: - * 1. 将此文件复制到 HA 的 www/community/sigmesh_gateway/ 目录 - * 2. 在 HA 的 configuration.yaml 中添加: + * 1. 在 HACS 中安装本集成后,卡片会自动可用 + * 2. 或者手动复制此文件到 HA 的 www/sigmesh_gateway/ 目录 + * 3. 在 HA 的 configuration.yaml 中添加: * frontend: * extra_module_url: - * - /local/community/sigmesh_gateway/sigmesh-gateway-panel.js - * 3. 在 Lovelace Dashboard 中添加自定义卡片 + * - /local/sigmesh_gateway/sigmesh-gateway-panel.js + * 4. 在 Lovelace Dashboard 中添加自定义卡片: custom:sigmesh-gateway-panel */ // 配置常量 const API_BASE = '/api/sigmesh_gateway'; const POLL_INTERVAL = 3000; +// 注册到全局自定义卡片列表 +if (!window.customCards) { + window.customCards = []; +} +window.customCards.push({ + type: 'sigmesh-gateway-panel', + name: 'SigMesh Gateway 配网管理', + description: '管理 SigMesh 网关的配网和分组功能', + preview: true, + documentationURL: 'https://github.com/impress-sig-mesh/sigmesh_gateway', +}); + /** * Lovelace 卡片组件 */ diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..0167965 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# SigMesh Gateway 部署脚本 + +set -e + +echo "=== SigMesh Gateway 部署脚本 ===" + +# 获取 HA 配置目录 +HA_CONFIG="${HOME}/.homeassistant" +if [ -n "$1" ]; then + HA_CONFIG="$1" +fi + +echo "HA 配置目录:$HA_CONFIG" + +# 1. 复制集成文件 +echo "复制集成文件..." +cp -r custom_components/sigmesh_gateway "$HA_CONFIG/custom_components/" + +# 2. 复制 Lovelace 卡片文件 +echo "复制 Lovelace 卡片文件..." +mkdir -p "$HA_CONFIG/www/sigmesh_gateway" +cp custom_components/sigmesh_gateway/sigmesh-gateway-panel.js "$HA_CONFIG/www/sigmesh_gateway/" + +# 3. 设置权限 +echo "设置权限..." +chown -R homeassistant:homeassistant "$HA_CONFIG/custom_components/sigmesh_gateway" +chown -R homeassistant:homeassistant "$HA_CONFIG/www/sigmesh_gateway" + +# 4. 提示用户配置 frontend +echo "" +echo "=== 配置步骤 ===" +echo "请在 configuration.yaml 中添加以下内容:" +echo "" +echo "frontend:" +echo " extra_module_url:" +echo " - /local/sigmesh_gateway/sigmesh-gateway-panel.js" +echo "" + +# 5. 重启提示 +echo "=== 重启 Home Assistant ===" +echo "运行以下命令重启:" +echo " ha core restart" +echo "" +echo "部署完成!" diff --git a/hacs.json b/hacs.json index b692b19..c5b2ec8 100644 --- a/hacs.json +++ b/hacs.json @@ -6,5 +6,9 @@ "zip_release": true, "homeassistant": "2024.1.0", "hacs": "1.34.0", - "icon": ".asset/impress_sig_mesh_hacs.png" + "icon": ".asset/impress_sig_mesh_hacs.png", + "category": "integration", + "frontend": { + "extra_module_url": "/local/sigmesh_gateway/sigmesh-gateway-panel.js" + } }