@7365admin1/core 3.122.4 → 3.122.5

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.122.5
4
+
5
+ ### Patch Changes
6
+
7
+ - c8627c4: PadBot: Start patrol checks the route against the map the robot is on before sending (the default route on another map was accepted by PadBot and the robot stayed idle); routes take their map from their points; routes on the robot's map are listed first; go to point uses the location read's map.
8
+
3
9
  ## 3.122.4
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -65410,6 +65410,9 @@ function padbotPatrolPlan(paths, maps, states = {}) {
65410
65410
  const routeMapId = (p) => {
65411
65411
  if (typeof p?.mapId === "string" && p.mapId)
65412
65412
  return p.mapId;
65413
+ const pointMaps = new Set((Array.isArray(p?.points) ? p.points : []).map((pt) => pt?.mapId).filter((id) => typeof id === "string" && id));
65414
+ if (pointMaps.size === 1)
65415
+ return [...pointMaps][0];
65413
65416
  const names = Array.isArray(p?.points) && p.points.length ? p.points.map((pt) => pt?.targetPointName) : Array.isArray(p?.pointNames) ? p.pointNames : [];
65414
65417
  if (!names.length)
65415
65418
  return p?.mapId;
@@ -65444,7 +65447,10 @@ function padbotPatrolPlan(paths, maps, states = {}) {
65444
65447
  const r = candidates[0];
65445
65448
  r.currentCheckpoint = r.checkpoints.findIndex((c) => c.name === next);
65446
65449
  }
65447
- routes.sort((a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || Number(b._default) - Number(a._default));
65450
+ const here = (r) => Number(!!currentMap && r.mapId === currentMap);
65451
+ routes.sort(
65452
+ (a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || here(b) - here(a) || Number(b._default) - Number(a._default)
65453
+ );
65448
65454
  for (const r of routes)
65449
65455
  delete r._default;
65450
65456
  return { routes, schedule: [], scheduleShared: false };
@@ -65712,6 +65718,39 @@ function createPadbotAdapter(credentials, options = {}) {
65712
65718
  const n = command?.options?.cleanTimes;
65713
65719
  return Number.isInteger(n) && n >= 1 ? Math.min(n, 99) : 1;
65714
65720
  };
65721
+ async function whereIs(robotSn) {
65722
+ const [st, all, loc] = await Promise.all([
65723
+ states(robotSn),
65724
+ maps(robotSn).catch(() => []),
65725
+ call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null)
65726
+ ]);
65727
+ const ids2 = [loc?.mapId, st?.["1007"]?.mapId];
65728
+ const map = padbotCurrentMap(all, ids2, st?.["1007"]?.floor);
65729
+ const mapId = map?.mapId ?? ids2.find((id) => typeof id === "string" && id) ?? null;
65730
+ return { st: st ?? {}, all: all ?? [], mapId };
65731
+ }
65732
+ const mapName = (all, id) => {
65733
+ const m = all.find((x) => x?.mapId === id);
65734
+ return String(m?.mapDisplayName || m?.mapName || "another");
65735
+ };
65736
+ async function checkedRoute(robotSn, routeId) {
65737
+ const [paths, where] = await Promise.all([call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList), whereIs(robotSn)]);
65738
+ const rawRoute = routeId ? paths.find((p) => p?.pathId === routeId) : paths.find((p) => p?.isDefault);
65739
+ if (!rawRoute) {
65740
+ if (routeId)
65741
+ throw new import_node_server_utils162.BadRequestError(padbotErrorText(2002));
65742
+ return null;
65743
+ }
65744
+ const plan = padbotPatrolPlan(paths, where.all, { ...where.st, "1007": { ...where.st["1007"] ?? {}, mapId: where.mapId } });
65745
+ const route = plan.routes.find((r) => r.id === String(rawRoute.pathId));
65746
+ const routeMap = route?.mapId;
65747
+ if (routeMap && where.mapId && !padbotCanReachMap(where.all, where.mapId, routeMap)) {
65748
+ throw new import_node_server_utils162.BadRequestError(
65749
+ `"${rawRoute.pathName || "That route"}" is on the ${mapName(where.all, routeMap)} map, but the robot is on ${mapName(where.all, where.mapId)}. Pick a route on the robot's map.`
65750
+ );
65751
+ }
65752
+ return String(rawRoute.pathId);
65753
+ }
65715
65754
  async function sendCommand2(robotSn, command) {
65716
65755
  const sn = { serialNumber: robotSn };
65717
65756
  const call2 = async (path5, body) => {
@@ -65733,14 +65772,18 @@ function createPadbotAdapter(credentials, options = {}) {
65733
65772
  }
65734
65773
  };
65735
65774
  switch (command.kind) {
65736
- case "full":
65737
- await call2(PADBOT_PATHS.patrolStart, { ...sn, patrolCount: rounds(command) });
65775
+ case "full": {
65776
+ const pathId = await checkedRoute(robotSn, null);
65777
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, ...pathId ? { pathId } : {}, patrolCount: rounds(command) });
65738
65778
  return;
65739
- case "area":
65779
+ }
65780
+ case "area": {
65740
65781
  if (command.areas.length !== 1)
65741
65782
  throw new import_node_server_utils162.BadRequestError("Choose one patrol route to start.");
65742
- await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId: command.areas[0], patrolCount: rounds(command) });
65783
+ const pathId = await checkedRoute(robotSn, command.areas[0]);
65784
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId, patrolCount: rounds(command) });
65743
65785
  return;
65786
+ }
65744
65787
  case "patrol-resume":
65745
65788
  await call2(PADBOT_PATHS.patrolResume, sn);
65746
65789
  return;
@@ -65759,8 +65802,8 @@ function createPadbotAdapter(credentials, options = {}) {
65759
65802
  await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
65760
65803
  return;
65761
65804
  case "go-to-point": {
65762
- const [st, all] = await Promise.all([states(robotSn), maps(robotSn).catch(() => [])]);
65763
- if (!padbotCanReachMap(all, st?.["1007"]?.mapId, command.mapId))
65805
+ const where = await whereIs(robotSn);
65806
+ if (!padbotCanReachMap(where.all, where.mapId, command.mapId))
65764
65807
  throw new import_node_server_utils162.BadRequestError(PADBOT_OTHER_MAP_TEXT);
65765
65808
  await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
65766
65809
  return;