node-miio 0.4.0 → 0.5.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/.claude/skills/release/SKILL.md +11 -0
- package/AGENTS.md +17 -2
- package/CONTRIBUTING.md +41 -87
- package/README.md +43 -7
- package/dist/cli/commands/cloud/devices.d.ts +10 -0
- package/dist/cli/commands/cloud/login.d.ts +8 -0
- package/dist/cli/commands/cloud/logout.d.ts +4 -0
- package/dist/cli/commands/cloud.d.ts +5 -0
- package/dist/cli/commands/configure.d.ts +18 -0
- package/dist/cli/commands/control.d.ts +4 -0
- package/dist/cli/commands/discover.d.ts +9 -0
- package/dist/cli/commands/inspect.d.ts +4 -0
- package/dist/cli/commands/miot-spec.d.ts +10 -0
- package/dist/cli/commands/protocol/call.d.ts +9 -0
- package/dist/cli/commands/protocol/json-dump.d.ts +8 -0
- package/dist/cli/commands/protocol/packet.d.ts +8 -0
- package/dist/cli/commands/protocol.d.ts +5 -0
- package/dist/cli/commands/tokens/update.d.ts +9 -0
- package/dist/cli/commands/tokens.d.ts +5 -0
- package/dist/cli/device-finder.d.ts +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/log.d.ts +9 -0
- package/dist/cli/prompt.d.ts +11 -0
- package/dist/cli/terminal_qr.d.ts +7 -0
- package/dist/lib/check_result.d.ts +6 -0
- package/dist/lib/cloud/client.d.ts +142 -0
- package/dist/lib/cloud/client.js +2 -5
- package/dist/lib/cloud/client.js.map +1 -1
- package/dist/lib/cloud/crypto.d.ts +56 -0
- package/dist/lib/cloud/errors.d.ts +26 -0
- package/dist/lib/cloud/http.d.ts +55 -0
- package/dist/lib/cloud/index.d.ts +5 -0
- package/dist/lib/cloud/login.d.ts +57 -0
- package/dist/lib/cloud/login.js +2 -2
- package/dist/lib/cloud/login.js.map +1 -1
- package/dist/lib/cloud/session_store.d.ts +27 -0
- package/dist/lib/connect_to_device.d.ts +10 -0
- package/dist/lib/device.d.ts +151 -0
- package/dist/lib/device.js +53 -19
- package/dist/lib/device.js.map +1 -1
- package/dist/lib/device_info.d.ts +66 -0
- package/dist/lib/device_info.js +23 -10
- package/dist/lib/device_info.js.map +1 -1
- package/dist/lib/devices/air-monitor.d.ts +8 -0
- package/dist/lib/devices/air-purifier.d.ts +40 -0
- package/dist/lib/devices/capabilities/battery-level.d.ts +22 -0
- package/dist/lib/devices/capabilities/buzzer.d.ts +33 -0
- package/dist/lib/devices/capabilities/changeable-led-brightness.d.ts +35 -0
- package/dist/lib/devices/capabilities/colorable.d.ts +21 -0
- package/dist/lib/devices/capabilities/dimmable.d.ts +21 -0
- package/dist/lib/devices/capabilities/mode.d.ts +21 -0
- package/dist/lib/devices/capabilities/power.d.ts +21 -0
- package/dist/lib/devices/capabilities/sensor.d.ts +15 -0
- package/dist/lib/devices/capabilities/switchable-led.d.ts +35 -0
- package/dist/lib/devices/chuangmi.plug.v1.d.ts +31 -0
- package/dist/lib/devices/eyecare-lamp2.d.ts +91 -0
- package/dist/lib/devices/gateway/86sw1.d.ts +7 -0
- package/dist/lib/devices/gateway/86sw2.d.ts +7 -0
- package/dist/lib/devices/gateway/ctrl_ln1.d.ts +8 -0
- package/dist/lib/devices/gateway/ctrl_ln2.d.ts +8 -0
- package/dist/lib/devices/gateway/ctrl_neutral1.d.ts +8 -0
- package/dist/lib/devices/gateway/ctrl_neutral2.d.ts +8 -0
- package/dist/lib/devices/gateway/cube.d.ts +6 -0
- package/dist/lib/devices/gateway/developer-api.d.ts +15 -0
- package/dist/lib/devices/gateway/light-channel.d.ts +10 -0
- package/dist/lib/devices/gateway/light-mixin.d.ts +2 -0
- package/dist/lib/devices/gateway/magnet.d.ts +6 -0
- package/dist/lib/devices/gateway/magnet2.d.ts +5 -0
- package/dist/lib/devices/gateway/motion.d.ts +6 -0
- package/dist/lib/devices/gateway/motion2.d.ts +6 -0
- package/dist/lib/devices/gateway/plug.d.ts +6 -0
- package/dist/lib/devices/gateway/sensor_ht.d.ts +5 -0
- package/dist/lib/devices/gateway/subdevice.d.ts +70 -0
- package/dist/lib/devices/gateway/subdevices.d.ts +49 -0
- package/dist/lib/devices/gateway/switch.d.ts +6 -0
- package/dist/lib/devices/gateway/switch2.d.ts +6 -0
- package/dist/lib/devices/gateway/voltage.d.ts +23 -0
- package/dist/lib/devices/gateway/weather.d.ts +5 -0
- package/dist/lib/devices/gateway.d.ts +98 -0
- package/dist/lib/devices/humidifier.d.ts +20 -0
- package/dist/lib/devices/philips-light-bulb.d.ts +8 -0
- package/dist/lib/devices/power-plug.d.ts +30 -0
- package/dist/lib/devices/power-strip.d.ts +7 -0
- package/dist/lib/devices/vacuums/dreamevacuum.d.ts +81 -0
- package/dist/lib/devices/vacuums/dreamevacuum.js +10 -2
- package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -1
- package/dist/lib/devices/vacuums/mijiavacuum.d.ts +4 -0
- package/dist/lib/devices/vacuums/miot-vacuum.d.ts +130 -0
- package/dist/lib/devices/vacuums/miot-vacuum.js +2 -0
- package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -1
- package/dist/lib/devices/vacuums/vacuum.d.ts +276 -0
- package/dist/lib/devices/vacuums/vacuum.js +2 -0
- package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
- package/dist/lib/devices/vacuums/vacuum_device.d.ts +17 -0
- package/dist/lib/devices/vacuums/vacuum_device.js +14 -0
- package/dist/lib/devices/vacuums/vacuum_device.js.map +1 -0
- package/dist/lib/devices/vacuums/vacuum_errors.d.ts +10 -0
- package/dist/lib/devices/vacuums/vacuum_errors.js +25 -0
- package/dist/lib/devices/vacuums/vacuum_errors.js.map +1 -0
- package/dist/lib/devices/vacuums/vacuum_modes.d.ts +51 -0
- package/dist/lib/devices/vacuums/viomivacuum.d.ts +76 -0
- package/dist/lib/devices/vacuums/viomivacuum.js +2 -0
- package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -1
- package/dist/lib/devices/yeelight.color.d.ts +3 -0
- package/dist/lib/devices/yeelight.d.ts +159 -0
- package/dist/lib/devices/yeelight.mono.d.ts +3 -0
- package/dist/lib/discovery.d.ts +53 -0
- package/dist/lib/events.d.ts +18 -0
- package/dist/lib/events.js +3 -0
- package/dist/lib/events.js.map +1 -0
- package/dist/lib/index.d.ts +60 -0
- package/dist/lib/index.js +5 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/info_from_hostname.d.ts +13 -0
- package/dist/lib/logger.d.ts +43 -0
- package/dist/lib/logger.js +62 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/management.d.ts +53 -0
- package/dist/lib/maps/map_watcher.d.ts +71 -0
- package/dist/lib/maps/map_watcher.js +2 -5
- package/dist/lib/maps/map_watcher.js.map +1 -1
- package/dist/lib/maps/roborock_map.d.ts +83 -0
- package/dist/lib/miio_error.d.ts +12 -0
- package/dist/lib/miot/miot_api.d.ts +54 -0
- package/dist/lib/miot/miot_spec.d.ts +114 -0
- package/dist/lib/miot/spec_client.d.ts +125 -0
- package/dist/lib/miot/spec_client.js +2 -2
- package/dist/lib/miot/spec_client.js.map +1 -1
- package/dist/lib/models.d.ts +271 -0
- package/dist/lib/network.d.ts +58 -0
- package/dist/lib/network.js +5 -2
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/packet.d.ts +21 -0
- package/dist/lib/placeholder.d.ts +7 -0
- package/dist/lib/protocol.d.ts +299 -0
- package/dist/lib/safeish_json.d.ts +7 -0
- package/dist/lib/tokens.d.ts +12 -0
- package/dist/types/abstract-things/climate/index.d.ts +431 -0
- package/dist/types/abstract-things/electricals/index.d.ts +5 -0
- package/dist/types/abstract-things/index.d.ts +206 -0
- package/dist/types/abstract-things/lights/index.d.ts +14 -0
- package/dist/types/abstract-things/values/index.d.ts +12 -0
- package/package.json +6 -3
- package/snapshots/vacuum-specs.json.gz +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configureLogging = configureLogging;
|
|
7
|
+
exports.redact = redact;
|
|
8
|
+
exports.maskToken = maskToken;
|
|
9
|
+
exports.createDebug = createDebug;
|
|
10
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
11
|
+
const debug_1 = __importDefault(require("debug"));
|
|
12
|
+
let globalLogger;
|
|
13
|
+
/**
|
|
14
|
+
* Sends node-miio's debug messages to a logger, in addition to the `debug` package (`DEBUG=miio*`, used by the CLI).
|
|
15
|
+
*
|
|
16
|
+
* This is the global logger, used for messages that aren't about a specific device (network, MIoT specs, cloud…).
|
|
17
|
+
* Use the `logger` option of `device()` for the messages of a specific device.
|
|
18
|
+
*
|
|
19
|
+
* @param options The options
|
|
20
|
+
* @param options.logger The logger, or `undefined` to stop sending messages to it
|
|
21
|
+
*/
|
|
22
|
+
function configureLogging(options) {
|
|
23
|
+
globalLogger = options.logger;
|
|
24
|
+
}
|
|
25
|
+
/** Keys whose values are never logged */
|
|
26
|
+
const SECRET_KEYS = /"(token|passwd|password|ssecurity|serviceToken)"\s*:\s*"[^"]*"/g;
|
|
27
|
+
/**
|
|
28
|
+
* Removes secrets (tokens, passwords) from a log message, so users can share their logs safely.
|
|
29
|
+
*
|
|
30
|
+
* @param message The message
|
|
31
|
+
* @returns The message, with the secrets replaced by `***`
|
|
32
|
+
*/
|
|
33
|
+
function redact(message) {
|
|
34
|
+
return message.replace(SECRET_KEYS, '"$1":"***"');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Masks a token: only its first 4 characters are kept, enough to tell tokens apart.
|
|
38
|
+
*
|
|
39
|
+
* @param token The token as hex
|
|
40
|
+
* @returns The masked token
|
|
41
|
+
*/
|
|
42
|
+
function maskToken(token) {
|
|
43
|
+
return token ? `${token.slice(0, 4)}***` : String(token);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a debug function that logs to the `debug` package under `namespace`, and to a {@link MiioLogger}:
|
|
47
|
+
* the one returned by `getLogger` (e.g. the device's), or the global one (see {@link configureLogging}).
|
|
48
|
+
*
|
|
49
|
+
* @param namespace The `debug` namespace (e.g. `miio:network`)
|
|
50
|
+
* @param getLogger Returns the logger to use instead of the global one, if any
|
|
51
|
+
* @returns The debug function
|
|
52
|
+
*/
|
|
53
|
+
function createDebug(namespace, getLogger) {
|
|
54
|
+
const debug = (0, debug_1.default)(namespace);
|
|
55
|
+
return (...msgs) => {
|
|
56
|
+
const message = redact(node_util_1.default.format(...msgs));
|
|
57
|
+
debug("%s", message);
|
|
58
|
+
const logger = getLogger?.() ?? globalLogger;
|
|
59
|
+
logger?.debug(`[${namespace}] ${message}`);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":";;;;;AAyBA,4CAEC;AAYD,wBAEC;AAQD,8BAEC;AAUD,kCAWC;AAxED,0DAA6B;AAE7B,kDAAiC;AAYjC,IAAI,YAAoC,CAAC;AAEzC;;;;;;;;GAQG;AACH,SAAgB,gBAAgB,CAAC,OAAgC;IAC/D,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;AAChC,CAAC;AAED,yCAAyC;AACzC,MAAM,WAAW,GACf,iEAAiE,CAAC;AAEpE;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,OAAe;IACpC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,WAAW,CACzB,SAAiB,EACjB,SAAwC;IAExC,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,SAAS,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,IAAe,EAAE,EAAE;QAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAC7C,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrB,MAAM,MAAM,GAAG,SAAS,EAAE,EAAE,IAAI,YAAY,CAAC;QAC7C,MAAM,EAAE,KAAK,CAAC,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DeviceInfo } from "./device_info";
|
|
2
|
+
export interface DeviceHandle {
|
|
3
|
+
ref: {
|
|
4
|
+
release: () => void;
|
|
5
|
+
};
|
|
6
|
+
api: DeviceInfo;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Management of a device. Supports querying it for information and changing
|
|
10
|
+
* the Wi-Fi settings.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DeviceManagement {
|
|
13
|
+
private readonly api;
|
|
14
|
+
constructor(device: {
|
|
15
|
+
handle: DeviceHandle;
|
|
16
|
+
});
|
|
17
|
+
get model(): string | undefined;
|
|
18
|
+
get token(): string | null;
|
|
19
|
+
get autoToken(): boolean | undefined;
|
|
20
|
+
get address(): string;
|
|
21
|
+
get port(): number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get information about this device. Includes model info, token and
|
|
24
|
+
* connection information.
|
|
25
|
+
*/
|
|
26
|
+
info(): Promise<import("./protocol").MiioDeviceInfo>;
|
|
27
|
+
/**
|
|
28
|
+
* Update the wireless settings of this device. Needs `ssid` and `passwd`
|
|
29
|
+
* to be set in the options object.
|
|
30
|
+
*
|
|
31
|
+
* `uid` can be set to associate the device with a Mi Home user id.
|
|
32
|
+
*
|
|
33
|
+
* @param options
|
|
34
|
+
* @param options.ssid
|
|
35
|
+
* @param options.passwd
|
|
36
|
+
*/
|
|
37
|
+
updateWireless(options: {
|
|
38
|
+
ssid?: string;
|
|
39
|
+
passwd?: string;
|
|
40
|
+
}): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Get the wireless state of this device. Includes if the device is
|
|
43
|
+
* online and counters for things such as authentication failures and
|
|
44
|
+
* connection success and failures.
|
|
45
|
+
*/
|
|
46
|
+
wirelessState(): Promise<unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Update the token used to connect to this device.
|
|
49
|
+
*
|
|
50
|
+
* @param token
|
|
51
|
+
*/
|
|
52
|
+
updateToken(token: string | Buffer): Promise<boolean>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { CloudServer, XiaomiCloud } from "../cloud/client";
|
|
3
|
+
import type { MapPoint, RoborockMap } from "./roborock_map";
|
|
4
|
+
/** What the watcher needs from the vacuum (e.g. a Roborock {@link Vacuum}) */
|
|
5
|
+
export interface MapWatcherDevice {
|
|
6
|
+
getCloudMap(cloud: Pick<XiaomiCloud, "getMapFileUrl" | "download">, server: CloudServer | string): Promise<RoborockMap>;
|
|
7
|
+
cleaning(): Promise<boolean>;
|
|
8
|
+
on(event: "cleaningChanged", listener: (cleaning: boolean) => void): unknown;
|
|
9
|
+
off(event: "cleaningChanged", listener: (cleaning: boolean) => void): unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface MapWatcherOptions {
|
|
12
|
+
/** The server the device is registered in (see {@link XiaomiCloud.findDevice}) */
|
|
13
|
+
server: CloudServer | string;
|
|
14
|
+
/** How often to download the map while cleaning (default 10s, minimum 5s) */
|
|
15
|
+
intervalMs?: number;
|
|
16
|
+
/** The longest wait after consecutive errors (default 5 minutes) */
|
|
17
|
+
maxBackoffMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface MapWatcherEvents {
|
|
20
|
+
/** A new map was downloaded */
|
|
21
|
+
map: [RoborockMap];
|
|
22
|
+
/** The robot moved to another room, or left the rooms (`undefined`), e.g. when it stops cleaning */
|
|
23
|
+
currentRoom: [number | undefined];
|
|
24
|
+
/** The robot moved */
|
|
25
|
+
position: [MapPoint | undefined];
|
|
26
|
+
/** The map couldn't be downloaded. With {@link CloudSessionExpiredError}, the watcher stops polling */
|
|
27
|
+
failed: [Error];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Downloads the vacuum's map from the Xiaomi Cloud while it's cleaning, to report the room it's in.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const watcher = new MapWatcher(vacuum, cloud, { server: "de" });
|
|
34
|
+
* watcher.on("currentRoom", (room) => console.log("Now in room", room));
|
|
35
|
+
* await watcher.start();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class MapWatcher extends EventEmitter<MapWatcherEvents> {
|
|
39
|
+
private readonly device;
|
|
40
|
+
private readonly cloud;
|
|
41
|
+
private readonly options;
|
|
42
|
+
private readonly intervalMs;
|
|
43
|
+
private readonly maxBackoffMs;
|
|
44
|
+
private timer?;
|
|
45
|
+
private polling;
|
|
46
|
+
private started;
|
|
47
|
+
private failures;
|
|
48
|
+
private lastRoom?;
|
|
49
|
+
private lastPosition?;
|
|
50
|
+
constructor(device: MapWatcherDevice, cloud: Pick<XiaomiCloud, "getMapFileUrl" | "download">, options: MapWatcherOptions);
|
|
51
|
+
private readonly onCleaningChanged;
|
|
52
|
+
/**
|
|
53
|
+
* Starts following the vacuum: the map is downloaded while it's cleaning.
|
|
54
|
+
*/
|
|
55
|
+
start(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Stops following the vacuum.
|
|
58
|
+
*/
|
|
59
|
+
stop(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Downloads the map once.
|
|
62
|
+
*
|
|
63
|
+
* @returns The map, or `undefined` if it failed (see the `failed` event)
|
|
64
|
+
*/
|
|
65
|
+
refresh(): Promise<RoborockMap | undefined>;
|
|
66
|
+
private startPolling;
|
|
67
|
+
private stopPolling;
|
|
68
|
+
private poll;
|
|
69
|
+
private updateRoom;
|
|
70
|
+
private updatePosition;
|
|
71
|
+
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.MapWatcher = void 0;
|
|
7
4
|
const node_events_1 = require("node:events");
|
|
8
|
-
const
|
|
5
|
+
const logger_1 = require("../logger");
|
|
9
6
|
const errors_1 = require("../cloud/errors");
|
|
10
|
-
const debug = (0,
|
|
7
|
+
const debug = (0, logger_1.createDebug)("miio:map-watcher");
|
|
11
8
|
const MIN_INTERVAL_MS = 5_000;
|
|
12
9
|
/**
|
|
13
10
|
* Downloads the vacuum's map from the Xiaomi Cloud while it's cleaning, to report the room it's in.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map_watcher.js","sourceRoot":"","sources":["../../../src/lib/maps/map_watcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map_watcher.js","sourceRoot":"","sources":["../../../src/lib/maps/map_watcher.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAE3C,sCAAwC;AAExC,4CAA2D;AAI3D,MAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,kBAAkB,CAAC,CAAC;AAiC9C,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;GAQG;AACH,MAAa,UAAW,SAAQ,0BAA8B;IAWzC;IACA;IACA;IAZF,UAAU,CAAS;IACnB,YAAY,CAAS;IAC9B,KAAK,CAAkB;IACvB,OAAO,GAAG,KAAK,CAAC;IAChB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QACrB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAC1B,MAAM,KAAK,GACT,IAAI,CAAC,QAAQ,KAAK,CAAC;YACjB,CAAC,CAAC,IAAI,CAAC,UAAU;YACjB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACxE,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IAEO,UAAU,CAAC,IAAwB;QACzC,IAAI,IAAI,KAAK,IAAI,CAAC,QAAQ;YAAE,OAAO;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEO,cAAc,CAAC,QAA8B;QACnD,IACE,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC,EACpC,CAAC;YACD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;CACF;AAjHD,gCAiHC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** A pixel of the map image is 50mm (the map coordinates are in mm) */
|
|
2
|
+
export declare const MM_PER_PIXEL = 50;
|
|
3
|
+
/** Pixel values of the map image */
|
|
4
|
+
export declare const PIXEL: {
|
|
5
|
+
readonly OUTSIDE: 0;
|
|
6
|
+
readonly WALL: 1;
|
|
7
|
+
readonly INSIDE: 255;
|
|
8
|
+
readonly SCAN: 7;
|
|
9
|
+
};
|
|
10
|
+
/** A point in map coordinates (mm) */
|
|
11
|
+
export interface MapPoint {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
/** The orientation in degrees, when known */
|
|
15
|
+
angle?: number;
|
|
16
|
+
}
|
|
17
|
+
/** A rectangle in map coordinates (mm) */
|
|
18
|
+
export interface MapRectangle {
|
|
19
|
+
x0: number;
|
|
20
|
+
y0: number;
|
|
21
|
+
x1: number;
|
|
22
|
+
y1: number;
|
|
23
|
+
}
|
|
24
|
+
/** A room (segment) of the map */
|
|
25
|
+
export interface MapRoom extends MapRectangle {
|
|
26
|
+
/** The segment ID, as used by `get_room_mapping` and `app_segment_clean` */
|
|
27
|
+
id: number;
|
|
28
|
+
}
|
|
29
|
+
/** A quadrilateral area (no-go and no-mopping areas) */
|
|
30
|
+
export type MapArea = [MapPoint, MapPoint, MapPoint, MapPoint];
|
|
31
|
+
export interface MapImage {
|
|
32
|
+
/** The position of the image in the map, in pixels */
|
|
33
|
+
top: number;
|
|
34
|
+
left: number;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
/** One byte per pixel, row by row (see {@link PIXEL} and {@link roomOfPixel}) */
|
|
38
|
+
pixels: Uint8Array;
|
|
39
|
+
}
|
|
40
|
+
export interface RoborockMap {
|
|
41
|
+
majorVersion: number;
|
|
42
|
+
minorVersion: number;
|
|
43
|
+
mapIndex: number;
|
|
44
|
+
mapSequence: number;
|
|
45
|
+
/** Whether the file has a digest block (complete file) */
|
|
46
|
+
isValid: boolean;
|
|
47
|
+
image?: MapImage;
|
|
48
|
+
rooms: MapRoom[];
|
|
49
|
+
robot?: MapPoint;
|
|
50
|
+
charger?: MapPoint;
|
|
51
|
+
path: MapPoint[];
|
|
52
|
+
gotoPath: MapPoint[];
|
|
53
|
+
gotoPredictedPath: MapPoint[];
|
|
54
|
+
gotoTarget?: MapPoint;
|
|
55
|
+
zones: MapRectangle[];
|
|
56
|
+
noGoAreas: MapArea[];
|
|
57
|
+
noMoppingAreas: MapArea[];
|
|
58
|
+
virtualWalls: MapRectangle[];
|
|
59
|
+
/** The room the robot is in, if it's inside one */
|
|
60
|
+
currentRoom?: number;
|
|
61
|
+
}
|
|
62
|
+
/** The map file couldn't be parsed */
|
|
63
|
+
export declare class MapParseError extends Error {
|
|
64
|
+
constructor(message: string);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @param value A pixel of the map image
|
|
68
|
+
* @returns The room (segment ID) of the pixel, if it belongs to a room
|
|
69
|
+
*/
|
|
70
|
+
export declare function roomOfPixel(value: number): number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* @param map The parsed map
|
|
73
|
+
* @param point A point in map coordinates (mm)
|
|
74
|
+
* @returns The room (segment ID) at that point, if any
|
|
75
|
+
*/
|
|
76
|
+
export declare function roomAt(map: Pick<RoborockMap, "image">, point: MapPoint): number | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Parses a Roborock map file.
|
|
79
|
+
*
|
|
80
|
+
* @param file The map file, gzipped (as downloaded) or not
|
|
81
|
+
* @returns The map
|
|
82
|
+
*/
|
|
83
|
+
export declare function parseRoborockMap(file: Buffer): RoborockMap;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DeviceInfo } from "./device_info";
|
|
2
|
+
/**
|
|
3
|
+
* Type Guard for MiioError
|
|
4
|
+
*
|
|
5
|
+
* @param error Any possible error
|
|
6
|
+
*/
|
|
7
|
+
export declare function isMiioError(error: unknown): error is MiioError;
|
|
8
|
+
export declare class MiioError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
device?: DeviceInfo | undefined;
|
|
11
|
+
constructor(message: string, code: string, device?: DeviceInfo | undefined);
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { IDevice } from "../device";
|
|
2
|
+
import type { MiotActionResult, MiotPropertyResult } from "../protocol";
|
|
3
|
+
/** Anything that can send RPC calls to the device (i.e., a device instance) */
|
|
4
|
+
export type MiotCaller = Pick<IDevice, "call">;
|
|
5
|
+
/** Devices reject `get_properties` requests with too many properties, so they are sent in batches */
|
|
6
|
+
export declare const GET_PROPERTIES_BATCH_SIZE = 10;
|
|
7
|
+
export interface MiotPropertyRequest {
|
|
8
|
+
/** Free-form identifier echoed back by the device (we use the property's local name) */
|
|
9
|
+
did: string;
|
|
10
|
+
siid: number;
|
|
11
|
+
piid: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Error returned by a MIoT call (`code !== 0`).
|
|
15
|
+
*/
|
|
16
|
+
export declare class MiotError extends Error {
|
|
17
|
+
readonly code: number;
|
|
18
|
+
constructor(message: string, code: number);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads properties with `get_properties`, in batches.
|
|
22
|
+
*
|
|
23
|
+
* @param device The device
|
|
24
|
+
* @param properties The properties to read
|
|
25
|
+
* @returns The results of every property (check `code === 0` for success)
|
|
26
|
+
*/
|
|
27
|
+
export declare function getProperties(device: MiotCaller, properties: MiotPropertyRequest[]): Promise<MiotPropertyResult[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Writes a property with `set_properties`.
|
|
30
|
+
*
|
|
31
|
+
* @param device The device
|
|
32
|
+
* @param property The property to write
|
|
33
|
+
* @param value The value to set
|
|
34
|
+
* @param options Options forwarded to `call` (e.g. `refresh`)
|
|
35
|
+
* @returns The result of the write
|
|
36
|
+
*/
|
|
37
|
+
export declare function setProperty(device: MiotCaller, property: MiotPropertyRequest, value: unknown, options?: Parameters<IDevice["call"]>[2]): Promise<MiotPropertyResult | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Calls an action.
|
|
40
|
+
*
|
|
41
|
+
* @param device The device
|
|
42
|
+
* @param action The action to call
|
|
43
|
+
* @param action.did Free-form identifier
|
|
44
|
+
* @param action.siid The service id
|
|
45
|
+
* @param action.aiid The action id
|
|
46
|
+
* @param args Input arguments (values for the `in` properties, in order)
|
|
47
|
+
* @param options Options forwarded to `call` (e.g. `refresh`)
|
|
48
|
+
* @returns The result of the action
|
|
49
|
+
*/
|
|
50
|
+
export declare function callAction(device: MiotCaller, action: {
|
|
51
|
+
did: string;
|
|
52
|
+
siid: number;
|
|
53
|
+
aiid: number;
|
|
54
|
+
}, args?: unknown[], options?: Parameters<IDevice["call"]>[2]): Promise<MiotActionResult>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and helpers for MIoT specs, as published on https://miot-spec.org/miot-spec-v2/instance?type=<urn>
|
|
3
|
+
*
|
|
4
|
+
* - `services[].iid` is the `siid`
|
|
5
|
+
* - `services[].properties[].iid` is the `piid`
|
|
6
|
+
* - `services[].actions[].iid` is the `aiid`, and `in`/`out` are lists of `piid`s of the same service
|
|
7
|
+
*/
|
|
8
|
+
export interface MiotValueListItem {
|
|
9
|
+
value: number;
|
|
10
|
+
description: string;
|
|
11
|
+
}
|
|
12
|
+
export interface MiotProperty {
|
|
13
|
+
iid: number;
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
format: string;
|
|
17
|
+
access: string[];
|
|
18
|
+
unit?: string;
|
|
19
|
+
"value-list"?: MiotValueListItem[];
|
|
20
|
+
"value-range"?: [number, number, number];
|
|
21
|
+
}
|
|
22
|
+
export interface MiotAction {
|
|
23
|
+
iid: number;
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
in: number[];
|
|
27
|
+
out: number[];
|
|
28
|
+
}
|
|
29
|
+
export interface MiotService {
|
|
30
|
+
iid: number;
|
|
31
|
+
type: string;
|
|
32
|
+
description: string;
|
|
33
|
+
properties?: MiotProperty[];
|
|
34
|
+
actions?: MiotAction[];
|
|
35
|
+
}
|
|
36
|
+
export interface MiotSpec {
|
|
37
|
+
type: string;
|
|
38
|
+
description: string;
|
|
39
|
+
services: MiotService[];
|
|
40
|
+
}
|
|
41
|
+
/** The namespace of the standard (non vendor-specific) definitions */
|
|
42
|
+
export declare const STANDARD_NAMESPACE = "miot-spec-v2";
|
|
43
|
+
export interface ParsedUrn {
|
|
44
|
+
/** e.g. `miot-spec-v2` (standard) or `dreame-spec` (vendor-specific) */
|
|
45
|
+
namespace: string;
|
|
46
|
+
/** e.g. `service`, `property`, `action` or `device` */
|
|
47
|
+
kind: string;
|
|
48
|
+
/** e.g. `vacuum`, `battery-level` */
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parses a MIoT URN like `urn:miot-spec-v2:property:battery-level:00000014:dreame-p2008:1`.
|
|
53
|
+
*
|
|
54
|
+
* @param urn The URN to parse
|
|
55
|
+
* @returns The namespace, kind and name of the URN
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseUrn(urn: string): ParsedUrn;
|
|
58
|
+
export interface ResolvedProperty {
|
|
59
|
+
siid: number;
|
|
60
|
+
piid: number;
|
|
61
|
+
service: MiotService;
|
|
62
|
+
property: MiotProperty;
|
|
63
|
+
}
|
|
64
|
+
export interface ResolvedAction {
|
|
65
|
+
siid: number;
|
|
66
|
+
aiid: number;
|
|
67
|
+
service: MiotService;
|
|
68
|
+
action: MiotAction;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Helper to look up the standard services, properties and actions of a spec by name.
|
|
72
|
+
* Only definitions in the standard namespace are matched, so vendor-specific ones with the same name don't collide.
|
|
73
|
+
*/
|
|
74
|
+
export declare class MiotSpecIndex {
|
|
75
|
+
readonly spec: MiotSpec;
|
|
76
|
+
constructor(spec: MiotSpec);
|
|
77
|
+
/**
|
|
78
|
+
* All standard services with the given name (some services, like `brush-cleaner`, can appear more than once).
|
|
79
|
+
*
|
|
80
|
+
* @param serviceName The name of the service (e.g. `vacuum`)
|
|
81
|
+
* @returns The matching services
|
|
82
|
+
*/
|
|
83
|
+
services(serviceName: string): MiotService[];
|
|
84
|
+
/**
|
|
85
|
+
* Finds a standard property.
|
|
86
|
+
*
|
|
87
|
+
* @param serviceName The name of the service (e.g. `vacuum`)
|
|
88
|
+
* @param propertyName The name of the property (e.g. `status`)
|
|
89
|
+
* @returns The first match, or `undefined`
|
|
90
|
+
*/
|
|
91
|
+
property(serviceName: string, propertyName: string): ResolvedProperty | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Finds a standard action.
|
|
94
|
+
*
|
|
95
|
+
* @param serviceName The name of the service (e.g. `vacuum`)
|
|
96
|
+
* @param actionName The name of the action (e.g. `start-sweep`)
|
|
97
|
+
* @returns The first match, or `undefined`
|
|
98
|
+
*/
|
|
99
|
+
action(serviceName: string, actionName: string): ResolvedAction | undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether the property can be read.
|
|
103
|
+
*
|
|
104
|
+
* @param property The property definition
|
|
105
|
+
* @returns `true` if readable
|
|
106
|
+
*/
|
|
107
|
+
export declare function isReadable(property: MiotProperty): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the property can be written.
|
|
110
|
+
*
|
|
111
|
+
* @param property The property definition
|
|
112
|
+
* @returns `true` if writable
|
|
113
|
+
*/
|
|
114
|
+
export declare function isWritable(property: MiotProperty): boolean;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { MiotSpec } from "./miot_spec";
|
|
2
|
+
export declare const MIOT_SPEC_BASE_URL = "https://miot-spec.org/miot-spec-v2";
|
|
3
|
+
/**
|
|
4
|
+
* The snapshot bundled with each release (generated by `scripts/update-spec-snapshot.mjs`).
|
|
5
|
+
* Resolved from both `src/lib/miot` and `dist/lib/miot`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_SNAPSHOT_PATH: string;
|
|
8
|
+
export interface MiotSpecOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Don't use the network at all (for air-gapped environments).
|
|
11
|
+
* Defaults to `true` when the env var `MIIO_OFFLINE` is set to `1` or `true`.
|
|
12
|
+
*/
|
|
13
|
+
offline?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Directory where the downloaded specs are cached. Set to `false` to disable the cache.
|
|
16
|
+
* Defaults to the env var `MIIO_CACHE_DIR`, or the OS's cache directory (e.g. `~/.cache/node-miio`).
|
|
17
|
+
*/
|
|
18
|
+
cacheDir?: string | false;
|
|
19
|
+
/**
|
|
20
|
+
* Directory with user-provided specs, named `<model>.json`. They take precedence over any other source.
|
|
21
|
+
*/
|
|
22
|
+
specDir?: string;
|
|
23
|
+
/** How long cached data is considered fresh. Defaults to 7 days. */
|
|
24
|
+
ttlMs?: number;
|
|
25
|
+
/** Path to the bundled snapshot. Mostly for testing. */
|
|
26
|
+
snapshotPath?: string;
|
|
27
|
+
/** `fetch` implementation. Mostly for testing. */
|
|
28
|
+
fetch?: typeof fetch;
|
|
29
|
+
}
|
|
30
|
+
export interface MiotInstance {
|
|
31
|
+
model: string;
|
|
32
|
+
type: string;
|
|
33
|
+
status: string;
|
|
34
|
+
version: number;
|
|
35
|
+
}
|
|
36
|
+
export interface MiotSnapshot {
|
|
37
|
+
generatedAt: string;
|
|
38
|
+
source: string;
|
|
39
|
+
models: Record<string, string>;
|
|
40
|
+
specs: Record<string, MiotSpec>;
|
|
41
|
+
}
|
|
42
|
+
export type MiotSpecSource = "spec-dir" | "cache" | "network" | "stale-cache" | "snapshot";
|
|
43
|
+
export interface ResolvedMiotSpec {
|
|
44
|
+
model: string;
|
|
45
|
+
urn: string;
|
|
46
|
+
spec: MiotSpec;
|
|
47
|
+
source: MiotSpecSource;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The default cache directory for the current OS.
|
|
51
|
+
*
|
|
52
|
+
* @returns The absolute path to the cache directory
|
|
53
|
+
*/
|
|
54
|
+
export declare function defaultCacheDir(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Picks the best spec for a model: prefers `released` over other statuses (e.g. `debug`), then the highest version.
|
|
57
|
+
*
|
|
58
|
+
* @param instances The list from `instances?status=all`
|
|
59
|
+
* @param model The model to look for
|
|
60
|
+
* @returns The best instance, or `undefined` if the model is unknown
|
|
61
|
+
*/
|
|
62
|
+
export declare function pickInstance(instances: MiotInstance[], model: string): MiotInstance | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves MIoT specs for device models. Sources, in order:
|
|
65
|
+
* 1. User-provided `specDir`
|
|
66
|
+
* 2. Fresh cache
|
|
67
|
+
* 3. miot-spec.org (unless `offline`)
|
|
68
|
+
* 4. Stale cache
|
|
69
|
+
* 5. The snapshot bundled with the release
|
|
70
|
+
*/
|
|
71
|
+
export declare class MiotSpecClient {
|
|
72
|
+
private readonly options;
|
|
73
|
+
private readonly offline;
|
|
74
|
+
private readonly cacheDir;
|
|
75
|
+
private readonly ttlMs;
|
|
76
|
+
private readonly snapshotPath;
|
|
77
|
+
private readonly fetchImpl;
|
|
78
|
+
private snapshot?;
|
|
79
|
+
private instances?;
|
|
80
|
+
constructor(options?: MiotSpecOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Resolves the spec of a model.
|
|
83
|
+
*
|
|
84
|
+
* @param model The device model (e.g. `dreame.vacuum.p2008`)
|
|
85
|
+
* @returns The spec and where it came from, or `undefined` if no source knows the model
|
|
86
|
+
*/
|
|
87
|
+
getSpec(model: string): Promise<ResolvedMiotSpec | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Metadata about the bundled snapshot (or `undefined` if it's not available).
|
|
90
|
+
*
|
|
91
|
+
* @returns When it was generated and how many models it contains
|
|
92
|
+
*/
|
|
93
|
+
snapshotInfo(): {
|
|
94
|
+
generatedAt: string;
|
|
95
|
+
models: number;
|
|
96
|
+
} | undefined;
|
|
97
|
+
private fromSpecDir;
|
|
98
|
+
private fromNetwork;
|
|
99
|
+
private fromSnapshot;
|
|
100
|
+
private loadSnapshot;
|
|
101
|
+
/**
|
|
102
|
+
* The list of model → URN (~7 MB), cached on disk and in memory.
|
|
103
|
+
*
|
|
104
|
+
* @returns The list of instances
|
|
105
|
+
*/
|
|
106
|
+
private getInstances;
|
|
107
|
+
private loadInstances;
|
|
108
|
+
private fetchJson;
|
|
109
|
+
private specCacheFile;
|
|
110
|
+
private isFresh;
|
|
111
|
+
private readCache;
|
|
112
|
+
private writeCache;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Configures the client used when connecting to devices.
|
|
116
|
+
*
|
|
117
|
+
* @param options The options for the spec client
|
|
118
|
+
*/
|
|
119
|
+
export declare function configureMiotSpecs(options: MiotSpecOptions): void;
|
|
120
|
+
/**
|
|
121
|
+
* The shared spec client (configured via {@link configureMiotSpecs}).
|
|
122
|
+
*
|
|
123
|
+
* @returns The client
|
|
124
|
+
*/
|
|
125
|
+
export declare function getMiotSpecClient(): MiotSpecClient;
|
|
@@ -13,8 +13,8 @@ const node_fs_1 = require("node:fs");
|
|
|
13
13
|
const node_os_1 = __importDefault(require("node:os"));
|
|
14
14
|
const node_path_1 = __importDefault(require("node:path"));
|
|
15
15
|
const node_zlib_1 = require("node:zlib");
|
|
16
|
-
const
|
|
17
|
-
const debug = (0,
|
|
16
|
+
const logger_1 = require("../logger");
|
|
17
|
+
const debug = (0, logger_1.createDebug)("miio:miot-spec");
|
|
18
18
|
exports.MIOT_SPEC_BASE_URL = "https://miot-spec.org/miot-spec-v2";
|
|
19
19
|
const DAY = 24 * 60 * 60 * 1000;
|
|
20
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec_client.js","sourceRoot":"","sources":["../../../src/lib/miot/spec_client.ts"],"names":[],"mappings":";;;;;;AAsFA,0CAkBC;AASD,oCAqBC;AAwOD,gDAGC;AAOD,8CAKC;AA7XD,gEAAkC;AAClC,qCAAmD;AACnD,sDAAyB;AACzB,0DAA6B;AAC7B,yCAAuC;AAEvC,
|
|
1
|
+
{"version":3,"file":"spec_client.js","sourceRoot":"","sources":["../../../src/lib/miot/spec_client.ts"],"names":[],"mappings":";;;;;;AAsFA,0CAkBC;AASD,oCAqBC;AAwOD,gDAGC;AAOD,8CAKC;AA7XD,gEAAkC;AAClC,qCAAmD;AACnD,sDAAyB;AACzB,0DAA6B;AAC7B,yCAAuC;AAEvC,sCAAwC;AAIxC,M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