@7365admin1/core 3.124.0 → 3.124.1

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/dist/index.mjs CHANGED
@@ -64692,9 +64692,9 @@ function padbotReadiness(states, now = Date.now()) {
64692
64692
  const charging = st["1002"]?.chargingState;
64693
64693
  const notes = [];
64694
64694
  if (es.wheelLockState === 1)
64695
- notes.push("PadBot reports the wheel motor lock ON (1006 wheelLockState 1). PadBot's v4.0 document does not say whether this stops navigation - asked PadBot.");
64695
+ notes.push("Wheel motor lock reads 1 (1006). The S2 reads 1 even while it drives, so this does not stop it.");
64696
64696
  if (charging === 2)
64697
- notes.push("Charging state 2 is not in PadBot's v4.0 document (only 0 and 1) - asked PadBot what it means.");
64697
+ notes.push("Charging state 2 = docked on the charger (inferred from the S2; PadBot's v4.0 document lists only 0 and 1).");
64698
64698
  return {
64699
64699
  online: padbotMode(st, now).online,
64700
64700
  heartbeatAt: st["1000"]?.updatedAt ?? null,
@@ -64728,6 +64728,33 @@ function padbotFailureText(p) {
64728
64728
  return null;
64729
64729
  return `Could not reach ${p.target || "its destination"}${p.message ? ` (${p.message})` : ""}`;
64730
64730
  }
64731
+ var PADBOT_CHARGING = { OFF: 0, UNDOCKING_OR_CHARGING: 1, DOCKED: 2, DOCKING: 3 };
64732
+ var PADBOT_MOVED_M = 0.3;
64733
+ var PADBOT_ARRIVED_M = 0.5;
64734
+ var PADBOT_MOTION_MS = 3 * 6e4;
64735
+ function padbotMotion(m, now) {
64736
+ const c = typeof now.charging === "number" ? now.charging : null;
64737
+ const walked = m.pose && now.pose ? Math.hypot(now.pose.x - m.pose.x, now.pose.y - m.pose.y) : null;
64738
+ const moved = c !== null && m.charging !== null && c !== m.charging || walked !== null && walked > PADBOT_MOVED_M;
64739
+ if (!moved)
64740
+ return null;
64741
+ if (m.kind === "return") {
64742
+ if (c === PADBOT_CHARGING.DOCKING)
64743
+ return { text: "Docking", mode: "WORKING", done: false };
64744
+ if (c === PADBOT_CHARGING.DOCKED || c === PADBOT_CHARGING.UNDOCKING_OR_CHARGING)
64745
+ return { text: "Back on charger", mode: null, done: true };
64746
+ return { text: "On the way to the charger", mode: "WORKING", done: false };
64747
+ }
64748
+ if (m.charging === PADBOT_CHARGING.DOCKED && c === PADBOT_CHARGING.UNDOCKING_OR_CHARGING)
64749
+ return { text: "Leaving the charger", mode: "WORKING", done: false };
64750
+ const t = m.target;
64751
+ if (t && t.x !== null && t.y !== null && now.pose && Math.hypot(now.pose.x - t.x, now.pose.y - t.y) <= PADBOT_ARRIVED_M) {
64752
+ return { text: `Arrived at ${t.name}`, mode: null, done: true };
64753
+ }
64754
+ if (t)
64755
+ return { text: `On the way to ${t.name}`, mode: "WORKING", done: false };
64756
+ return { text: m.kind === "full" || m.kind === "area" || m.kind === "patrol-resume" ? "Patrolling" : "On the way", mode: "WORKING", done: false };
64757
+ }
64731
64758
  function networkText(net) {
64732
64759
  const say = (label2, v) => v < 0 ? ` \xB7 ${label2} ${v} dBm` : ` \xB7 ${label2} signal ${v}`;
64733
64760
  const wifi = num(net?.wifi?.signalStrength);
@@ -64996,6 +65023,9 @@ function clearPadbotCache() {
64996
65023
  live.clear();
64997
65024
  commandLog.clear();
64998
65025
  lastFailure.clear();
65026
+ motions.clear();
65027
+ robotReads.clear();
65028
+ alarmReads.clear();
64999
65029
  }
65000
65030
  function forgetPadbotMaps(appid, robotSn) {
65001
65031
  for (const key of cache2.keys())
@@ -65024,6 +65054,11 @@ function logCommand(accountKey, robotSn, entry) {
65024
65054
  var padbotCommandLog = (accountKey, robotSn) => commandLog.get(`${accountKey}:${robotSn}`) ?? [];
65025
65055
  var lastFailure = /* @__PURE__ */ new Map();
65026
65056
  var PADBOT_FAILURE_SHOW_MS = 3 * 6e4;
65057
+ var motions = /* @__PURE__ */ new Map();
65058
+ var PADBOT_ROBOT_READ_MS = 900;
65059
+ var robotReads = /* @__PURE__ */ new Map();
65060
+ var PADBOT_ALARM_READ_MS = 1e4;
65061
+ var alarmReads = /* @__PURE__ */ new Map();
65027
65062
  async function readPadbotStates(credentials, robotSn, stateTypes) {
65028
65063
  const list = await createPadbotClient(credentials).call(PADBOT_PATHS.states, { serialNumbers: [robotSn], stateTypes });
65029
65064
  const entry = (list ?? []).find((e) => e?.serialNumber === robotSn);
@@ -65049,7 +65084,7 @@ async function listPadbotAlarmsSince(credentials, serials, startTime) {
65049
65084
  }
65050
65085
  function createPadbotAdapter(credentials, options = {}) {
65051
65086
  const { call, raw } = createPadbotClient(credentials, options);
65052
- const watch = options.watch === void 0 ? { everyMs: 2e3, forMs: 3e4 } : options.watch;
65087
+ const watch = options.watch === void 0 ? { everyMs: 2e3, forMs: 6e4 } : options.watch;
65053
65088
  const sleep3 = options.sleep ?? ((ms2) => new Promise((resolve) => {
65054
65089
  const t = setTimeout(resolve, ms2);
65055
65090
  t?.unref?.();
@@ -65065,14 +65100,43 @@ function createPadbotAdapter(credentials, options = {}) {
65065
65100
  const entry = (list ?? []).find((e) => e?.serialNumber === sn);
65066
65101
  return entry ? statesByType(entry) : null;
65067
65102
  };
65068
- async function getRobot(robotSn) {
65103
+ function openAlarm(robotSn) {
65104
+ const k = `${account}:${robotSn}`;
65105
+ const hit = alarmReads.get(k);
65106
+ if (hit && now() - hit.at < PADBOT_ALARM_READ_MS)
65107
+ return hit.value;
65108
+ if (alarmReads.size > 2e3)
65109
+ alarmReads.clear();
65110
+ const value = call(PADBOT_PATHS.alarms, { serialNumbers: [robotSn], resolved: false, pageNumber: 1, pageSize: 1 }).then((d) => d?.items?.[0] ?? null).catch(() => {
65111
+ alarmReads.delete(k);
65112
+ return null;
65113
+ });
65114
+ alarmReads.set(k, { at: now(), value });
65115
+ return value;
65116
+ }
65117
+ function getRobot(robotSn) {
65118
+ const k = `${account}:${robotSn}`;
65119
+ const hit = robotReads.get(k);
65120
+ if (hit && now() - hit.at < PADBOT_ROBOT_READ_MS)
65121
+ return hit.value;
65122
+ if (robotReads.size > 2e3)
65123
+ robotReads.clear();
65124
+ const value = readRobot(robotSn);
65125
+ robotReads.set(k, { at: now(), value });
65126
+ value.catch(() => robotReads.delete(k));
65127
+ return value;
65128
+ }
65129
+ async function readRobot(robotSn) {
65130
+ const heard = padbotLive(account, robotSn);
65131
+ const pose = heard?.pose && now() - heard.pose.at < PADBOT_LIVE_POSE_MS ? heard.pose : null;
65132
+ const locRead = pose ? Promise.resolve({ mapId: pose.mapId, worldX: pose.x, worldY: pose.y, yaw: pose.yawDeg }) : call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null);
65133
+ const alarmRead = openAlarm(robotSn);
65069
65134
  const [st, list] = await Promise.all([states(robotSn), roster().catch(() => [])]);
65070
65135
  if (!st)
65071
65136
  return null;
65072
65137
  const info = (list ?? []).find((r) => r?.serialNumber === robotSn);
65073
65138
  const { online, mode, statusName } = padbotMode(st, now());
65074
65139
  const floor = st["1007"]?.floor;
65075
- const heard = padbotLive(account, robotSn);
65076
65140
  const restBatteryAt = ms(st["1001"]?.updatedAt);
65077
65141
  const battery = heard?.batteryPercent !== void 0 && (!Number.isFinite(restBatteryAt) || (heard.batteryAt ?? 0) > restBatteryAt) ? heard.batteryPercent : num(st["1001"]?.batteryPercent);
65078
65142
  const failed = lastFailure.get(`${account}:${robotSn}`);
@@ -65099,11 +65163,8 @@ function createPadbotAdapter(credentials, options = {}) {
65099
65163
  }
65100
65164
  if (!online)
65101
65165
  return robot;
65102
- const pose = heard?.pose && now() - heard.pose.at < PADBOT_LIVE_POSE_MS ? heard.pose : null;
65103
- const [loc, alarm] = await Promise.all([
65104
- pose ? Promise.resolve({ mapId: pose.mapId, worldX: pose.x, worldY: pose.y, yaw: pose.yawDeg }) : call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null),
65105
- robot.fault ? Promise.resolve(null) : call(PADBOT_PATHS.alarms, { serialNumbers: [robotSn], resolved: false, pageNumber: 1, pageSize: 1 }).then((d) => d?.items?.[0] ?? null).catch(() => null)
65106
- ]);
65166
+ const [loc, openA] = await Promise.all([locRead, alarmRead]);
65167
+ const alarm = robot.fault ? null : openA;
65107
65168
  const lx = num(loc?.worldX ?? loc?.x);
65108
65169
  const ly = num(loc?.worldY ?? loc?.y);
65109
65170
  if (typeof loc?.mapId === "string" && loc.mapId)
@@ -65115,6 +65176,13 @@ function createPadbotAdapter(credentials, options = {}) {
65115
65176
  robot.position = { x: lx, y: ly, theta: (num(loc.yaw ?? loc.r) ?? 0) * Math.PI / 180 };
65116
65177
  robot.planPosition = padbotPlanShare(map, lx, ly);
65117
65178
  }
65179
+ const mo = motions.get(`${account}:${robotSn}`);
65180
+ const going = mo && now() - mo.sentAt < PADBOT_MOTION_MS && /^(Standing by|Charging)/.test(robot.statusName ?? "") ? padbotMotion(mo, { charging: st["1002"]?.chargingState, pose: robot.position ? { x: robot.position.x, y: robot.position.y } : null }) : null;
65181
+ if (going) {
65182
+ robot.statusName = (robot.statusName ?? "").replace(/^(Standing by|Charging)/, going.text);
65183
+ if (going.mode)
65184
+ robot.mode = going.mode;
65185
+ }
65118
65186
  const last = heard?.pose;
65119
65187
  if (!robot.position && last && (last.mapId === null || last.mapId === robot.mapId) && (robot.mode === "IDLE" || robot.mode === "CHARGING_CYCLE" || robot.mode === "CHARGED")) {
65120
65188
  robot.position = { x: last.x, y: last.y, theta: (last.yawDeg ?? 0) * Math.PI / 180 };
@@ -65127,7 +65195,8 @@ function createPadbotAdapter(credentials, options = {}) {
65127
65195
  if (pile) {
65128
65196
  robot.position = { x: pile.worldX, y: pile.worldY, theta: (num(pile.yaw) ?? 0) * Math.PI / 180 };
65129
65197
  robot.planPosition = padbotPlanShare(map, pile.worldX, pile.worldY);
65130
- robot.statusName = `${robot.statusName} \xB7 At charger`;
65198
+ if (!going || going.done)
65199
+ robot.statusName = `${robot.statusName} \xB7 At charger`;
65131
65200
  }
65132
65201
  if (!robot.position)
65133
65202
  robot.statusName = `${robot.statusName} \xB7 Position not reported`;
@@ -65148,7 +65217,7 @@ function createPadbotAdapter(credentials, options = {}) {
65148
65217
  const ids2 = [loc?.mapId, st?.["1007"]?.mapId];
65149
65218
  const map = padbotCurrentMap(all, ids2, st?.["1007"]?.floor);
65150
65219
  const mapId = map?.mapId ?? ids2.find((id) => typeof id === "string" && id) ?? null;
65151
- return { st: st ?? {}, all: all ?? [], mapId };
65220
+ return { st: st ?? {}, all: all ?? [], mapId, loc };
65152
65221
  }
65153
65222
  const mapName = (all, id) => {
65154
65223
  const m = all.find((x) => x?.mapId === id);
@@ -65172,10 +65241,10 @@ function createPadbotAdapter(credentials, options = {}) {
65172
65241
  }
65173
65242
  return String(rawRoute.pathId);
65174
65243
  }
65175
- async function watchReaction(robotSn, entry, sentAt) {
65244
+ async function watchReaction(robotSn, entry, sentAt, motion) {
65176
65245
  if (!watch)
65177
65246
  return;
65178
- const r = entry.reaction = { watching: true, points: [], failure: null, moved: false };
65247
+ const r = entry.reaction = { watching: true, points: [], failure: null, moved: false, firstChangeAfterSeconds: null, progress: null };
65179
65248
  let last = "";
65180
65249
  try {
65181
65250
  for (let waited = 0; waited < watch.forMs; ) {
@@ -65185,19 +65254,28 @@ function createPadbotAdapter(credentials, options = {}) {
65185
65254
  if (!st)
65186
65255
  continue;
65187
65256
  const p = padbotReactionPoint(st);
65257
+ const after = Math.round((now() - sentAt) / 1e3);
65188
65258
  const key = JSON.stringify(p);
65189
- if (key !== last && r.points.length < 20)
65190
- r.points.push({ ...p, afterSeconds: Math.round((now() - sentAt) / 1e3) });
65259
+ if (key !== last && r.points.length < 30)
65260
+ r.points.push({ ...p, afterSeconds: after });
65191
65261
  last = key;
65192
- if (p.state >= 1 && p.state <= 4)
65262
+ const heard = padbotLive(account, robotSn)?.pose;
65263
+ const pose = heard && now() - heard.at < PADBOT_LIVE_POSE_MS ? { x: heard.x, y: heard.y } : null;
65264
+ const going = padbotMotion(motion, { charging: p.charging, pose });
65265
+ if (going || p.state >= 1 && p.state <= 5) {
65266
+ if (!r.moved)
65267
+ r.firstChangeAfterSeconds = after;
65193
65268
  r.moved = true;
65269
+ }
65270
+ if (going)
65271
+ r.progress = going.text;
65194
65272
  const failure = padbotFailureText(p);
65195
65273
  if (failure) {
65196
65274
  r.failure = failure;
65197
65275
  lastFailure.set(`${account}:${robotSn}`, { at: now(), text: failure });
65198
65276
  break;
65199
65277
  }
65200
- if (p.state === 5)
65278
+ if (p.state === 5 || going?.done)
65201
65279
  break;
65202
65280
  }
65203
65281
  } finally {
@@ -65206,22 +65284,48 @@ function createPadbotAdapter(credentials, options = {}) {
65206
65284
  }
65207
65285
  async function sendCommand2(robotSn, command) {
65208
65286
  const sn = { serialNumber: robotSn };
65287
+ const where = command.kind === "go-to-point" ? await whereIs(robotSn) : null;
65288
+ let motion = null;
65209
65289
  if (MOVING_COMMANDS.has(command.kind)) {
65210
- const block = padbotCommandBlock(await states(robotSn), command.kind, now());
65290
+ const before = where?.st ?? await states(robotSn);
65291
+ const block = padbotCommandBlock(before, command.kind, now());
65211
65292
  if (block)
65212
65293
  throw new BadRequestError135(block);
65213
65294
  lastFailure.delete(`${account}:${robotSn}`);
65214
- }
65295
+ const heard = padbotLive(account, robotSn)?.pose;
65296
+ const lx = num(where?.loc?.worldX);
65297
+ const ly = num(where?.loc?.worldY);
65298
+ let target = null;
65299
+ if (command.kind === "go-to-point") {
65300
+ const pt = (where?.all ?? []).flatMap((m) => Array.isArray(m?.targetPoints) ? m.targetPoints : []).find((t) => t?.targetPointId === command.targetPointId);
65301
+ target = { name: String(pt?.name || "the chosen point"), x: num(pt?.worldX), y: num(pt?.worldY) };
65302
+ }
65303
+ motion = {
65304
+ kind: command.kind,
65305
+ sentAt: 0,
65306
+ charging: typeof before?.["1002"]?.chargingState === "number" ? before["1002"].chargingState : null,
65307
+ pose: lx !== null && ly !== null ? { x: lx, y: ly } : heard ? { x: heard.x, y: heard.y } : null,
65308
+ target
65309
+ };
65310
+ } else if (command.kind === "cancel")
65311
+ motions.delete(`${account}:${robotSn}`);
65215
65312
  const call2 = async (path5, body) => {
65216
65313
  const at2 = new Date(now()).toISOString();
65217
65314
  const meta = {};
65315
+ const t0 = Date.now();
65218
65316
  try {
65219
65317
  await callRaw(path5, body, meta);
65220
- const entry = { at: at2, command: command.kind, path: path5, body, ok: true, vendorCode: 0, vendorMessage: meta.message, requestId: meta.requestId };
65318
+ const entry = { at: at2, command: command.kind, path: path5, body, ok: true, vendorCode: 0, vendorMessage: meta.message, requestId: meta.requestId, vendorMs: Date.now() - t0 };
65221
65319
  logCommand(account, robotSn, entry);
65222
- if (MOVING_COMMANDS.has(command.kind))
65223
- void watchReaction(robotSn, entry, now()).catch(() => {
65320
+ if (motion) {
65321
+ motion.sentAt = now();
65322
+ if (motions.size > 2e3)
65323
+ motions.clear();
65324
+ motions.set(`${account}:${robotSn}`, motion);
65325
+ robotReads.delete(`${account}:${robotSn}`);
65326
+ void watchReaction(robotSn, entry, motion.sentAt, motion).catch(() => {
65224
65327
  });
65328
+ }
65225
65329
  } catch (e) {
65226
65330
  logCommand(account, robotSn, {
65227
65331
  at: at2,
@@ -65266,7 +65370,6 @@ function createPadbotAdapter(credentials, options = {}) {
65266
65370
  await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
65267
65371
  return;
65268
65372
  case "go-to-point": {
65269
- const where = await whereIs(robotSn);
65270
65373
  if (!padbotCanReachMap(where.all, where.mapId, command.mapId))
65271
65374
  throw new BadRequestError135(PADBOT_OTHER_MAP_TEXT);
65272
65375
  await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
@@ -65364,6 +65467,8 @@ function createPadbotAdapter(credentials, options = {}) {
65364
65467
  }
65365
65468
  for (let i = 0; i < ids2.length; i += 100)
65366
65469
  await call(PADBOT_PATHS.resolve, { alarmIds: ids2.slice(i, i + 100) });
65470
+ robotReads.delete(`${account}:${robotSn}`);
65471
+ alarmReads.delete(`${account}:${robotSn}`);
65367
65472
  return ids2.length;
65368
65473
  },
65369
65474
  async getPatrolHistory(robotSn, pageNumber, pageSize) {
@@ -104918,20 +105023,26 @@ export {
104918
105023
  PADBOT_ACTION_TEXT,
104919
105024
  PADBOT_ALARMS,
104920
105025
  PADBOT_ALARM_POLL_MS,
105026
+ PADBOT_ALARM_READ_MS,
104921
105027
  PADBOT_ALARM_TEXT,
105028
+ PADBOT_ARRIVED_M,
104922
105029
  PADBOT_BRAND,
104923
105030
  PADBOT_BRAND_DEFINITION,
104924
105031
  PADBOT_CAPABILITIES,
105032
+ PADBOT_CHARGING,
104925
105033
  PADBOT_DISPLAY_NAME,
104926
105034
  PADBOT_FAILURE_SHOW_MS,
104927
105035
  PADBOT_LIVE_POSE_MS,
104928
105036
  PADBOT_MAKER_APP_ONLY,
104929
105037
  PADBOT_MODELS,
104930
105038
  PADBOT_MOTION,
105039
+ PADBOT_MOTION_MS,
105040
+ PADBOT_MOVED_M,
104931
105041
  PADBOT_MQTT_SYNC_MS,
104932
105042
  PADBOT_ONLINE_WINDOW_MS,
104933
105043
  PADBOT_OTHER_MAP_TEXT,
104934
105044
  PADBOT_PATHS,
105045
+ PADBOT_ROBOT_READ_MS,
104935
105046
  PATROL_CCTV_CAMERA_FILTER,
104936
105047
  PATROL_EMAIL_MAX_LOGS,
104937
105048
  PATROL_EMAIL_MAX_PER_HOUR,
@@ -105282,6 +105393,7 @@ export {
105282
105393
  padbotLive,
105283
105394
  padbotManualDriveEnabled,
105284
105395
  padbotMode,
105396
+ padbotMotion,
105285
105397
  padbotMqttEnabled,
105286
105398
  padbotPatrolPlan,
105287
105399
  padbotPatrolRecord,