matterbridge-ha-roborock 3.0.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.
@@ -0,0 +1,109 @@
1
+ export interface RoborockPlatformConfig {
2
+ /** Home Assistant base URL, e.g. http://10.10.10.215:8123 */
3
+ haUrl: string;
4
+
5
+ /** Home Assistant Long-Lived Access Token */
6
+ haToken: string;
7
+
8
+ /** Matter 运行模式:server(推荐 Apple Home)或 matter */
9
+ matterMode?: 'server' | 'matter';
10
+
11
+ /** 只允许注册的 vacuum entity_id 列表 */
12
+ deviceWhitelist?: string[];
13
+
14
+ /** 禁止注册的 vacuum entity_id 列表 */
15
+ deviceBlacklist?: string[];
16
+
17
+ /** 轮询间隔(毫秒) */
18
+ pollInterval?: number;
19
+
20
+ /** 是否开启 debug 日志 */
21
+ debug?: boolean;
22
+
23
+ /**
24
+ * 电池电量传感器映射
25
+ * key: vacuum entity_id
26
+ * value: 对应的电池传感器 entity_id
27
+ * 例如: { "vacuum.dreame_vacuum_r2254": "sensor.dreame_vacuum_r2254_battery_level" }
28
+ */
29
+ batterySensorMap?: Record<string, string>;
30
+
31
+ /**
32
+ * 充电状态传感器映射
33
+ * key: vacuum entity_id
34
+ * value: 对应的充电状态传感器 entity_id
35
+ * 例如: { "vacuum.dreame_vacuum_r2254": "binary_sensor.dreame_vacuum_r2254_charging_state" }
36
+ */
37
+ chargingSensorMap?: Record<string, string>;
38
+
39
+ /**
40
+ * 清洁模式选择器映射
41
+ * key: vacuum entity_id
42
+ * value: 对应的清洁模式选择器 entity_id
43
+ * 例如: { "vacuum.dreame_vacuum_r2254": "select.dreame_vacuum_r2254_cleaning_mode" }
44
+ */
45
+ cleaningModeEntityMap?: Record<string, string>;
46
+
47
+ /**
48
+ * 错误传感器映射
49
+ * key: vacuum entity_id
50
+ * value: 对应的错误传感器 entity_id
51
+ * 例如: { "vacuum.dreame_vacuum_r2254": "sensor.dreame_vacuum_r2254_error" }
52
+ */
53
+ errorSensorMap?: Record<string, string>;
54
+ }
55
+
56
+ export function validateConfig(config: any): RoborockPlatformConfig {
57
+ if (!config || typeof config !== 'object') {
58
+ throw new Error('Config must be an object');
59
+ }
60
+
61
+ if (!config.haUrl) {
62
+ throw new Error('haUrl is required');
63
+ }
64
+
65
+ if (!config.haToken) {
66
+ throw new Error('haToken is required');
67
+ }
68
+
69
+ // 去掉 haUrl 末尾的 /
70
+ config.haUrl = String(config.haUrl).replace(/\/$/, '');
71
+
72
+ // 默认轮询 30 秒
73
+ if (!config.pollInterval || typeof config.pollInterval !== 'number') {
74
+ config.pollInterval = 30000;
75
+ }
76
+
77
+ // Apple Home 兼容性最好:server
78
+ if (!config.matterMode) {
79
+ config.matterMode = 'server';
80
+ }
81
+
82
+ // 规范化 whitelist / blacklist
83
+ if (config.deviceWhitelist && !Array.isArray(config.deviceWhitelist)) {
84
+ throw new Error('deviceWhitelist must be an array of strings');
85
+ }
86
+
87
+ if (config.deviceBlacklist && !Array.isArray(config.deviceBlacklist)) {
88
+ throw new Error('deviceBlacklist must be an array of strings');
89
+ }
90
+
91
+ // 验证传感器映射
92
+ if (config.batterySensorMap && typeof config.batterySensorMap !== 'object') {
93
+ throw new Error('batterySensorMap must be an object');
94
+ }
95
+
96
+ if (config.chargingSensorMap && typeof config.chargingSensorMap !== 'object') {
97
+ throw new Error('chargingSensorMap must be an object');
98
+ }
99
+
100
+ if (config.cleaningModeEntityMap && typeof config.cleaningModeEntityMap !== 'object') {
101
+ throw new Error('cleaningModeEntityMap must be an object');
102
+ }
103
+
104
+ if (config.errorSensorMap && typeof config.errorSensorMap !== 'object') {
105
+ throw new Error('errorSensorMap must be an object');
106
+ }
107
+
108
+ return config as RoborockPlatformConfig;
109
+ }