@7365admin1/core 3.116.0 → 3.117.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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +42 -4
- package/dist/index.js +153 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/padbot-real-data.test.mjs +165 -0
package/package.json
CHANGED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// PadBot S2 in production (2026-09-26): what the first real robot showed and
|
|
2
|
+
// how the adapter now reads it - routes whose stops cannot be placed on the
|
|
3
|
+
// plan are still listed, schedules are said to live in PadBot's app, a
|
|
4
|
+
// positive Wi-Fi number is a level (not dBm), a missing position is said in
|
|
5
|
+
// words, and staff Diagnose returns PadBot's raw answers without credentials.
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { test } from "node:test";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
PADBOT_PATHS,
|
|
12
|
+
asList,
|
|
13
|
+
clearPadbotCache,
|
|
14
|
+
createPadbotAdapter,
|
|
15
|
+
networkText,
|
|
16
|
+
padbotPatrolPlan,
|
|
17
|
+
} from "./.build/services/padbot.adapter.mjs";
|
|
18
|
+
import { normalisePatrolPlan } from "./.build/utils/robot-adapter.util.mjs";
|
|
19
|
+
|
|
20
|
+
const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
|
|
21
|
+
const NOW = Date.parse("2026-09-26T08:00:00.000Z");
|
|
22
|
+
const fresh = new Date(NOW - 5000).toISOString();
|
|
23
|
+
|
|
24
|
+
function fake(routes) {
|
|
25
|
+
const calls = [];
|
|
26
|
+
const fetch = async (url, init) => {
|
|
27
|
+
const path = new URL(url).pathname;
|
|
28
|
+
calls.push({ path, body: JSON.parse(init.body), headers: init.headers });
|
|
29
|
+
const hit = routes[path];
|
|
30
|
+
if (!hit) return { status: 404, text: async () => "" };
|
|
31
|
+
const out = hit(JSON.parse(init.body));
|
|
32
|
+
return { status: 200, text: async () => JSON.stringify(out?.__raw ?? { code: 0, message: "success", data: out ?? null }) };
|
|
33
|
+
};
|
|
34
|
+
return { fetch, calls };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test("network: negative = dBm; zero or positive = a signal level (the real S2 reports 4)", () => {
|
|
38
|
+
assert.equal(networkText({ wifi: { signalStrength: -61 } }), " · Wi-Fi -61 dBm");
|
|
39
|
+
assert.equal(networkText({ wifi: { signalStrength: 4 } }), " · Wi-Fi signal 4");
|
|
40
|
+
assert.equal(networkText({ cellular: { signalStrength: 3 } }), " · Mobile signal 3");
|
|
41
|
+
assert.equal(networkText({}), "");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("routes: stops that cannot be placed are listed by name, the route is kept (not dropped)", () => {
|
|
45
|
+
// Map without resolution: no plan frame, so no stop can be placed.
|
|
46
|
+
const maps = [{ mapId: "m1", floor: 3, targetPoints: [{ targetPointId: "t1", name: "Gate" }, { targetPointId: "t2", name: "Lobby" }] }];
|
|
47
|
+
const paths = [{ pathId: "p1", pathName: "Night round", mapId: "m1", isDefault: true, points: [
|
|
48
|
+
{ targetPointId: "t2", targetPointName: "Lobby", pointIndex: 1 },
|
|
49
|
+
{ targetPointId: "t1", targetPointName: "Gate", pointIndex: 0 },
|
|
50
|
+
] }];
|
|
51
|
+
const plan = normalisePatrolPlan(padbotPatrolPlan(paths, maps, {}));
|
|
52
|
+
assert.equal(plan.routes.length, 1);
|
|
53
|
+
assert.equal(plan.routes[0].name, "Night round (default)");
|
|
54
|
+
assert.deepEqual(plan.routes[0].stops, ["Gate", "Lobby"]);
|
|
55
|
+
assert.deepEqual(plan.routes[0].checkpoints, [], "nothing drawn at a guessed spot");
|
|
56
|
+
assert.equal(plan.routes[0].floorNo, 3);
|
|
57
|
+
assert.equal(plan.scheduleShared, false, "schedules live in PadBot's app");
|
|
58
|
+
assert.deepEqual(plan.schedule, []);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("routes: pointNames when points are absent; a stop found on the robot's OTHER map is placed", () => {
|
|
62
|
+
const frame = { width: 200, height: 100, resolution: 0.05, originX: 0, originY: 0 };
|
|
63
|
+
const maps = [
|
|
64
|
+
{ mapId: "m1", floor: 3, ...frame, targetPoints: [] },
|
|
65
|
+
{ mapId: "m2", floor: 4, ...frame, targetPoints: [{ targetPointId: "a", name: "A", worldX: 1, worldY: 1 }, { targetPointId: "b", name: "B", worldX: 5, worldY: 2.5 }] },
|
|
66
|
+
];
|
|
67
|
+
const byNames = normalisePatrolPlan(padbotPatrolPlan([{ pathId: "p9", pathName: "Loop", mapId: "m1", pointNames: ["A", "B"] }], maps, {}));
|
|
68
|
+
assert.deepEqual(byNames.routes[0].stops, ["A", "B"]);
|
|
69
|
+
assert.equal(byNames.routes[0].checkpoints.length, 2, "found by name on m2 and placed");
|
|
70
|
+
const perPoint = normalisePatrolPlan(padbotPatrolPlan([{ pathId: "p8", pathName: "Cross", mapId: "m1", points: [
|
|
71
|
+
{ targetPointId: "a", targetPointName: "A", mapId: "m2", pointIndex: 0 },
|
|
72
|
+
{ targetPointId: "b", targetPointName: "B", mapId: "m2", pointIndex: 1 },
|
|
73
|
+
] }], maps, {}));
|
|
74
|
+
assert.deepEqual(perPoint.routes[0].checkpoints.map((c) => c.name), ["A", "B"]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("routes: a route with neither placed checkpoints nor stop names is still dropped; demo shape unchanged", () => {
|
|
78
|
+
assert.equal(normalisePatrolPlan({ routes: [{ id: "x", name: "Empty", checkpoints: [] }] }).routes.length, 0);
|
|
79
|
+
const demo = normalisePatrolPlan({ routes: [{ id: "d", name: "Demo", checkpoints: [{ name: "a", x: 1, y: 1 }, { name: "b", x: 2, y: 2 }] }], schedule: [] });
|
|
80
|
+
assert.equal(demo.routes[0].checkpoints.length, 2);
|
|
81
|
+
assert.equal("stops" in demo.routes[0], false);
|
|
82
|
+
assert.equal("scheduleShared" in demo, false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("list answers: bare array or an {items}/{list}/{records} page", () => {
|
|
86
|
+
assert.deepEqual(asList([1]), [1]);
|
|
87
|
+
assert.deepEqual(asList({ items: [2] }), [2]);
|
|
88
|
+
assert.deepEqual(asList({ list: [3] }), [3]);
|
|
89
|
+
assert.deepEqual(asList({ records: [4] }), [4]);
|
|
90
|
+
assert.deepEqual(asList(null), []);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const STATES = [{ serialNumber: "PS8517", states: [
|
|
94
|
+
{ stateType: "1000", data: { updatedAt: fresh } },
|
|
95
|
+
{ stateType: "1001", data: { batteryPercent: 100, updatedAt: fresh } },
|
|
96
|
+
{ stateType: "1007", data: { mapId: "m1", floor: 3 } },
|
|
97
|
+
{ stateType: "1107", data: { wifi: { signalStrength: 4 } } },
|
|
98
|
+
] }];
|
|
99
|
+
|
|
100
|
+
test("getRobot: online with no position says so in words and is not placed", async () => {
|
|
101
|
+
clearPadbotCache();
|
|
102
|
+
const f = fake({
|
|
103
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
104
|
+
[PADBOT_PATHS.robots]: () => [{ serialNumber: "PS8517", robotModel: "S2" }],
|
|
105
|
+
[PADBOT_PATHS.location]: () => ({ __raw: { code: 1008, message: "Failed to retrieve data", data: null } }),
|
|
106
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [] }),
|
|
107
|
+
});
|
|
108
|
+
const r = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).getRobot("PS8517");
|
|
109
|
+
assert.equal(r.online, true);
|
|
110
|
+
assert.equal(r.statusName, "Standing by · Wi-Fi signal 4 · Position not reported");
|
|
111
|
+
assert.equal(r.position, null);
|
|
112
|
+
assert.equal(r.planPosition, null);
|
|
113
|
+
assert.equal(r.model, "PadBot S2");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("getRobot: x/y in place of worldX/worldY is read; map from the current-map state when the answer omits it", async () => {
|
|
117
|
+
clearPadbotCache();
|
|
118
|
+
const f = fake({
|
|
119
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
120
|
+
[PADBOT_PATHS.robots]: () => [],
|
|
121
|
+
[PADBOT_PATHS.location]: () => ({ x: 5, y: 2.5, yaw: 0 }),
|
|
122
|
+
[PADBOT_PATHS.maps]: () => ({ items: [{ mapId: "m1", width: 200, height: 100, resolution: 0.05, originX: 0, originY: 0 }] }),
|
|
123
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [] }),
|
|
124
|
+
});
|
|
125
|
+
const r = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).getRobot("PS8517");
|
|
126
|
+
assert.deepEqual(r.position, { x: 5, y: 2.5, theta: 0 });
|
|
127
|
+
assert.deepEqual(r.planPosition, { x: 50, y: 50 });
|
|
128
|
+
assert.equal(r.statusName, "Standing by · Wi-Fi signal 4");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("diagnose: PadBot's raw answers per read (code, message, data); maps summarised; no credential anywhere", async () => {
|
|
132
|
+
clearPadbotCache();
|
|
133
|
+
const f = fake({
|
|
134
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
135
|
+
[PADBOT_PATHS.location]: () => ({ __raw: { code: 1008, message: "Failed to retrieve data", data: null } }),
|
|
136
|
+
[PADBOT_PATHS.maps]: () => [{ mapId: "m1", mapName: "20260528172106098_5ecd8fa9", floor: 3, imageUrl: "https://img/x.png", targetPoints: [{ targetPointId: "t", name: "Gate", worldX: 1, worldY: 2, targetPointType: 6 }], restrictedAreas: [{}, {}] }],
|
|
137
|
+
[PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Night", mapId: "m1" }],
|
|
138
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [], totalItems: 0 }),
|
|
139
|
+
[PADBOT_PATHS.records]: () => ({ items: [], totalItems: 0 }),
|
|
140
|
+
});
|
|
141
|
+
const steps = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).diagnose("PS8517");
|
|
142
|
+
assert.deepEqual(steps.map((s) => s.step), ["states (4.2)", "location (4.3)", "maps (5.1)", "patrol routes (6.1)", "alarms (6.4)", "patrol records (6.7)"]);
|
|
143
|
+
const loc = steps[1];
|
|
144
|
+
assert.equal(loc.code, 1008);
|
|
145
|
+
assert.equal(loc.message, "Failed to retrieve data");
|
|
146
|
+
assert.deepEqual(loc.body, { serialNumber: "PS8517" });
|
|
147
|
+
const map = steps[2].data[0];
|
|
148
|
+
assert.equal(map.mapName, "20260528172106098_5ecd8fa9");
|
|
149
|
+
assert.equal(map.counts.restrictedAreas, 2);
|
|
150
|
+
assert.equal(map.targetPoints[0].targetPointType, 6);
|
|
151
|
+
assert.equal("imageUrl" in map, false);
|
|
152
|
+
assert.deepEqual(steps[3].data, [{ pathId: "p1", pathName: "Night", mapId: "m1" }]);
|
|
153
|
+
const text = JSON.stringify(steps);
|
|
154
|
+
assert.ok(!text.includes(CREDS.secret) && !text.includes(CREDS.appid), "never a credential");
|
|
155
|
+
assert.ok(!f.calls.some((c) => c.path === "/api/v1/robots/mqtt/credentials"), "never asks for MQTT credentials");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("live video: HD asks PadBot for quality 1, default smooth for quality 2", async () => {
|
|
159
|
+
clearPadbotCache();
|
|
160
|
+
const f = fake({ [PADBOT_PATHS.video]: () => ({ playbackUrl: "https://v/play", expiresAt: "2026-09-26T09:00:00.000Z" }) });
|
|
161
|
+
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW });
|
|
162
|
+
await a.getLiveVideo("PS8517", "hd");
|
|
163
|
+
await a.getLiveVideo("PS8517");
|
|
164
|
+
assert.deepEqual(f.calls.map((c) => c.body.quality), [1, 2]);
|
|
165
|
+
});
|