(graphs: Array<{
name: string;
id: string;
enable?: boolean;
updateTime?: number;
}>)
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return lines.join("\n"); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * 处理错误信息 |
| 150 | */ |
| 151 | export function handleError(error: unknown, context: string): string { |
| 152 | const msg = error instanceof Error ? error.message : String(error); |
| 153 | if (msg.includes("timeout")) { |
| 154 | return `Error: 请求超时。请检查网关连接或网络状态。(${context})`; |
| 155 | } |
| 156 | if (msg.includes("not connected") || msg.includes("未连接")) { |
| 157 | return `Error: 网关未连接。请先调用 mijia_auth 进行认证。(${context})`; |
| 158 | } |
| 159 | return `Error: ${msg} (${context})`; |
| 160 | } |
| 161 | |
| 162 | const onlineTag = (online?: boolean): string => (online ? "[在线]" : "[离线]"); |
| 163 | const enableTag = (enable?: boolean): string => (enable ? "[启用]" : "[禁用]"); |
| 164 | |
| 165 | // ==================== 设备 ==================== |
| 166 | |
| 167 | /** |
| 168 | * 格式化设备列表为 Markdown(每台设备一行) |
| 169 | */ |
| 170 | export function formatDeviceListMarkdown(devices: Array<{ |
| 171 | name: string; |
| 172 | did: string; |
| 173 | modelName?: string; |
| 174 | online?: boolean; |
| 175 | roomName?: string; |
| 176 | }>, count: number): string { |
| 177 | const lines = [`## 设备列表(${count} 台)`]; |
| 178 | for (const device of devices) { |
| 179 | lines.push(`- ${device.name} (${device.did}) | ${device.roomName || "未分组"} | ${device.modelName || "未知"} | ${onlineTag(device.online)}`); |
no outgoing calls
no test coverage detected