@apocaliss92/nodedreame 1.11.6 → 1.11.9
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.cjs +92 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +92 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -88,7 +88,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
88
88
|
|
|
89
89
|
// src/support/version.ts
|
|
90
90
|
var LIBRARY_NAME = "nodedreame";
|
|
91
|
-
var LIBRARY_VERSION = "1.11.
|
|
91
|
+
var LIBRARY_VERSION = "1.11.9";
|
|
92
92
|
|
|
93
93
|
// src/transport/errors.ts
|
|
94
94
|
var DreameError = class extends Error {
|
|
@@ -387,6 +387,11 @@ var CachedPropsResponseSchema = import_zod.z.object({
|
|
|
387
387
|
msg: import_zod.z.string().nullish(),
|
|
388
388
|
data: import_zod.z.array(CachedPropEntrySchema).optional()
|
|
389
389
|
}).passthrough();
|
|
390
|
+
var BatchDeviceDataResponseSchema = import_zod.z.object({
|
|
391
|
+
code: import_zod.z.number().optional(),
|
|
392
|
+
msg: import_zod.z.string().nullish(),
|
|
393
|
+
data: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
394
|
+
}).passthrough();
|
|
390
395
|
var SendCommandResponseSchema = import_zod.z.object({
|
|
391
396
|
code: import_zod.z.number().optional(),
|
|
392
397
|
msg: import_zod.z.string().nullish(),
|
|
@@ -647,6 +652,29 @@ async function callAction(base, action, opts = {}) {
|
|
|
647
652
|
const res = await sendCommand({ ...base, ...opts, method: "action", params });
|
|
648
653
|
return res.data?.result ?? res.result ?? res;
|
|
649
654
|
}
|
|
655
|
+
async function getBatchDeviceDatas(base, props, opts = {}) {
|
|
656
|
+
const ctx = base.ctx ?? RequestContext.from({ ...base, host: base.apiHost });
|
|
657
|
+
const signal = opts.signal ?? base.signal;
|
|
658
|
+
const timeoutMs = opts.timeoutMs ?? base.timeoutMs;
|
|
659
|
+
const raw = await httpPostJsonBody({
|
|
660
|
+
ctx,
|
|
661
|
+
path: "/dreame-user-iot/iotuserdata/getDeviceData",
|
|
662
|
+
accessToken: base.session.accessToken,
|
|
663
|
+
body: { did: base.did, model: props },
|
|
664
|
+
context: "batch device data",
|
|
665
|
+
...signal !== void 0 ? { signal } : {},
|
|
666
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {}
|
|
667
|
+
});
|
|
668
|
+
const parsed = BatchDeviceDataResponseSchema.parse(raw);
|
|
669
|
+
if (parsed.code !== void 0 && parsed.code !== 0) {
|
|
670
|
+
throw new DreameApiError(
|
|
671
|
+
`batch device data rejected: code=${parsed.code} msg=${parsed.msg ?? "?"}`,
|
|
672
|
+
200,
|
|
673
|
+
parsed
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
return parsed.data ?? {};
|
|
677
|
+
}
|
|
650
678
|
function extractResultArray(res, context) {
|
|
651
679
|
const raw = Array.isArray(res.data?.result) ? res.data.result : Array.isArray(res.result) ? res.result : null;
|
|
652
680
|
if (raw === null) {
|
|
@@ -2151,6 +2179,43 @@ function parseFrame(inflated) {
|
|
|
2151
2179
|
return { header, tail };
|
|
2152
2180
|
}
|
|
2153
2181
|
|
|
2182
|
+
// src/models/vacuum/map/segment-types.ts
|
|
2183
|
+
var SEGMENT_TYPE_CODE_TO_NAME = {
|
|
2184
|
+
0: "Room",
|
|
2185
|
+
1: "Living Room",
|
|
2186
|
+
2: "Primary Bedroom",
|
|
2187
|
+
3: "Study",
|
|
2188
|
+
4: "Kitchen",
|
|
2189
|
+
5: "Dining Hall",
|
|
2190
|
+
6: "Bathroom",
|
|
2191
|
+
7: "Balcony",
|
|
2192
|
+
8: "Corridor",
|
|
2193
|
+
9: "Utility Room",
|
|
2194
|
+
10: "Closet",
|
|
2195
|
+
11: "Meeting Room",
|
|
2196
|
+
12: "Office",
|
|
2197
|
+
13: "Fitness Area",
|
|
2198
|
+
14: "Recreation Area",
|
|
2199
|
+
15: "Secondary Bedroom"
|
|
2200
|
+
};
|
|
2201
|
+
function safeBase64ToUtf8(s) {
|
|
2202
|
+
try {
|
|
2203
|
+
return Buffer.from(s, "base64").toString("utf8");
|
|
2204
|
+
} catch {
|
|
2205
|
+
return null;
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
function resolveSegmentName(type, index, customName) {
|
|
2209
|
+
if (type !== void 0 && type !== 0 && SEGMENT_TYPE_CODE_TO_NAME[type] !== void 0) {
|
|
2210
|
+
const base = SEGMENT_TYPE_CODE_TO_NAME[type];
|
|
2211
|
+
return index !== void 0 && index > 0 ? `${base} ${index + 1}` : base;
|
|
2212
|
+
}
|
|
2213
|
+
if (typeof customName === "string" && customName.length > 0) {
|
|
2214
|
+
return safeBase64ToUtf8(customName);
|
|
2215
|
+
}
|
|
2216
|
+
return null;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2154
2219
|
// src/models/vacuum/map/pixel-grid.ts
|
|
2155
2220
|
function classifyPixelFsm1(byte) {
|
|
2156
2221
|
if (byte === 0) {
|
|
@@ -2296,7 +2361,9 @@ function collectSegments(layers, dim, tail) {
|
|
|
2296
2361
|
};
|
|
2297
2362
|
segs.push({
|
|
2298
2363
|
id,
|
|
2299
|
-
|
|
2364
|
+
// Mirror the donor: a room-type code (≠0) yields a localized default name
|
|
2365
|
+
// (e.g. "Kitchen"), else the user's custom base64 name, else null.
|
|
2366
|
+
name: resolveSegmentName(meta?.type, meta?.index, meta?.name),
|
|
2300
2367
|
bbox,
|
|
2301
2368
|
centroid,
|
|
2302
2369
|
neighbours: meta?.nei_id ?? [],
|
|
@@ -2307,13 +2374,6 @@ function collectSegments(layers, dim, tail) {
|
|
|
2307
2374
|
}
|
|
2308
2375
|
return segs;
|
|
2309
2376
|
}
|
|
2310
|
-
function safeBase64ToUtf8(s) {
|
|
2311
|
-
try {
|
|
2312
|
-
return Buffer.from(s, "base64").toString("utf8");
|
|
2313
|
-
} catch {
|
|
2314
|
-
return null;
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
2377
|
|
|
2318
2378
|
// src/models/vacuum/map/path.ts
|
|
2319
2379
|
var PATH_TYPE_FROM_OP = {
|
|
@@ -4109,7 +4169,8 @@ var TASK_OPCODE = {
|
|
|
4109
4169
|
ALL_AREA: 100,
|
|
4110
4170
|
EDGE: 101,
|
|
4111
4171
|
ZONE: 102,
|
|
4112
|
-
SPOT: 103
|
|
4172
|
+
SPOT: 103,
|
|
4173
|
+
SET_CURRENT_MAP: 200
|
|
4113
4174
|
};
|
|
4114
4175
|
function buildResumePayload() {
|
|
4115
4176
|
return { m: "a", p: 0, o: 5 };
|
|
@@ -4126,6 +4187,9 @@ function buildEdgePayload(contourIds) {
|
|
|
4126
4187
|
function buildSpotPayload(spotAreaIds) {
|
|
4127
4188
|
return { m: "a", p: 0, o: TASK_OPCODE.SPOT, d: { area: [...spotAreaIds] } };
|
|
4128
4189
|
}
|
|
4190
|
+
function buildSetCurrentMapPayload(mapIndex) {
|
|
4191
|
+
return { m: "a", p: 0, o: TASK_OPCODE.SET_CURRENT_MAP, d: { idx: mapIndex } };
|
|
4192
|
+
}
|
|
4129
4193
|
function buildGetConsumablePayload() {
|
|
4130
4194
|
return { m: "g", t: "CMS" };
|
|
4131
4195
|
}
|
|
@@ -5116,7 +5180,10 @@ var MowerDevice = class _MowerDevice extends BaseDevice {
|
|
|
5116
5180
|
capabilities: input.capabilities ?? new MowerCapabilityResolver().resolve(input.device.model)
|
|
5117
5181
|
});
|
|
5118
5182
|
this.#caps = getMowerCapabilities(input.device.model);
|
|
5119
|
-
this.#fetchBatch = input.getBatchDeviceDatas ??
|
|
5183
|
+
this.#fetchBatch = input.getBatchDeviceDatas ?? ((did, props) => getBatchDeviceDatas(
|
|
5184
|
+
{ session: this.currentSession(), region: this.region, did },
|
|
5185
|
+
props
|
|
5186
|
+
));
|
|
5120
5187
|
}
|
|
5121
5188
|
/** Rich, mower-specific capability record. */
|
|
5122
5189
|
get mowerCapabilities() {
|
|
@@ -5295,6 +5362,20 @@ var MowerDevice = class _MowerDevice extends BaseDevice {
|
|
|
5295
5362
|
}
|
|
5296
5363
|
return this.#sendTask(buildSpotPayload(spotAreaIds.map((s) => Math.trunc(s))));
|
|
5297
5364
|
}
|
|
5365
|
+
/**
|
|
5366
|
+
* Switch the mower's ACTIVE map (2:50 o:200). Takes a map *id* (as carried by
|
|
5367
|
+
* {@link MowerMap.availableMaps}/`currentMapId`) and resolves it to the
|
|
5368
|
+
* firmware's map *index* via the last-fetched map; falls back to treating the
|
|
5369
|
+
* id as the index when no map has been fetched yet. Mirrors the donor
|
|
5370
|
+
* `set_current_map`. Capability-gated on `canMap`.
|
|
5371
|
+
*/
|
|
5372
|
+
async setCurrentMap(mapId) {
|
|
5373
|
+
this.#requireCap(this.#caps.canMap, "setCurrentMap", "map switching");
|
|
5374
|
+
const id = Math.trunc(mapId);
|
|
5375
|
+
const entry = this.#lastMap?.availableMaps.find((m) => m.mapId === id);
|
|
5376
|
+
const index = entry?.mapIndex ?? id;
|
|
5377
|
+
return this.#sendTask(buildSetCurrentMapPayload(index));
|
|
5378
|
+
}
|
|
5298
5379
|
// -- CMS consumables ----------------------------------------------------
|
|
5299
5380
|
/**
|
|
5300
5381
|
* Read the raw CMS consumable counters `[blade, brush, robot]` (minutes used),
|