sesame-kit 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +106 -73
- package/README.md +76 -43
- package/clients/js/sesame-client.mjs +2 -2
- package/clients/python/__pycache__/sesame_client.cpython-313.pyc +0 -0
- package/clients/python/sesame_client.py +2 -2
- package/docs/{architecture.md → en/architecture.md} +7 -7
- package/docs/en/ble.md +65 -0
- package/docs/{commands.md → en/commands.md} +26 -11
- package/docs/en/index.md +20 -0
- package/docs/en/integration.md +181 -0
- package/docs/{library.md → en/library.md} +6 -5
- package/docs/en/migration.md +13 -0
- package/docs/en/quickstart.md +51 -0
- package/docs/{architecture.ja.md → ja/architecture.md} +37 -37
- package/docs/ja/ble.md +65 -0
- package/docs/{commands.ja.md → ja/commands.md} +54 -39
- package/docs/ja/index.md +20 -0
- package/docs/ja/integration.md +181 -0
- package/docs/{library.ja.md → ja/library.md} +6 -5
- package/docs/ja/migration.md +13 -0
- package/docs/ja/quickstart.md +51 -0
- package/package.json +4 -1
- package/src/cli/serve.js +1 -1
- package/src/cli.js +9 -9
- package/src/client.js +2 -2
- package/src/config.js +1 -1
- package/src/paths.js +5 -5
- package/src/tokens.js +1 -1
- package/types/client.d.ts +1 -1
- package/docs/migration.ja.md +0 -13
- package/docs/migration.md +0 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<!-- English | [日本語](
|
|
1
|
+
<!-- English | [日本語](../ja/architecture.md) -->
|
|
2
2
|
|
|
3
3
|
# Architecture / Design Notes
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> [日本語](../ja/architecture.md) · [Docs index](./index.md)
|
|
6
6
|
|
|
7
7
|
This document covers the lineage of the implementation, the design decisions, and the file layout. The README covers usage; this covers why things are the way they are.
|
|
8
8
|
|
|
@@ -19,14 +19,14 @@ This implementation is a Node.js port of the **official biz3 admin web app (http
|
|
|
19
19
|
| `src/devices.js` | `references_web/src/api/useManageDevice.js` / `useManageGroup.js` / `useDeveloper.js` / `MobileBatteryChart.js` |
|
|
20
20
|
| `src/crypto.js` | `references_web/src/utils/Cmac.js` + `biz3utils.js` + `constants/cmdCode.js` (CMAC implemented with `node-aes-cmac`) |
|
|
21
21
|
|
|
22
|
-
**The only functional difference from biz3**: the Cognito Client ID is swapped from biz3's `21u50hboia4s5q0sbk6pbdfmss` to the same Consumer Client as the official iOS/Android apps, `6ialca0p8u0lsgvbmvsljfm305`. This keeps the refreshToken from effectively expiring. The biz3 MIT license text is bundled as [LICENSE.biz3](
|
|
22
|
+
**The only functional difference from biz3**: the Cognito Client ID is swapped from biz3's `21u50hboia4s5q0sbk6pbdfmss` to the same Consumer Client as the official iOS/Android apps, `6ialca0p8u0lsgvbmvsljfm305`. This keeps the refreshToken from effectively expiring. The biz3 MIT license text is bundled as [LICENSE.biz3](../../LICENSE.biz3).
|
|
23
23
|
|
|
24
24
|
## Unified cloud / BLE design (the route is the leaf)
|
|
25
25
|
|
|
26
26
|
Like the official SesameSDK, cloud and BLE **share the underlying command (itemCode) and the device capability model**; only the final send route (transport) is swapped as a leaf. This is a single design.
|
|
27
27
|
|
|
28
|
-
- itemCode has one source in `src/itemcodes.js` (the cloud refers to it as `CMD` in `crypto.js`, BLE as `ITEM` in `protocol.js` — different aliases for the same thing).
|
|
29
|
-
- Capability is held by `devicemodel.js` as **type × route** (each kind has a `cloud:[...]` and a `ble:[...]` op set).
|
|
28
|
+
- itemCode has one source in `src/itemcodes.js` (the cloud refers to it as `CMD` in `src/crypto.js`, BLE as `ITEM` in `src/ble/protocol.js` — different aliases for the same thing).
|
|
29
|
+
- Capability is held by `src/ble/devicemodel.js` as **type × route** (each kind has a `cloud:[...]` and a `ble:[...]` op set).
|
|
30
30
|
The **operable ops = the union of the two**, and the session's targets, operation menu, and `pickTransport` route selection are all derived from this union.
|
|
31
31
|
- Example: a lock has autolock under `ble` but not `cloud` → autolock is BLE-only.
|
|
32
32
|
- An OS2 lock has an empty `ble` set and lock/unlock/toggle under `cloud` → operable via cloud only.
|
|
@@ -55,7 +55,7 @@ The protocol layer (`src/ble/protocol.js`: CMAC session key / AES-CCM / segments
|
|
|
55
55
|
|
|
56
56
|
## `sesame serve` language-agnostic backend
|
|
57
57
|
|
|
58
|
-
With 1 core + 5 framings, the full feature set is uniformly exposed on a single resident `SesameHub3`. See the README's [language-agnostic backend](
|
|
58
|
+
With 1 core + 5 framings, the full feature set is uniformly exposed on a single resident `SesameHub3`. See the README's [language-agnostic backend](../../README.md#language-agnostic-backend-sesame-serve) for details.
|
|
59
59
|
|
|
60
60
|
- **Core**: `src/serve/jsonrpc.js` (JSON-RPC 2.0, transport-independent) + `registry.js` (auto-exposes methods from `NAMESPACE_OPS` + OpenRPC) + `daemon.js` (serialization / unified subscription / backpressure / shutdown).
|
|
61
61
|
- **Framing**: stdio / socket(UDS) / http(+SSE) / ws / grpc + token under `framing/`.
|
|
@@ -99,7 +99,7 @@ sesame-kit/
|
|
|
99
99
|
│ ├── transport.js # noble adapter (optionalDependency, lazy require)
|
|
100
100
|
│ └── index.js # SesameBle facade
|
|
101
101
|
├── iot.js / account.js / schedule.js / org.js / company.js / access.js / devices.js
|
|
102
|
-
├── config.js # ConfigStore (~/.config/sesame-
|
|
102
|
+
├── config.js # ConfigStore (~/.config/sesame-kit/config.json)
|
|
103
103
|
├── tokens.js # FileTokenStore
|
|
104
104
|
└── paths.js # config directory resolution
|
|
105
105
|
```
|
package/docs/en/ble.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!-- English | [日本語](../ja/ble.md) -->
|
|
2
|
+
|
|
3
|
+
# BLE direct control
|
|
4
|
+
|
|
5
|
+
> [日本語](../ja/ble.md) · [Docs index](./index.md)
|
|
6
|
+
|
|
7
|
+
Drive a registered SESAME directly over Bluetooth from your PC, without going through the cloud. It works offline, and **settings such as autolock — which the cloud cannot change — take effect on the device over BLE**. No sign-in is required for BLE-only operation.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
BLE control is not a separate command — add `--ble-only` to the device operation (`autolock` requires BLE, so it uses BLE even without the flag):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
sesame front status --ble-only # current state (locked / unlocked, position)
|
|
15
|
+
sesame front unlock --ble-only # unlock (lock / Bike)
|
|
16
|
+
sesame front lock --ble-only # lock
|
|
17
|
+
sesame front toggle --ble-only # toggle based on current state
|
|
18
|
+
sesame kitchen click --ble-only # SESAME Bot click (Bot2 / Bot3)
|
|
19
|
+
sesame front autolock 30 # autolock (BLE required; actually takes effect)
|
|
20
|
+
sesame front autolock 0 # disable
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Without `--ble-only`, the route (cloud / BLE) is chosen automatically; `--cloud-only` pins it to the cloud.
|
|
24
|
+
|
|
25
|
+
## Capabilities by device type (follows the official SesameSDK)
|
|
26
|
+
|
|
27
|
+
The operation set differs by device type. The official SDK defines capabilities asymmetrically per type, and this CLI reproduces that from the `model` in your config. Unsupported operations are rejected (e.g. `lock` on a Bot → "use click").
|
|
28
|
+
|
|
29
|
+
| Type (example model) | BLE operations | mechStatus |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| Lock `sesame_5` / `_pro` / `sesame_6` / `_pro` / `_us` / `miwa` | `lock` `unlock` `toggle` `autolock` `status` | locked / unlocked + position |
|
|
32
|
+
| Bot `bot_2` / `bot_3` | `click` `status` | locked / unlocked (no position) |
|
|
33
|
+
| Bike `bike_2` / `bike_3` | `unlock` `status` | locked / unlocked (no position) |
|
|
34
|
+
| Touch / Face / Sensor / Remote, Hub3, WiFiModule2 | (no BLE lock operation) | — |
|
|
35
|
+
| OS2 `sesame_2` / `_4`, `ssmbot_1`, `bike_1` | BLE not implemented (different key derivation / crypto). Operate via the cloud | — |
|
|
36
|
+
|
|
37
|
+
> On OS3, "locked / unlocked" is a 2-state value based on `isInLockRange` only; there is no intermediate (moved) state (only OS2 devices like Sesame2 have it).
|
|
38
|
+
|
|
39
|
+
## Error codes
|
|
40
|
+
|
|
41
|
+
When a device returns a non-zero result, the library throws `BleResultError` (`.resultCode` / `.resultName`). `resultName` matches the official SesameSDK `SesameResultCode` (`success` / `invalidFormat` / `notSupported` / `invalidSig` / `notFound` / `unknown` / `busy` / `invalidParam` / `invalidAction`), so you can branch on it.
|
|
42
|
+
|
|
43
|
+
This is the device-layer (SesameOS3) taxonomy and is only available over BLE; the cloud path does not surface these codes, so they do not appear in `sesame serve`'s `kind`.
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- The BLE adapter `@abandonware/noble`. It is an `optionalDependency`, so `npm install` attempts it automatically and the install does not break on unsupported platforms (BLE is simply disabled). Install manually with `npm i @abandonware/noble`.
|
|
48
|
+
- **macOS requires Bluetooth permission for the terminal** (System Settings → Privacy & Security → Bluetooth). This is an OS-level permission, unavoidable with any BLE implementation.
|
|
49
|
+
- Be within Bluetooth range of the lock.
|
|
50
|
+
|
|
51
|
+
## As a library
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { SesameBle } from "sesame-kit"; // or: import { ble } from "sesame-kit"
|
|
55
|
+
|
|
56
|
+
await SesameBle.use({ deviceUUID, secretKey }, async (lock) => {
|
|
57
|
+
await lock.unlock();
|
|
58
|
+
await lock.autolock(30);
|
|
59
|
+
console.log(lock.lastStatus); // { state, isInLockRange, position, batteryRaw, ... } (batteryRaw = voltage ADC raw, not mV)
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Scope
|
|
64
|
+
|
|
65
|
+
Targets **SesameOS3** (SESAME 5 / 5 Pro / Touch, etc.). New pairing (registering an unregistered device) is not supported; only operating already-registered devices. See the design notes in [architecture.md](./architecture.md).
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<!-- English | [日本語](
|
|
1
|
+
<!-- English | [日本語](../ja/commands.md) -->
|
|
2
2
|
|
|
3
3
|
# Command Reference
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> [日本語](../ja/commands.md) · [Docs index](./index.md)
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
> When calling from another language via `sesame serve`, `sesame rpc` (or `rpc.discover`)
|
|
7
|
+
> The CLI commands, grouped by area. Each subcommand also accepts `sesame <cmd> --help` for its full options.
|
|
8
|
+
> When calling from another language via `sesame serve`, `sesame rpc` (or `rpc.discover`) lists every method and its parameters, machine-readably.
|
|
9
9
|
|
|
10
10
|
## Device operations (device as the subject)
|
|
11
11
|
|
|
@@ -26,14 +26,14 @@ sesame # interactive menu for all devices (session)
|
|
|
26
26
|
|
|
27
27
|
action: `unlock` / `lock` / `toggle` / `click` / `status` / `autolock <seconds>` (**which operations apply depends on the type** — see below).
|
|
28
28
|
|
|
29
|
-
### The route (transport) defaults to
|
|
29
|
+
### The route (transport) defaults to auto
|
|
30
30
|
|
|
31
|
-
- The default is
|
|
31
|
+
- The default is auto; the route is chosen automatically. Ops that the cloud can carry go over cloud, and only BLE-required ops such as `autolock` open a BLE connection (so you don't pay the BLE scan/connect cost every time).
|
|
32
32
|
- Pin the route with `--ble-only` / `--cloud-only`. `--ble-only` takes a few seconds to connect. `--cloud-only` restricts some operations.
|
|
33
33
|
- To hold a BLE connection open across a run of operations, use `sesame session` (the multi-device form of `sesame <device>`).
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
sesame front unlock #
|
|
36
|
+
sesame front unlock # auto (the tool picks the route)
|
|
37
37
|
sesame front autolock 30 # BLE-required op → connects over BLE automatically
|
|
38
38
|
sesame front lock --ble-only # pinned to BLE (a few seconds to connect)
|
|
39
39
|
sesame front lock --cloud-only # pinned to cloud
|
|
@@ -54,7 +54,7 @@ sesame locks rm front
|
|
|
54
54
|
|
|
55
55
|
A cloud operation returns only after the synchronous ack (`biz3TriggerLocker`, `success:true`) arrives (timeout 10s).
|
|
56
56
|
|
|
57
|
-
> autolock cannot be set over the cloud (BLE only). Use `sesame autolock
|
|
57
|
+
> autolock cannot be set over the cloud (BLE only). Use `sesame <device> autolock <seconds>` (e.g. `sesame front autolock 30`, `0` = off). Background in [architecture.md](./architecture.md).
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
@@ -95,6 +95,19 @@ sesame ir match ac <hex波形> # match a learned waveform against know
|
|
|
95
95
|
|
|
96
96
|
> To refer to a self-learned remote, use the real type `0xFE00` (65024) for `irType`. Passing the menu id `0xFEFF` makes the server match fail and the remote is not found. See [architecture.md](./architecture.md) for details.
|
|
97
97
|
|
|
98
|
+
### Register remotes and the Hub3
|
|
99
|
+
|
|
100
|
+
`send` / `ir learn` need a remote (and its Hub3) imported into config first. The fastest path is to sync everything from the server:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
sesame hub3 sync-from-devices # import your Hub3(s)
|
|
104
|
+
sesame remote sync-from-devices # import remotes (Hub3 + irType auto-detected) and their keys
|
|
105
|
+
sesame remote ls # list configured remotes
|
|
106
|
+
sesame remote set-default ac # default remote used by a bare `sesame send <key>`
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Or add one at a time: `sesame hub3 add` / `sesame remote add` both pick from a list (no UUID/irType to type). `sesame remote sync-keys [name]` re-imports a remote's key list.
|
|
110
|
+
|
|
98
111
|
---
|
|
99
112
|
|
|
100
113
|
## Device management
|
|
@@ -198,13 +211,15 @@ Direct commands to the Hub3 itself (LED dimming, LTE relay, firmware update, Mat
|
|
|
198
211
|
Pass `--device <hub3UUID> --secret <hex>`, or select from connected devices when interactive.
|
|
199
212
|
|
|
200
213
|
```bash
|
|
201
|
-
sesame iot led 80 --device <uuid> --secret <hex> # LED dimming (0-
|
|
214
|
+
sesame iot led 80 --device <uuid> --secret <hex> # LED dimming (duty 0-255)
|
|
202
215
|
sesame iot led --get --device <uuid> --secret <hex># get the current dimming level
|
|
203
216
|
sesame iot relay on --device <uuid> --secret <hex># LTE relay open/close
|
|
204
217
|
sesame iot firmware-update --device <uuid> --secret <hex> --wait 60
|
|
205
218
|
sesame iot matter-code --device <uuid> --secret <hex> # Matter pairing code
|
|
206
219
|
```
|
|
207
220
|
|
|
221
|
+
> `relay` is fire-and-forget: the Hub3 sends no acknowledgement, so a successful send is not a confirmed switch. The `off` opcode mapping is unverified against the official source and may behave differently on real hardware.
|
|
222
|
+
|
|
208
223
|
---
|
|
209
224
|
|
|
210
225
|
## Preset IR remotes (HXD command)
|
|
@@ -218,7 +233,7 @@ sesame preset-ir send --device <hub3uuid> --command <hex> --irtype 49152 # emi
|
|
|
218
233
|
```
|
|
219
234
|
|
|
220
235
|
> Preset command generation (biz3's HXDCommandProcessor) is not yet ported, so preset emit does not currently work.
|
|
221
|
-
> Use a self-learned remote (`sesame ir learn`) instead ([known limitations](
|
|
236
|
+
> Use a self-learned remote (`sesame ir learn`) instead ([known limitations](../../README.md#known-limitations)).
|
|
222
237
|
|
|
223
238
|
---
|
|
224
239
|
|
|
@@ -278,7 +293,7 @@ await SesameBle.use({ deviceUUID, secretKey }, async (lock) => {
|
|
|
278
293
|
|
|
279
294
|
## Interactive session
|
|
280
295
|
|
|
281
|
-
The interactive session (`sesame` / `sesame <device>` / `sesame session`) is an **app-like
|
|
296
|
+
The interactive session (`sesame` / `sesame <device>` / `sesame session`) is an **app-like auto**.
|
|
282
297
|
It lists **every device you can operate**: Locks/Bots/Bikes (BLE + cloud) and, if you are logged in, **Hub3** (cloud: IR send / relay / LED).
|
|
283
298
|
It attaches BLE best-effort but **does not exit even when BLE is zero**: devices out of range or without permission are **operated over cloud** when you are logged in (devices with a BLE connection prefer BLE = lower latency + autolock available).
|
|
284
299
|
|
package/docs/en/index.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- English | [日本語](../ja/index.md) -->
|
|
2
|
+
|
|
3
|
+
# sesame-kit documentation
|
|
4
|
+
|
|
5
|
+
> [日本語](../ja/index.md) · [← Back to README](../../README.md)
|
|
6
|
+
|
|
7
|
+
Pick the guide for how you want to use sesame-kit.
|
|
8
|
+
|
|
9
|
+
## Getting started
|
|
10
|
+
- [Quickstart](./quickstart.md) — install, sign in, and open a lock in a few minutes.
|
|
11
|
+
|
|
12
|
+
## Guides (by usage)
|
|
13
|
+
- [CLI](./commands.md) — full command reference for the `sesame` CLI.
|
|
14
|
+
- [BLE direct control](./ble.md) — drive locks over Bluetooth without the cloud (autolock, permissions, per-device capabilities).
|
|
15
|
+
- [Node library](./library.md) — embed sesame-kit in a Node.js app (`SesameHub3.use()`, direct API, events).
|
|
16
|
+
- [Integrate from any language](./integration.md) — call every feature over JSON-RPC via `sesame serve` (Python / JS / HTTP / WebSocket / gRPC).
|
|
17
|
+
|
|
18
|
+
## Reference & design
|
|
19
|
+
- [Architecture](./architecture.md) — lineage, design decisions, file layout.
|
|
20
|
+
- [Migration](./migration.md) — upgrading from older versions.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<!-- English | [日本語](../ja/integration.md) -->
|
|
2
|
+
|
|
3
|
+
# Integrate from any language (`sesame serve`)
|
|
4
|
+
|
|
5
|
+
> [日本語](../ja/integration.md) · [Docs index](./index.md)
|
|
6
|
+
|
|
7
|
+
`sesame serve` is a long-running JSON-RPC 2.0 daemon. It signs in once, keeps the cloud connection alive, and runs operations and pushes events repeatedly. Every feature is callable from any language.
|
|
8
|
+
|
|
9
|
+
## 1. Sign in and start the daemon
|
|
10
|
+
|
|
11
|
+
The daemon uses your stored login — it does not sign in itself. Sign in once with the CLI, then start the daemon.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
sesame login your@email.com && sesame verify # if not already signed in
|
|
15
|
+
sesame serve --http 8080 # serve over HTTP on port 8080
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The daemon prints a token at startup (also saved to `~/.config/sesame-kit/serve.token`). Every HTTP request must send `Authorization: Bearer <token>`.
|
|
19
|
+
|
|
20
|
+
> For same-machine use, `sesame serve` with no flags listens on a Unix socket and needs no token. HTTP is used here because it works from any language and any machine.
|
|
21
|
+
|
|
22
|
+
## 2. Your first call — no library to install
|
|
23
|
+
|
|
24
|
+
It is plain JSON-RPC over HTTP. Anything that can POST works.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
TOKEN=... # the token printed by `sesame serve`
|
|
28
|
+
|
|
29
|
+
curl -s -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" \
|
|
30
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"lock.unlock","params":{"name":"front"}}' \
|
|
31
|
+
http://127.0.0.1:8080/rpc
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The same in Python, using only the standard library (no pip install):
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import json, urllib.request
|
|
38
|
+
|
|
39
|
+
TOKEN = "..." # the token printed by `sesame serve`
|
|
40
|
+
|
|
41
|
+
def rpc(method, params=None):
|
|
42
|
+
body = json.dumps({"jsonrpc": "2.0", "id": 1, "method": method, "params": params or {}}).encode()
|
|
43
|
+
req = urllib.request.Request("http://127.0.0.1:8080/rpc", data=body,
|
|
44
|
+
headers={"content-type": "application/json", "authorization": f"Bearer {TOKEN}"})
|
|
45
|
+
return json.load(urllib.request.urlopen(req))
|
|
46
|
+
|
|
47
|
+
print(rpc("status"))
|
|
48
|
+
print(rpc("lock.unlock", {"name": "front"}))
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
A response is `{"jsonrpc":"2.0","id":1,"result": ...}` on success, or `{"jsonrpc":"2.0","id":1,"error":{"code","message","data":{"kind"}}}` on failure.
|
|
52
|
+
|
|
53
|
+
## 3. Finding the method and the values to pass
|
|
54
|
+
|
|
55
|
+
`sesame rpc` lists every method with its parameters (required shown plain, optional in `[brackets]`):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
sesame rpc
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
lock.unlock [name] [deviceUUID] [secretKey]
|
|
63
|
+
lock.status deviceUUID
|
|
64
|
+
devices.list
|
|
65
|
+
device.history deviceUUID [pageSize]
|
|
66
|
+
ir.send [remote] key
|
|
67
|
+
org.getEmployees companyID
|
|
68
|
+
…
|
|
69
|
+
79 methods.
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Read the line for the method you want. Each line is `method <required> [optional]`. For example, `device.history deviceUUID [pageSize]` means **`deviceUUID` is required and `pageSize` is optional**.
|
|
73
|
+
|
|
74
|
+
Then fill each parameter with a **value**. Values come from one of two places:
|
|
75
|
+
|
|
76
|
+
- **IDs** (`deviceUUID`, `companyID`, …) are returned by another list method. For a `deviceUUID`, take one from `devices.list`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
sesame rpc devices.list
|
|
80
|
+
# → [{"deviceUUID":"AB12CD34...","deviceName":"front", ...}, ...]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- **Values you choose** (`pageSize`, `name`, …) are optional and up to you. `pageSize` is the number of records.
|
|
84
|
+
|
|
85
|
+
Put the values in the `--params` JSON and call it:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
sesame rpc device.history --params '{"deviceUUID":"AB12CD34...","pageSize":10}'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The **method name and params you settle on here are exactly what you send from any client** (the `method` / `params` fields of the call in section 2).
|
|
92
|
+
|
|
93
|
+
> Lock ops also accept a config name instead of a `deviceUUID` — `{"name":"front"}` works for `lock.unlock` / `lock.lock` / `lock.toggle` / `lock.click`. (`lock.status` takes a `deviceUUID`.)
|
|
94
|
+
|
|
95
|
+
For exact parameter types (e.g. for code generation), `sesame rpc --json rpc.discover` returns the full OpenRPC document. Each method entry carries its param types:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"name": "device.history",
|
|
100
|
+
"params": [
|
|
101
|
+
{ "name": "deviceUUID", "required": true, "schema": { "type": "string" } },
|
|
102
|
+
{ "name": "pageSize", "required": false, "schema": { "type": "number" } }
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 4. Bundled clients (optional)
|
|
108
|
+
|
|
109
|
+
Thin clients wrap the above so you write `c.unlock("front")` instead of building JSON by hand. They are optional — section 2 already works without them.
|
|
110
|
+
|
|
111
|
+
**Node** — after `npm install sesame-kit`:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import { SesameClient } from "sesame-kit/client";
|
|
115
|
+
|
|
116
|
+
const c = SesameClient.unix(); // default Unix socket
|
|
117
|
+
console.log(await c.unlock("front")); // convenience method
|
|
118
|
+
console.log(await c.call("device.history", { deviceUUID: "AB12CD34...", pageSize: 10 })); // any method
|
|
119
|
+
console.log((await c.discover()).methods.map((m) => m.name)); // list methods from JS
|
|
120
|
+
await c.subscribe(["lockState"], (topic, p) => console.log(topic, p)); // always await
|
|
121
|
+
|
|
122
|
+
// const h = SesameClient.http("http://127.0.0.1:8080"); // token auto-read from serve.token
|
|
123
|
+
// const w = await SesameClient.ws("ws://127.0.0.1:8081"); // npm i ws for header auth
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Python** — the client is a single file shipped with the package:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install ./clients/python # from a cloned repo
|
|
130
|
+
pip install "$(npm root -g)/sesame-kit/clients/python" # from a global `npm install -g sesame-kit`
|
|
131
|
+
```
|
|
132
|
+
```python
|
|
133
|
+
from sesame_client import SesameClient
|
|
134
|
+
|
|
135
|
+
c = SesameClient.unix() # default Unix socket
|
|
136
|
+
print(c.unlock("front")) # convenience method
|
|
137
|
+
print(c.call("device.history", deviceUUID="AB12CD34...", pageSize=10)) # any method
|
|
138
|
+
print(c.discover_names()) # list methods from Python
|
|
139
|
+
c.subscribe(["lockState"], lambda topic, payload: print(topic, payload))
|
|
140
|
+
# HTTP: SesameClient.http("http://127.0.0.1:8080") / embedded: SesameClient.stdio()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Transports (framings)
|
|
144
|
+
|
|
145
|
+
The same methods are available over five transports. Use HTTP/WS/gRPC for network access, the Unix socket or stdio for the local machine.
|
|
146
|
+
|
|
147
|
+
| Framing | Use | Events | Auth |
|
|
148
|
+
|---|---|---|---|
|
|
149
|
+
| stdio | embedded (child process) | `event.*` notifications | inherits parent trust |
|
|
150
|
+
| Unix socket | local daemon, multiple clients | `event.*` notifications | file permission 0600 |
|
|
151
|
+
| HTTP | any language / browser | `GET /events` (SSE) | `Authorization: Bearer <token>` |
|
|
152
|
+
| WebSocket | any language / browser (full-duplex) | `event.*` notifications | token |
|
|
153
|
+
| gRPC | typed stubs for many languages | `Subscribe` stream | token (metadata) |
|
|
154
|
+
|
|
155
|
+
gRPC is typed: `src/serve/sesame.proto` has a typed method per op. Generate stubs with
|
|
156
|
+
`python -m grpc_tools.protoc -I src/serve --python_out=. --grpc_python_out=. src/serve/sesame.proto`.
|
|
157
|
+
Scalar/array params are protobuf-typed; dynamic params are a JSON-string field; responses are `JsonRpc{json}`. Ops without a typed method use the generic `Invoke`.
|
|
158
|
+
|
|
159
|
+
## Events
|
|
160
|
+
|
|
161
|
+
```jsonc
|
|
162
|
+
// request (over Unix socket / WebSocket / stdio):
|
|
163
|
+
{"jsonrpc":"2.0","id":1,"method":"events.subscribe","params":{"topics":["lockState","deviceUpdate"]}}
|
|
164
|
+
// then notifications arrive (no id):
|
|
165
|
+
{"jsonrpc":"2.0","method":"event.lockState","params":{ /* state */ }}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Topics: `lockState`, `deviceUpdate`. Over HTTP use `GET /events?topics=…` (SSE); over gRPC use the `Subscribe` stream. `POST /rpc` and gRPC `Invoke` are request/response only and reject `events.*`.
|
|
169
|
+
|
|
170
|
+
## Errors
|
|
171
|
+
|
|
172
|
+
Errors are `{error:{code, message, data:{kind}}}`. `kind` is one of:
|
|
173
|
+
`not_authenticated` (sign in via the CLI, then restart the daemon) / `connection_lost` (cloud connection down) / `timeout` / `bad_params` / `not_implemented` (unknown method) / `internal` (anything else; details in `message`).
|
|
174
|
+
|
|
175
|
+
## Compatibility
|
|
176
|
+
|
|
177
|
+
The result shape is method-specific. To check compatibility, read the contract version: `status` returns `contractVersion`, and `rpc.discover` returns `info["x-contractVersion"]`. It is a SemVer for the machine contract; only breaking changes bump the major.
|
|
178
|
+
|
|
179
|
+
## Security boundary
|
|
180
|
+
|
|
181
|
+
Interactive login is CLI-only and never runs in the daemon. A Unix socket can be used by any process of the same user (the same boundary as the CLI). HTTP / WS / gRPC are over TCP and require a loopback token generated at startup. They are plaintext (no TLS); expose them over loopback only, or tunnel via SSH / a TLS reverse proxy. POSIX only (Windows UDS is out of scope; stdio / HTTP / WS / gRPC work).
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<!-- English | [日本語](
|
|
1
|
+
<!-- English | [日本語](../ja/library.md) -->
|
|
2
2
|
|
|
3
3
|
# Using sesame-kit as a library
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> [日本語](../ja/library.md) · [Docs index](./index.md)
|
|
6
6
|
|
|
7
|
-
The same features as the `sesame` CLI can be called directly from Node.js. To use it from other languages, use [`sesame serve`](
|
|
7
|
+
The same features as the `sesame` CLI can be called directly from Node.js. To use it from other languages, use [`sesame serve`](../../README.md#language-agnostic-backend-sesame-serve); to use it inside Node, use this.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## `use()` helper (auto connect/close)
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
import { SesameHub3 } from "sesame-kit";
|
|
@@ -53,10 +53,11 @@ await SesameHub3.use(async (hub) => {
|
|
|
53
53
|
await hub.lockDevice({ deviceUUID, secretKey });
|
|
54
54
|
await hub.toggleDevice({ deviceUUID, secretKey });
|
|
55
55
|
await hub.botClickDevice({ deviceUUID, secretKey });
|
|
56
|
-
await hub.triggerLockDevice({ deviceUUID, secretKey, cmd: 83 }); //
|
|
56
|
+
await hub.triggerLockDevice({ deviceUUID, secretKey, cmd: 83 }); // raw itemCode: 83=unlock, 82=lock, 88=toggle, 89=click
|
|
57
57
|
|
|
58
58
|
// IR
|
|
59
59
|
await hub.sendIRDirect({
|
|
60
|
+
// irType selects the remote category: 49152 (0xC000)=air-conditioner, 8192=TV, 32768=fan, 57344=light
|
|
60
61
|
hub3DeviceId, irDeviceUUID, irType: 49152, command: keyUUID, operation: "learnEmit",
|
|
61
62
|
});
|
|
62
63
|
const keys = await hub.getIRCodesDirect({ hub3DeviceId, irDeviceUUID });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- English | [日本語](../ja/migration.md) -->
|
|
2
|
+
|
|
3
|
+
# Migrating from older versions
|
|
4
|
+
|
|
5
|
+
> [日本語](../ja/migration.md) · [Docs index](./index.md)
|
|
6
|
+
|
|
7
|
+
Upgrading from the old `sesame-hub3` (CLI = `hub3-ir`):
|
|
8
|
+
|
|
9
|
+
- The CLI is renamed to `sesame` (the old `hub3-ir` is removed). Replace it in any shell scripts.
|
|
10
|
+
- Config and tokens are stored in `~/.config/sesame-kit`.
|
|
11
|
+
- Config is now stored under a single `devices` map; `locks` is a derived view rebuilt on each load, not a stored key. Populate `devices` from the server with `sesame locks sync-from-devices`.
|
|
12
|
+
|
|
13
|
+
Migrating from an old `.env` + `.tokens.json` + `keys.json` works with `sesame migrate`.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<!-- English | [日本語](../ja/quickstart.md) -->
|
|
2
|
+
|
|
3
|
+
# Quickstart
|
|
4
|
+
|
|
5
|
+
> [日本語](../ja/quickstart.md) · [Docs index](./index.md)
|
|
6
|
+
|
|
7
|
+
Open a lock from the command line in a few minutes.
|
|
8
|
+
|
|
9
|
+
## 1. Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g sesame-kit # global CLI: `sesame ...`
|
|
13
|
+
# or without installing: npx sesame-kit ...
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Requires Node.js 18+.
|
|
17
|
+
|
|
18
|
+
## 2. Sign in
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
sesame init # create ~/.config/sesame-kit/ (first run only)
|
|
22
|
+
sesame login your@email.com # sends a verification code to your email
|
|
23
|
+
sesame verify # enter the code
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`verify` imports your devices together with their keys, so you can control them right away.
|
|
27
|
+
|
|
28
|
+
## 3. Control a lock
|
|
29
|
+
|
|
30
|
+
Run `sesame` for the interactive menu. It lists your devices and the actions each supports.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
sesame # ↑↓ move · → (or Enter) confirm · ← (or Esc) back · q quit
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or run an action directly. The subject is the device: `sesame <device> <action>` (substring match).
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
sesame front status # current state (locked / unlocked)
|
|
40
|
+
sesame front unlock # unlock
|
|
41
|
+
sesame front lock # lock
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Next steps
|
|
45
|
+
|
|
46
|
+
- All CLI commands: [CLI reference](./commands.md)
|
|
47
|
+
- Operate over Bluetooth without the cloud: [BLE direct control](./ble.md)
|
|
48
|
+
- Call from another language: [Integrate via `sesame serve`](./integration.md)
|
|
49
|
+
- Use it from Node code: [Node library](./library.md)
|
|
50
|
+
|
|
51
|
+
> Cloud control needs sign-in. BLE-only control works without sign-in — see [BLE direct control](./ble.md).
|