node-miio 0.3.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/settings.json +5 -0
- package/.claude/skills/release/SKILL.md +73 -0
- package/AGENTS.md +25 -2
- package/CONTRIBUTING.md +41 -87
- package/LICENSE.md +28 -0
- package/README.md +86 -44
- package/dist/cli/commands/cloud/devices.d.ts +10 -0
- package/dist/cli/commands/cloud/devices.js +71 -0
- package/dist/cli/commands/cloud/devices.js.map +1 -0
- package/dist/cli/commands/cloud/login.d.ts +8 -0
- package/dist/cli/commands/cloud/login.js +63 -0
- package/dist/cli/commands/cloud/login.js.map +1 -0
- package/dist/cli/commands/cloud/logout.d.ts +4 -0
- package/dist/cli/commands/cloud/logout.js +14 -0
- package/dist/cli/commands/cloud/logout.js.map +1 -0
- package/dist/cli/commands/cloud.d.ts +5 -0
- package/dist/cli/commands/cloud.js +49 -0
- package/dist/cli/commands/cloud.js.map +1 -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/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/log.d.ts +9 -0
- package/dist/cli/prompt.d.ts +11 -0
- package/dist/cli/prompt.js +42 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/terminal_qr.d.ts +7 -0
- package/dist/cli/terminal_qr.js +14 -0
- package/dist/cli/terminal_qr.js.map +1 -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 +282 -0
- package/dist/lib/cloud/client.js.map +1 -0
- package/dist/lib/cloud/crypto.d.ts +56 -0
- package/dist/lib/cloud/crypto.js +128 -0
- package/dist/lib/cloud/crypto.js.map +1 -0
- package/dist/lib/cloud/errors.d.ts +26 -0
- package/dist/lib/cloud/errors.js +50 -0
- package/dist/lib/cloud/errors.js.map +1 -0
- package/dist/lib/cloud/http.d.ts +55 -0
- package/dist/lib/cloud/http.js +159 -0
- package/dist/lib/cloud/http.js.map +1 -0
- package/dist/lib/cloud/index.d.ts +5 -0
- package/dist/lib/cloud/index.js +22 -0
- package/dist/lib/cloud/index.js.map +1 -0
- package/dist/lib/cloud/login.d.ts +57 -0
- package/dist/lib/cloud/login.js +352 -0
- package/dist/lib/cloud/login.js.map +1 -0
- package/dist/lib/cloud/session_store.d.ts +27 -0
- package/dist/lib/cloud/session_store.js +71 -0
- package/dist/lib/cloud/session_store.js.map +1 -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 +82 -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 +18 -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 +127 -0
- package/dist/lib/maps/map_watcher.js.map +1 -0
- package/dist/lib/maps/roborock_map.d.ts +83 -0
- package/dist/lib/maps/roborock_map.js +269 -0
- package/dist/lib/maps/roborock_map.js.map +1 -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/docs/cloud.md +74 -0
- package/docs/devices/vacuum.md +9 -1
- package/package.json +7 -3
- package/snapshots/vacuum-specs.json.gz +0 -0
|
@@ -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,MAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,gBAAgB,CAAC,CAAC;AAE/B,QAAA,kBAAkB,GAAG,oCAAoC,CAAC;AAEvE,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhC;;;GAGG;AACU,QAAA,qBAAqB,GAAG,mBAAI,CAAC,OAAO,CAC/C,SAAS,EACT,yCAAyC,CAC1C,CAAC;AA0DF;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IA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AI,oBAAiD,CAAC;AAEtD;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,OAAwB;IACzD,oBAAoB,GAAG,OAAO,CAAC;IAC/B,aAAa,GAAG,SAAS,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,cAAc,CAAC,oBAAoB,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping from models into high-level devices.
|
|
3
|
+
*/
|
|
4
|
+
import { AirMonitor } from "./devices/air-monitor";
|
|
5
|
+
import { AirPurifier } from "./devices/air-purifier";
|
|
6
|
+
import { Vacuum } from "./devices/vacuums/vacuum";
|
|
7
|
+
import { MijiaVacuum } from "./devices/vacuums/mijiavacuum";
|
|
8
|
+
import { ViomiVacuum } from "./devices/vacuums/viomivacuum";
|
|
9
|
+
import { DreameVacuum } from "./devices/vacuums/dreamevacuum";
|
|
10
|
+
import PowerPlug from "./devices/power-plug";
|
|
11
|
+
import PowerPlugChuangmiV1 from "./devices/chuangmi.plug.v1";
|
|
12
|
+
import PowerStrip from "./devices/power-strip";
|
|
13
|
+
import Humidifier from "./devices/humidifier";
|
|
14
|
+
import YeelightColor from "./devices/yeelight.color";
|
|
15
|
+
import YeelightMono from "./devices/yeelight.mono";
|
|
16
|
+
import EyecareLamp2 from "./devices/eyecare-lamp2";
|
|
17
|
+
import PhilipsLightBulb from "./devices/philips-light-bulb";
|
|
18
|
+
export declare const models: {
|
|
19
|
+
"zhimi.airmonitor.v1": typeof AirMonitor;
|
|
20
|
+
"zhimi.airpurifier.v1": typeof AirPurifier;
|
|
21
|
+
"zhimi.airpurifier.v2": typeof AirPurifier;
|
|
22
|
+
"zhimi.airpurifier.v3": typeof AirPurifier;
|
|
23
|
+
"zhimi.airpurifier.v6": typeof AirPurifier;
|
|
24
|
+
"zhimi.airpurifier.m1": typeof AirPurifier;
|
|
25
|
+
"zhimi.airpurifier.m2": typeof AirPurifier;
|
|
26
|
+
"zhimi.airpurifier.ma2": typeof AirPurifier;
|
|
27
|
+
"zhimi.humidifier.v1": {
|
|
28
|
+
new (options: any): Humidifier;
|
|
29
|
+
get type(): string;
|
|
30
|
+
};
|
|
31
|
+
"chuangmi.plug.m1": {
|
|
32
|
+
new (options: any): PowerPlug;
|
|
33
|
+
get type(): string;
|
|
34
|
+
};
|
|
35
|
+
"chuangmi.plug.v1": {
|
|
36
|
+
new (options: any): PowerPlugChuangmiV1;
|
|
37
|
+
get type(): string;
|
|
38
|
+
};
|
|
39
|
+
"chuangmi.plug.v2": {
|
|
40
|
+
new (options: any): PowerPlug;
|
|
41
|
+
get type(): string;
|
|
42
|
+
};
|
|
43
|
+
"rockrobo.vacuum.v1": typeof Vacuum;
|
|
44
|
+
"roborock.vacuum.s5": typeof Vacuum;
|
|
45
|
+
"roborock.vacuum.s5e": typeof Vacuum;
|
|
46
|
+
"roborock.vacuum.c1": typeof Vacuum;
|
|
47
|
+
"roborock.vacuum.s6": typeof Vacuum;
|
|
48
|
+
"roborock.vacuum.t6": typeof Vacuum;
|
|
49
|
+
"roborock.vacuum.e2": typeof Vacuum;
|
|
50
|
+
"roborock.vacuum.s4": typeof Vacuum;
|
|
51
|
+
"roborock.vacuum.a10": typeof Vacuum;
|
|
52
|
+
"roborock.vacuum.m1s": typeof MijiaVacuum;
|
|
53
|
+
"viomi.vacuum.v7": typeof ViomiVacuum;
|
|
54
|
+
"viomi.vacuum.v8": typeof ViomiVacuum;
|
|
55
|
+
"dreame.vacuum.mc1808": typeof DreameVacuum;
|
|
56
|
+
"lumi.gateway.v2": any;
|
|
57
|
+
"lumi.gateway.v3": any;
|
|
58
|
+
"lumi.acpartner.v1": new (options?: any) => {
|
|
59
|
+
extraChildren: any[];
|
|
60
|
+
_monitorInterval: number;
|
|
61
|
+
syncer: any;
|
|
62
|
+
_report(properties: any): void;
|
|
63
|
+
initCallback(): Promise<void>;
|
|
64
|
+
_deviceListTimer: NodeJS.Timeout | undefined;
|
|
65
|
+
destroyCallback(): Promise<void>;
|
|
66
|
+
addExtraChild(child: any): void;
|
|
67
|
+
_updateDeviceList(): Promise<any>;
|
|
68
|
+
_findDeveloperKey(): Promise<any>;
|
|
69
|
+
_setDeveloperKey(key: string): Promise<any>;
|
|
70
|
+
_developerKey: string | undefined;
|
|
71
|
+
devApi: import("./devices/gateway/developer-api") | undefined;
|
|
72
|
+
addDevice(): Promise<undefined>;
|
|
73
|
+
stopAddDevice(): Promise<undefined>;
|
|
74
|
+
removeDevice(id: string): Promise<undefined>;
|
|
75
|
+
id: string | null;
|
|
76
|
+
metadata: Record<string, unknown> & {
|
|
77
|
+
types: string[];
|
|
78
|
+
capabilities: string[];
|
|
79
|
+
addCapabilities(...capabilities: string[]): void;
|
|
80
|
+
};
|
|
81
|
+
init(): Promise</*elided*/ any | undefined>;
|
|
82
|
+
destroy(): Promise<void>;
|
|
83
|
+
debug: ((...parts: unknown[]) => void) & ((...msgs: unknown[]) => void);
|
|
84
|
+
matches(...tags: string[]): boolean;
|
|
85
|
+
propertyUpdated: ((key: string, value: unknown, oldValue?: unknown) => void) & ((_key: string, _value: unknown, _oldValue: unknown) => void);
|
|
86
|
+
emitEvent(event: string, data?: unknown, options?: unknown): void;
|
|
87
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
88
|
+
off(event: string, listener: (...args: never[]) => void): unknown;
|
|
89
|
+
extendWith<T>(...mixins: T[]): T & import("abstract-things").Thing;
|
|
90
|
+
readonly miioModel?: string;
|
|
91
|
+
readonly _properties: Record<string, unknown>;
|
|
92
|
+
readonly _propertiesToMonitor: string[];
|
|
93
|
+
readonly _propertyDefinitions: Record<string, import("./device").PersistedPropertyDefinition<never, never>>;
|
|
94
|
+
readonly _reversePropertyDefinitions: Record<string, string>;
|
|
95
|
+
readonly management: import("./management").DeviceManagement;
|
|
96
|
+
debugFn?: import("./logger").DebugFn;
|
|
97
|
+
readonly handle: import("./management").DeviceHandle;
|
|
98
|
+
miioCall<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params): Promise<Response>;
|
|
99
|
+
call<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params, options?: {
|
|
100
|
+
refresh?: string[];
|
|
101
|
+
refreshDelay?: number;
|
|
102
|
+
sid?: number;
|
|
103
|
+
retries?: number;
|
|
104
|
+
}): Promise<Response>;
|
|
105
|
+
defineProperty<T, V>(name: string, def?: import("./device").Mapper<T, V> | import("./device").PropertyDefinition<T, V> | undefined): void;
|
|
106
|
+
_pushProperty(result: Record<string, unknown>, name: string, value: unknown): void;
|
|
107
|
+
poll(_isInitial?: boolean): Promise<void>;
|
|
108
|
+
_loadProperties(properties?: string[]): Promise<void>;
|
|
109
|
+
setProperty(key: string, value: unknown): void;
|
|
110
|
+
setRawProperty(name: string, value: unknown): void;
|
|
111
|
+
property<T>(key: string): T;
|
|
112
|
+
get connected(): boolean;
|
|
113
|
+
get properties(): Record<string, unknown>;
|
|
114
|
+
miioProperties(): Record<string, unknown>;
|
|
115
|
+
getProperties(props: string[]): {};
|
|
116
|
+
loadProperties(props: string[]): Promise<{}>;
|
|
117
|
+
updatePollDuration(duration: number): void;
|
|
118
|
+
updateMaxPollFailures(failures: number): void;
|
|
119
|
+
} & import("abstract-things").Thing;
|
|
120
|
+
"lumi.acpartner.v2": new (options?: any) => {
|
|
121
|
+
extraChildren: any[];
|
|
122
|
+
_monitorInterval: number;
|
|
123
|
+
syncer: any;
|
|
124
|
+
_report(properties: any): void;
|
|
125
|
+
initCallback(): Promise<void>;
|
|
126
|
+
_deviceListTimer: NodeJS.Timeout | undefined;
|
|
127
|
+
destroyCallback(): Promise<void>;
|
|
128
|
+
addExtraChild(child: any): void;
|
|
129
|
+
_updateDeviceList(): Promise<any>;
|
|
130
|
+
_findDeveloperKey(): Promise<any>;
|
|
131
|
+
_setDeveloperKey(key: string): Promise<any>;
|
|
132
|
+
_developerKey: string | undefined;
|
|
133
|
+
devApi: import("./devices/gateway/developer-api") | undefined;
|
|
134
|
+
addDevice(): Promise<undefined>;
|
|
135
|
+
stopAddDevice(): Promise<undefined>;
|
|
136
|
+
removeDevice(id: string): Promise<undefined>;
|
|
137
|
+
id: string | null;
|
|
138
|
+
metadata: Record<string, unknown> & {
|
|
139
|
+
types: string[];
|
|
140
|
+
capabilities: string[];
|
|
141
|
+
addCapabilities(...capabilities: string[]): void;
|
|
142
|
+
};
|
|
143
|
+
init(): Promise</*elided*/ any | undefined>;
|
|
144
|
+
destroy(): Promise<void>;
|
|
145
|
+
debug: ((...parts: unknown[]) => void) & ((...msgs: unknown[]) => void);
|
|
146
|
+
matches(...tags: string[]): boolean;
|
|
147
|
+
propertyUpdated: ((key: string, value: unknown, oldValue?: unknown) => void) & ((_key: string, _value: unknown, _oldValue: unknown) => void);
|
|
148
|
+
emitEvent(event: string, data?: unknown, options?: unknown): void;
|
|
149
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
150
|
+
off(event: string, listener: (...args: never[]) => void): unknown;
|
|
151
|
+
extendWith<T>(...mixins: T[]): T & import("abstract-things").Thing;
|
|
152
|
+
readonly miioModel?: string;
|
|
153
|
+
readonly _properties: Record<string, unknown>;
|
|
154
|
+
readonly _propertiesToMonitor: string[];
|
|
155
|
+
readonly _propertyDefinitions: Record<string, import("./device").PersistedPropertyDefinition<never, never>>;
|
|
156
|
+
readonly _reversePropertyDefinitions: Record<string, string>;
|
|
157
|
+
readonly management: import("./management").DeviceManagement;
|
|
158
|
+
debugFn?: import("./logger").DebugFn;
|
|
159
|
+
readonly handle: import("./management").DeviceHandle;
|
|
160
|
+
miioCall<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params): Promise<Response>;
|
|
161
|
+
call<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params, options?: {
|
|
162
|
+
refresh?: string[];
|
|
163
|
+
refreshDelay?: number;
|
|
164
|
+
sid?: number;
|
|
165
|
+
retries?: number;
|
|
166
|
+
}): Promise<Response>;
|
|
167
|
+
defineProperty<T, V>(name: string, def?: import("./device").Mapper<T, V> | import("./device").PropertyDefinition<T, V> | undefined): void;
|
|
168
|
+
_pushProperty(result: Record<string, unknown>, name: string, value: unknown): void;
|
|
169
|
+
poll(_isInitial?: boolean): Promise<void>;
|
|
170
|
+
_loadProperties(properties?: string[]): Promise<void>;
|
|
171
|
+
setProperty(key: string, value: unknown): void;
|
|
172
|
+
setRawProperty(name: string, value: unknown): void;
|
|
173
|
+
property<T>(key: string): T;
|
|
174
|
+
get connected(): boolean;
|
|
175
|
+
get properties(): Record<string, unknown>;
|
|
176
|
+
miioProperties(): Record<string, unknown>;
|
|
177
|
+
getProperties(props: string[]): {};
|
|
178
|
+
loadProperties(props: string[]): Promise<{}>;
|
|
179
|
+
updatePollDuration(duration: number): void;
|
|
180
|
+
updateMaxPollFailures(failures: number): void;
|
|
181
|
+
} & import("abstract-things").Thing;
|
|
182
|
+
"lumi.acpartner.v3": new (options?: any) => {
|
|
183
|
+
extraChildren: any[];
|
|
184
|
+
_monitorInterval: number;
|
|
185
|
+
syncer: any;
|
|
186
|
+
_report(properties: any): void;
|
|
187
|
+
initCallback(): Promise<void>;
|
|
188
|
+
_deviceListTimer: NodeJS.Timeout | undefined;
|
|
189
|
+
destroyCallback(): Promise<void>;
|
|
190
|
+
addExtraChild(child: any): void;
|
|
191
|
+
_updateDeviceList(): Promise<any>;
|
|
192
|
+
_findDeveloperKey(): Promise<any>;
|
|
193
|
+
_setDeveloperKey(key: string): Promise<any>;
|
|
194
|
+
_developerKey: string | undefined;
|
|
195
|
+
devApi: import("./devices/gateway/developer-api") | undefined;
|
|
196
|
+
addDevice(): Promise<undefined>;
|
|
197
|
+
stopAddDevice(): Promise<undefined>;
|
|
198
|
+
removeDevice(id: string): Promise<undefined>;
|
|
199
|
+
id: string | null;
|
|
200
|
+
metadata: Record<string, unknown> & {
|
|
201
|
+
types: string[];
|
|
202
|
+
capabilities: string[];
|
|
203
|
+
addCapabilities(...capabilities: string[]): void;
|
|
204
|
+
};
|
|
205
|
+
init(): Promise</*elided*/ any | undefined>;
|
|
206
|
+
destroy(): Promise<void>;
|
|
207
|
+
debug: ((...parts: unknown[]) => void) & ((...msgs: unknown[]) => void);
|
|
208
|
+
matches(...tags: string[]): boolean;
|
|
209
|
+
propertyUpdated: ((key: string, value: unknown, oldValue?: unknown) => void) & ((_key: string, _value: unknown, _oldValue: unknown) => void);
|
|
210
|
+
emitEvent(event: string, data?: unknown, options?: unknown): void;
|
|
211
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
212
|
+
off(event: string, listener: (...args: never[]) => void): unknown;
|
|
213
|
+
extendWith<T>(...mixins: T[]): T & import("abstract-things").Thing;
|
|
214
|
+
readonly miioModel?: string;
|
|
215
|
+
readonly _properties: Record<string, unknown>;
|
|
216
|
+
readonly _propertiesToMonitor: string[];
|
|
217
|
+
readonly _propertyDefinitions: Record<string, import("./device").PersistedPropertyDefinition<never, never>>;
|
|
218
|
+
readonly _reversePropertyDefinitions: Record<string, string>;
|
|
219
|
+
readonly management: import("./management").DeviceManagement;
|
|
220
|
+
debugFn?: import("./logger").DebugFn;
|
|
221
|
+
readonly handle: import("./management").DeviceHandle;
|
|
222
|
+
miioCall<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params): Promise<Response>;
|
|
223
|
+
call<Method extends keyof import("./protocol").Protocol, Params extends import("./protocol").Protocol[Method]["params"], Response extends import("./protocol").Protocol[Method]["response"]>(method: Method, args: Params, options?: {
|
|
224
|
+
refresh?: string[];
|
|
225
|
+
refreshDelay?: number;
|
|
226
|
+
sid?: number;
|
|
227
|
+
retries?: number;
|
|
228
|
+
}): Promise<Response>;
|
|
229
|
+
defineProperty<T, V>(name: string, def?: import("./device").Mapper<T, V> | import("./device").PropertyDefinition<T, V> | undefined): void;
|
|
230
|
+
_pushProperty(result: Record<string, unknown>, name: string, value: unknown): void;
|
|
231
|
+
poll(_isInitial?: boolean): Promise<void>;
|
|
232
|
+
_loadProperties(properties?: string[]): Promise<void>;
|
|
233
|
+
setProperty(key: string, value: unknown): void;
|
|
234
|
+
setRawProperty(name: string, value: unknown): void;
|
|
235
|
+
property<T>(key: string): T;
|
|
236
|
+
get connected(): boolean;
|
|
237
|
+
get properties(): Record<string, unknown>;
|
|
238
|
+
miioProperties(): Record<string, unknown>;
|
|
239
|
+
getProperties(props: string[]): {};
|
|
240
|
+
loadProperties(props: string[]): Promise<{}>;
|
|
241
|
+
updatePollDuration(duration: number): void;
|
|
242
|
+
updateMaxPollFailures(failures: number): void;
|
|
243
|
+
} & import("abstract-things").Thing;
|
|
244
|
+
"qmi.powerstrip.v1": {
|
|
245
|
+
new (options: any): PowerStrip;
|
|
246
|
+
get type(): string;
|
|
247
|
+
};
|
|
248
|
+
"zimi.powerstrip.v2": {
|
|
249
|
+
new (options: any): PowerStrip;
|
|
250
|
+
get type(): string;
|
|
251
|
+
};
|
|
252
|
+
"yeelink.light.lamp1": {
|
|
253
|
+
new (): YeelightMono;
|
|
254
|
+
};
|
|
255
|
+
"yeelink.light.mono1": {
|
|
256
|
+
new (): YeelightMono;
|
|
257
|
+
};
|
|
258
|
+
"yeelink.light.color1": {
|
|
259
|
+
new (): YeelightColor;
|
|
260
|
+
};
|
|
261
|
+
"yeelink.light.strip1": {
|
|
262
|
+
new (): YeelightColor;
|
|
263
|
+
};
|
|
264
|
+
"philips.light.sread1": {
|
|
265
|
+
new (options: any): EyecareLamp2;
|
|
266
|
+
};
|
|
267
|
+
"philips.light.bulb": {
|
|
268
|
+
new (options: any): PhilipsLightBulb;
|
|
269
|
+
get type(): string;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import dgram from "node:dgram";
|
|
3
|
+
import { type MiioLogger } from "./logger";
|
|
4
|
+
import { DeviceInfo } from "./device_info";
|
|
5
|
+
export interface FindDeviceViaAddressOptions {
|
|
6
|
+
address: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
token?: string | Buffer;
|
|
9
|
+
model?: string;
|
|
10
|
+
/** Where the debug messages of this device go, in addition to the `debug` package */
|
|
11
|
+
logger?: MiioLogger;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Class for keeping track of the current network of devices. This is used to
|
|
15
|
+
* track a few things:
|
|
16
|
+
*
|
|
17
|
+
* 1) Mapping between addresses and device identifiers. Used when connecting to
|
|
18
|
+
* a device directly via IP or hostname.
|
|
19
|
+
*
|
|
20
|
+
* 2) Mapping between id and detailed device info such as the model.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
declare class Network extends EventEmitter {
|
|
24
|
+
private readonly packet;
|
|
25
|
+
private readonly addresses;
|
|
26
|
+
private readonly devices;
|
|
27
|
+
private references;
|
|
28
|
+
private debug;
|
|
29
|
+
private _socket;
|
|
30
|
+
constructor();
|
|
31
|
+
search(): void;
|
|
32
|
+
findDevice(id: number, rinfo: dgram.RemoteInfo): DeviceInfo | undefined;
|
|
33
|
+
findDeviceViaAddress(options: FindDeviceViaAddressOptions): Promise<DeviceInfo>;
|
|
34
|
+
/**
|
|
35
|
+
* Caches the device if not previously cached (could be the reason of failures when reconnecting?)
|
|
36
|
+
*
|
|
37
|
+
* @param device {@link DeviceInfo}
|
|
38
|
+
* @returns New device or the previously cached one
|
|
39
|
+
*/
|
|
40
|
+
cacheDevice(device: DeviceInfo): DeviceInfo;
|
|
41
|
+
createSocket(): void;
|
|
42
|
+
list(): MapIterator<DeviceInfo>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a reference to the network. Helps with locking of a socket.
|
|
45
|
+
*/
|
|
46
|
+
ref(): {
|
|
47
|
+
release: () => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Update wether the socket is available or not. Instead of always keeping
|
|
51
|
+
* a socket we track if it is available to allow Node to exit if no
|
|
52
|
+
* discovery or device is being used.
|
|
53
|
+
*/
|
|
54
|
+
updateSocket(): void;
|
|
55
|
+
get socket(): dgram.Socket;
|
|
56
|
+
}
|
|
57
|
+
export declare const network: Network;
|
|
58
|
+
export {};
|