添加灯光管理、自动化和脚本功能,更新依赖项,完善文档
This commit is contained in:
27
readme.md
Normal file
27
readme.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# 灯光管理
|
||||
|
||||
该模块提供对Home Assistant中灯光设备的管理功能,包括获取灯光列表、搜索特定灯光设备以及控制灯光的开关状态。
|
||||
|
||||
```ts
|
||||
import { haLight } from '@kevisual/ha-api';
|
||||
|
||||
const light = new haLight({
|
||||
host: 'http://your-home-assistant:8123',
|
||||
token: 'your-long-lived-access-token',
|
||||
});
|
||||
// 获取所有灯光设备
|
||||
const lights = await light.getLights();
|
||||
console.log(lights);
|
||||
|
||||
const searchResult = await light.searchLight('living room');
|
||||
console.log(searchResult);
|
||||
|
||||
if(searchResult.hasMore) {
|
||||
console.log('多个灯光设备匹配该关键词,请进一步筛选。');
|
||||
} else if(searchResult.id) {
|
||||
console.log(`唯一匹配的灯光设备ID为: ${searchResult.id}`);
|
||||
light.toggleLight({ entity_id: searchResult.id, service: 'turn_on' });
|
||||
} else {
|
||||
console.log('没有找到匹配的灯光设备。');
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user