diff --git a/assistant/src/routes/ha-api/ha.ts b/assistant/src/routes/ha-api/ha.ts deleted file mode 100644 index 270ed08..0000000 --- a/assistant/src/routes/ha-api/ha.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { LightHA } from "@kevisual/ha-api"; -export const lightHA = new LightHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL }); - -export const callText = async (text: string) => { - const command = text?.trim().slice(0, 20); - type ParseCommand = { - type?: '打开' | '关闭', - appName?: string, - command?: string, - } - let obj: ParseCommand = {}; - if (command.startsWith('打开')) { - obj.appName = command.replace('打开', '').trim(); - obj.type = '打开'; - } else if (command.startsWith('关闭')) { - obj.appName = command.replace('关闭', '').trim(); - obj.type = '关闭'; - } - let endTime = Date.now(); - if (obj.type) { - try { - const search = await lightHA.searchLight(obj.appName || ''); - console.log('searchTime', Date.now() - endTime); - if (search.id) { - await lightHA.runService({ entity_id: search.id, service: obj.type === '打开' ? 'turn_on' : 'turn_off' }); - } else if (search.hasMore) { - const [first] = search.result; - await lightHA.runService({ entity_id: first.entity_id, service: obj.type === '打开' ? 'turn_on' : 'turn_off' }); - } else { - console.log('未找到对应设备:', obj.appName); - } - console.log('解析到控制指令', obj); - } catch (e) { - console.error('控制失败', e); - } - } -} \ No newline at end of file diff --git a/package.json b/package.json index 079dbf5..be4830e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.0.97", + "version": "0.0.98", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli",