本项目提供了 home-assistant-model-context
模块,用于与 Home Assistant 进行交互,实现实体、楼层和区域访问、设备控制等功能,方便开发者进行相关开发。
你可以按照以下步骤快速开始使用本项目:
使用以下命令安装 home-assistant-model-context
:
npm install home-assistant-model-context
const { ModelContext } = require('home-assistant-model-context');
// 初始化模型上下文
async function initializeModel() {
const model = new ModelContext({
host: 'localhost',
port: 8123,
tokenPath: '/config/secrets.yaml'
});
// 获取当前状态
await model.initialize();
const state = await model.getState('light.living_room');
console.log('灯的状态:', state.state);
}
// 执行初始化
initializeModel().catch(console.error);
# 开发模式(带热重载)
npm run dev
# 构建项目
npm run build
# 生产模式
npm run start
# 运行测试
npx jest --config=jest.config.cjs
# 代码格式化
npm run lint
# 生成文档
npm run doc:gen
// config.json
{
"host": "localhost",
"port": 8123,
"token": "your_api_key_here"
}
Node.js 版本(toSorted is not a function)
nvm install 20.10.0
nvm use 20.10.0
连接问题
HASS_HOST
是否可访问设备管理问题
✅ 已完成
🚧 进行中
MIT License
版权所有 (c) 2023, Author 姓名
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.