{"id":22413383,"url":"https://github.com/rokid/rokid-homebase-cli","last_synced_at":"2025-03-27T03:27:57.912Z","repository":{"id":65491169,"uuid":"88129339","full_name":"rokid/rokid-homebase-cli","owner":"rokid","description":"Rokid Homebase 命令行工具","archived":false,"fork":false,"pushed_at":"2018-07-23T13:29:41.000Z","size":237,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-25T07:42:18.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rokid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-13T05:45:33.000Z","updated_at":"2020-02-03T07:38:49.000Z","dependencies_parsed_at":"2023-01-25T18:45:25.704Z","dependency_job_id":null,"html_url":"https://github.com/rokid/rokid-homebase-cli","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rokid%2Frokid-homebase-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rokid%2Frokid-homebase-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rokid%2Frokid-homebase-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rokid%2Frokid-homebase-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rokid","download_url":"https://codeload.github.com/rokid/rokid-homebase-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245776257,"owners_count":20670292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T14:12:43.431Z","updated_at":"2025-03-27T03:27:57.892Z","avatar_url":"https://github.com/rokid.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rhome\n\n使用 rhome 工具通过 json schema 来验证 discover|control|report-state 接口的返回值来验证接入 Rokid Homebase 协议。\n\n## 功能\n\n- 调用 discover|control|report-state 接口。\n\n- 使用 jsonschema 对返回的数据格式进行校验，并指出具体错误信息。\n\n- 使用 jsonschema 对 ChangeReport 事件进行校验，并指出具体错误信息。\n\n## 安装\n\n从 [Release](https://github.com/Rokid/rokid-homebase-cli/releases) 页面下载最新的适合你的操作系统的已打包的程序。\n\n## 使用\n\n```bash\n$ rhome -h\n\n  Usage: rhome [options] [command]\n\n  Options:\n\n    -V, --version                               output the version number\n    -v, --verbose                               show raw response body\n    -h, --help                                  output usage information\n\n  Commands:\n\n    add                                         add a session of remote driver\n    del \u003cname\u003e                                  delete the session of remote driver\n    sessions                                    list all added sessions\n    use \u003cname\u003e                                  user an added session\n\n    discover [options]                          list all devices of a driver\n    control [options] \u003cendpointId\u003e \u003cdirective\u003e [value]  execute the device\u003cid\u003e with target action(e.g `Media.TVChannel.Set '{ \"tvChannel\": { \"code\": \"123\" } }'`)\n    report-state [options] \u003cid\u003e                 get current state of a driver\n\n    await-event [options]                       serve an event gateway to await change reports\n```\n\n\n### 步骤 1: 添加 Skill 配置\n\n* `rhome` 运行后，将在用户目录下新建 **rhome.json** 文件，保存 sessions、devices、currentSession 信息。如有必要，开发者可以进行修改。\n* `add` 是交互式命令。 name 必须由 **字母**、**数字** 和 **下划线** 组成。例如: demo_1。 其余为命令行模式。\n* `sessions` 命令显示已添加的所有 session，和显示当前使用的 session。默认使用第一个 session，或通过 `use` 指定。\n\n\n如：\n```bash\n$ rhome add\n\n? remote driver's name demo\n? remote driver's endpoint http://127.0.0.1:3000\n? userId in userAuth. If null, skip\n? userToken in userAuth. If null, skip\n{\n  \"name\": \"demo\",\n  \"endpoint\": \"http://127.0.0.1:3000\",\n  \"userId\": \"\",\n  \"userToken\": \"\"\n}\n```\n\n### 步骤 2: 搜索设备\n\n在控制设备之前，我们需要先获取 Skill 能控制的设备\n\n```bash\n$ rhome discover\n\nid: 0\nsessionName: mimic\nendpointId: device-1\ndisplayName: 大米台灯\ndisplayType: light\noffline: false\n\n```\n\n### 步骤 3: 控制设备\n\n使用 `control \u003cendpointId\u003e \u003cdirective\u003e [payload]` 命令来控制设备，其中 `payload` 为序列化的 JSON 字符串，如 `'{\"value\": 123}'`\n\n```bash\n$ rhome control device-1 Switch.On\n\nid: 0\nsessionName: mimic\nendpointId: device-1\ndisplayName: 大米台灯\ndisplayType: light\noffline: false\n\n```\n\n#### 数据校验\n\n`rhome` 将对返回数据进行校验，并显示具体的错误信息。\n\n* 数据格式正确\n\n```bash\n$ rhome discover\n\nid: 0\nsessionName: demo\ndeviceId: \"e12e2735-5e64-44d3-8ee2-46471f03d182\"\nname: light1\ntype: light\noffline: false\n```\n\n* 数据格式错误\n\n如有错误，将会显示具体的错误信息，以供参考。\n\n```\n$ rhome discover\n\nbody checked by json schema:\ninstance does not match allOf schema [subschema 1] with 2 error[s]:\ninstance.data[0].actions.color[1] is not one of enum values: random,num\ninstance.data[0] requires property \"type\"\n```\n\n### 步骤 4: 发送终端状态变化事件\n\n使用 `await-event` 命令来启动一个本地接收事件的测试服务器，可以使用如 `-p 7001` 的选项来指定服务器端口。\n\n```bash\n$ rhome await-event -p 9999\n\nrhome listening on port 9999\nReceived a change report: {\n  \"header\": {\n    \"messageId\": \"5f8a426e-01e4-4cc9-8b79-65f8bd0fd8a4\",\n    \"namespace\": \"Rokid\",\n    \"name\": \"ChangeReport\",\n    \"payloadVersion\": \"v1\",\n    \"authorization\": {\n      \"type\": \"BearerToken\",\n      \"token\": \"a-token-from-rokid\"\n    }\n  },\n  \"endpoint\": {\n    \"endpointId\": \"0\",\n    \"states\": [\n      {\n        \"interface\": \"Switch\",\n        \"value\": \"On\",\n        \"timeOfSample\": \"2018-03-15T18:00:00.000Z\"\n      }\n    ]\n  },\n  \"payload\": {\n    \"change\": {\n      \"cause\": \"PHYSICAL_INTERACTION\"\n    }\n  }\n}\nCaused by: PHYSICAL_INTERACTION\nsessionName: mimic\nendpointId: 0\ndisplayName: 台灯\ndisplayType: light\noffline: false\nstates:\n  Switch: \"On\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frokid%2Frokid-homebase-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frokid%2Frokid-homebase-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frokid%2Frokid-homebase-cli/lists"}