@apocaliss92/nodedreame 1.7.2 → 1.8.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/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  AI_FEATURE_BIT: () => AI_FEATURE_BIT,
34
34
  AI_FEATURE_JSON_KEY: () => AI_FEATURE_JSON_KEY,
35
+ AUTO_SWITCH_JSON_KEY: () => AUTO_SWITCH_JSON_KEY,
35
36
  BaseDevice: () => BaseDevice,
36
37
  ChargingStatus: () => ChargingStatus,
37
38
  CleaningMode: () => CleaningMode,
@@ -64,19 +65,23 @@ __export(index_exports, {
64
65
  createClientDumper: () => createClientDumper,
65
66
  createDumper: () => createDumper,
66
67
  decodeAiFeature: () => decodeAiFeature,
68
+ decodeAutoSwitch: () => decodeAutoSwitch,
69
+ decodeAutoSwitchAll: () => decodeAutoSwitchAll,
67
70
  encodeAiFeatureWrite: () => encodeAiFeatureWrite,
71
+ encodeAutoSwitchWrite: () => encodeAutoSwitchWrite,
68
72
  getMowerCapabilities: () => getMowerCapabilities,
69
73
  getVacuumCapabilities: () => getVacuumCapabilities,
70
74
  isDreameConsumableKey: () => isDreameConsumableKey,
71
75
  renderMowerSvg: () => renderMowerSvg,
72
76
  renderVacuumPng: () => renderVacuumPng,
73
- resolveCapabilities: () => resolveCapabilities
77
+ resolveCapabilities: () => resolveCapabilities,
78
+ supportedAutoSwitchKeys: () => supportedAutoSwitchKeys
74
79
  });
75
80
  module.exports = __toCommonJS(index_exports);
76
81
 
77
82
  // src/support/version.ts
78
83
  var LIBRARY_NAME = "nodedreame";
79
- var LIBRARY_VERSION = "1.7.2";
84
+ var LIBRARY_VERSION = "1.8.0";
80
85
 
81
86
  // src/transport/errors.ts
82
87
  var DreameError = class extends Error {
@@ -1233,6 +1238,12 @@ var VACUUM_PROP = {
1233
1238
  * via `ai-detection.ts` ({@link decodeAiFeature} / {@link encodeAiFeatureWrite}).
1234
1239
  */
1235
1240
  AI_DETECTION: { siid: 4, piid: 22 },
1241
+ /**
1242
+ * Auto-switch settings bundle (Tasshack types.py — `AUTO_SWITCH_SETTINGS`,
1243
+ * siid 4 piid 50). A JSON string packing every secondary toggle/setting as
1244
+ * `[{"k":<key>,"v":<int>}, …]`. Decode/encode per-setting via `auto-switch.ts`.
1245
+ */
1246
+ AUTO_SWITCH_SETTINGS: { siid: 4, piid: 50 },
1236
1247
  /** VERIFIED r2532a 2026-05-03 — task progress percentage 0..100. */
1237
1248
  TASK_PROGRESS_PCT: { siid: 4, piid: 63 },
1238
1249
  /** VERIFIED r2532a — mop-drying progress (minutes ticking during MopDrying). */
@@ -1646,6 +1657,105 @@ function encodeAiFeatureWrite(raw, feature, value) {
1646
1657
  );
1647
1658
  }
1648
1659
 
1660
+ // src/models/vacuum/auto-switch.ts
1661
+ var AUTO_SWITCH_JSON_KEY = {
1662
+ collisionAvoidance: "LessColl",
1663
+ fillLight: "FillinLight",
1664
+ autoDrying: "AutoDry",
1665
+ stainAvoidance: "StainIdentify",
1666
+ moppingType: "CleanType",
1667
+ cleanGenius: "SmartHost",
1668
+ widerCornerCoverage: "MeticulousTwist",
1669
+ floorDirectionCleaning: "MaterialDirectionClean",
1670
+ petFocusedCleaning: "PetPartClean",
1671
+ autoRecleaning: "SmartAutoMop",
1672
+ autoRewashing: "SmartAutoWash",
1673
+ mopPadSwing: "MopScalable",
1674
+ autoCharging: "SmartCharge",
1675
+ humanFollow: "MonitorHumanFollow",
1676
+ maxSuctionPower: "SuctionMax",
1677
+ smartDrying: "SmartDrying",
1678
+ drainageConfirmResult: "FluctuationConfirmResult",
1679
+ drainageTestResult: "FluctuationTestResult",
1680
+ hotWashing: "HotWash",
1681
+ uvSterilization: "UVLight",
1682
+ cleaningRoute: "CleanRoute",
1683
+ customMoppingMode: "MopEffectSwitch",
1684
+ moppingMode: "MopEffectState",
1685
+ selfCleanFrequency: "BackWashType",
1686
+ intensiveCarpetCleaning: "CarpetFineClean",
1687
+ gapCleaningExtension: "LacuneMopScalable",
1688
+ moppingUnderFurnitures: "MopScalable2",
1689
+ ultraCleanMode: "SuperWash",
1690
+ streamingVoicePrompt: "MonitorPromptLevel",
1691
+ mopExtend: "MopExtrSwitch",
1692
+ mopExtendFrequency: "ExtrFreq",
1693
+ sideReach: "SbrushExtrSwitch",
1694
+ intelligentStainCleaning: "HeavyStainSmart"
1695
+ };
1696
+ var JSON_KEY_TO_CANONICAL = Object.fromEntries(
1697
+ Object.entries(AUTO_SWITCH_JSON_KEY).map(([k, v]) => [v, k])
1698
+ );
1699
+ function coerceInt(v) {
1700
+ if (typeof v === "number") return Number.isFinite(v) ? v : null;
1701
+ if (typeof v === "string" && v.trim() !== "") {
1702
+ const n = Number(v);
1703
+ return Number.isFinite(n) ? n : null;
1704
+ }
1705
+ return null;
1706
+ }
1707
+ function parseAutoSwitchMap(raw) {
1708
+ if (typeof raw !== "string" || raw.length <= 2) return null;
1709
+ let parsed;
1710
+ try {
1711
+ parsed = JSON.parse(raw);
1712
+ } catch {
1713
+ return null;
1714
+ }
1715
+ const out = /* @__PURE__ */ new Map();
1716
+ const add = (entry) => {
1717
+ if (entry === null || typeof entry !== "object") return;
1718
+ const rec = entry;
1719
+ if (typeof rec["k"] !== "string") return;
1720
+ const value = coerceInt(rec["v"]);
1721
+ if (value !== null) out.set(rec["k"], value);
1722
+ };
1723
+ if (Array.isArray(parsed)) {
1724
+ for (const entry of parsed) add(entry);
1725
+ } else {
1726
+ add(parsed);
1727
+ }
1728
+ return out.size > 0 ? out : null;
1729
+ }
1730
+ function decodeAutoSwitch(raw, key2) {
1731
+ const map = parseAutoSwitchMap(raw);
1732
+ if (map === null) return null;
1733
+ const jsonKey = AUTO_SWITCH_JSON_KEY[key2];
1734
+ return map.has(jsonKey) ? map.get(jsonKey) ?? null : null;
1735
+ }
1736
+ function supportedAutoSwitchKeys(raw) {
1737
+ const map = parseAutoSwitchMap(raw);
1738
+ if (map === null) return [];
1739
+ const present = [];
1740
+ for (const key2 of Object.keys(AUTO_SWITCH_JSON_KEY)) {
1741
+ if (map.has(AUTO_SWITCH_JSON_KEY[key2])) present.push(key2);
1742
+ }
1743
+ return present;
1744
+ }
1745
+ function decodeAutoSwitchAll(raw) {
1746
+ const map = parseAutoSwitchMap(raw);
1747
+ if (map === null) return {};
1748
+ const out = {};
1749
+ for (const [jsonKey, value] of map) {
1750
+ const canonical = JSON_KEY_TO_CANONICAL[jsonKey];
1751
+ if (canonical !== void 0) out[canonical] = value;
1752
+ }
1753
+ return out;
1754
+ }
1755
+ function encodeAutoSwitchWrite(key2, value) {
1756
+ return JSON.stringify({ k: AUTO_SWITCH_JSON_KEY[key2], v: Math.trunc(value) });
1757
+ }
1758
+
1649
1759
  // src/models/vacuum/consumables.ts
1650
1760
  var VACUUM_CONSUMABLES = [
1651
1761
  { key: "main-brush", label: "Main Brush", life: { siid: 9, piid: 2 }, reset: { siid: 9, aiid: 1 } },
@@ -2962,6 +3072,63 @@ var VacuumDevice = class _VacuumDevice extends BaseDevice {
2962
3072
  const next = encodeAiFeatureWrite(this.aiDetectionRaw, feature, value);
2963
3073
  return this.setProperty({ ...VACUUM_PROP.AI_DETECTION, value: next });
2964
3074
  }
3075
+ // -- auto-switch settings -----------------------------------------------
3076
+ /**
3077
+ * The raw `AUTO_SWITCH_SETTINGS` value (siid 4 piid 50) — a JSON string packing
3078
+ * every secondary toggle/setting — or `null` when not yet observed. Prefer the
3079
+ * decoded {@link autoSwitchProperty} / {@link supportedAutoSwitchKeys} surface.
3080
+ */
3081
+ get autoSwitchRaw() {
3082
+ const v = this.getProperty(
3083
+ VACUUM_PROP.AUTO_SWITCH_SETTINGS.siid,
3084
+ VACUUM_PROP.AUTO_SWITCH_SETTINGS.piid
3085
+ )?.value;
3086
+ return typeof v === "string" ? v : null;
3087
+ }
3088
+ /** Whether this model reports the packed auto-switch bundle at all. */
3089
+ get hasAutoSwitchSettings() {
3090
+ return this.autoSwitchRaw !== null;
3091
+ }
3092
+ /**
3093
+ * The auto-switch settings this model reports, decoded from the packed value.
3094
+ * Presence-driven (a key appears iff the payload carries it) — mirrors
3095
+ * Tasshack `auto_switch_data`.
3096
+ */
3097
+ get supportedAutoSwitchKeys() {
3098
+ return supportedAutoSwitchKeys(this.autoSwitchRaw);
3099
+ }
3100
+ /**
3101
+ * Read ONE auto-switch setting's int value, decoded from the packed
3102
+ * `AUTO_SWITCH_SETTINGS` payload. `null` when the value is unobserved or the
3103
+ * key is not present. The value is an opaque int (boolean 0/1, a small enum, or
3104
+ * a `-1`/`-n` "not applicable" sentinel) — the caller interprets it.
3105
+ */
3106
+ autoSwitchProperty(key2) {
3107
+ return decodeAutoSwitch(this.autoSwitchRaw, key2);
3108
+ }
3109
+ /**
3110
+ * Seed {@link autoSwitchRaw} from the CLOUD SHADOW (the last value the robot
3111
+ * pushed for `AUTO_SWITCH_SETTINGS`, siid 4 piid 50) WITHOUT waking it. Like the
3112
+ * AI bundle these are STATIC settings the robot rarely re-pushes over MQTT, so a
3113
+ * fresh connect to an idle robot has no value cached — call this on activate to
3114
+ * surface the current settings. Returns the resolved raw value (`null` when the
3115
+ * shadow carries none yet).
3116
+ */
3117
+ async refreshAutoSwitch() {
3118
+ await this.refreshCachedProperties([VACUUM_PROP.AUTO_SWITCH_SETTINGS]);
3119
+ return this.autoSwitchRaw;
3120
+ }
3121
+ /**
3122
+ * Set ONE auto-switch setting. Mirrors Tasshack `set_auto_switch_property`: a
3123
+ * single-key `{"k":<key>,"v":<int>}` write the device merges server-side (the
3124
+ * other settings are preserved without a read-modify-write). Rejects when the
3125
+ * model does not report the bundle.
3126
+ */
3127
+ async setAutoSwitchProperty(key2, value) {
3128
+ this.#requireCap(this.hasAutoSwitchSettings, "setAutoSwitchProperty", "auto-switch settings");
3129
+ const next = encodeAutoSwitchWrite(key2, value);
3130
+ return this.setProperty({ ...VACUUM_PROP.AUTO_SWITCH_SETTINGS, value: next });
3131
+ }
2965
3132
  // -- command helpers ----------------------------------------------------
2966
3133
  #resolveCleanOpts(opts) {
2967
3134
  const repeats = Math.max(1, Math.trunc(opts.repeats ?? 1));
@@ -4877,6 +5044,7 @@ function createClientDumper(client, options) {
4877
5044
  0 && (module.exports = {
4878
5045
  AI_FEATURE_BIT,
4879
5046
  AI_FEATURE_JSON_KEY,
5047
+ AUTO_SWITCH_JSON_KEY,
4880
5048
  BaseDevice,
4881
5049
  ChargingStatus,
4882
5050
  CleaningMode,
@@ -4909,12 +5077,16 @@ function createClientDumper(client, options) {
4909
5077
  createClientDumper,
4910
5078
  createDumper,
4911
5079
  decodeAiFeature,
5080
+ decodeAutoSwitch,
5081
+ decodeAutoSwitchAll,
4912
5082
  encodeAiFeatureWrite,
5083
+ encodeAutoSwitchWrite,
4913
5084
  getMowerCapabilities,
4914
5085
  getVacuumCapabilities,
4915
5086
  isDreameConsumableKey,
4916
5087
  renderMowerSvg,
4917
5088
  renderVacuumPng,
4918
- resolveCapabilities
5089
+ resolveCapabilities,
5090
+ supportedAutoSwitchKeys
4919
5091
  });
4920
5092
  //# sourceMappingURL=index.cjs.map