mqtt2matter 0.3.1 → 0.4.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +18 -0
  3. package/dist/config/schema.d.ts +2 -0
  4. package/dist/engine/payload.d.ts +6 -3
  5. package/dist/engine/payload.js +8 -1
  6. package/dist/engine/payload.js.map +1 -1
  7. package/dist/engine/runtime.js +4 -0
  8. package/dist/engine/runtime.js.map +1 -1
  9. package/dist/engine/template.d.ts +1 -20
  10. package/dist/engine/template.js +4 -263
  11. package/dist/engine/template.js.map +1 -1
  12. package/dist/families/color.d.ts +3 -22
  13. package/dist/families/color.js +7 -144
  14. package/dist/families/color.js.map +1 -1
  15. package/dist/families/cover.js +52 -26
  16. package/dist/families/cover.js.map +1 -1
  17. package/dist/families/fan.d.ts +2 -0
  18. package/dist/families/fan.js +17 -0
  19. package/dist/families/fan.js.map +1 -1
  20. package/dist/families/index.d.ts +2 -0
  21. package/dist/families/index.js +2 -1
  22. package/dist/families/index.js.map +1 -1
  23. package/dist/importers/ha/areas.d.ts +1 -6
  24. package/dist/importers/ha/areas.js +5 -278
  25. package/dist/importers/ha/areas.js.map +1 -1
  26. package/dist/importers/ha/generate.d.ts +13 -1
  27. package/dist/importers/ha/generate.js +47 -4
  28. package/dist/importers/ha/generate.js.map +1 -1
  29. package/dist/importers/ha/source.d.ts +11 -9
  30. package/dist/importers/ha/source.js +22 -63
  31. package/dist/importers/ha/source.js.map +1 -1
  32. package/dist/importers/ha/sync.d.ts +11 -1
  33. package/dist/importers/ha/sync.js +88 -26
  34. package/dist/importers/ha/sync.js.map +1 -1
  35. package/dist/importers/ha/templates.d.ts +3 -14
  36. package/dist/importers/ha/templates.js +7 -248
  37. package/dist/importers/ha/templates.js.map +1 -1
  38. package/dist/importers/ha/types.d.ts +2 -78
  39. package/dist/importers/ha/types.js +1 -472
  40. package/dist/importers/ha/types.js.map +1 -1
  41. package/dist/importers/sync.d.ts +18 -1
  42. package/dist/importers/sync.js +35 -6
  43. package/dist/importers/sync.js.map +1 -1
  44. package/dist/importers/z2m/generate.js +1 -1
  45. package/dist/importers/z2m/generate.js.map +1 -1
  46. package/dist/matter/bridge.js +1 -1
  47. package/dist/matter/bridge.js.map +1 -1
  48. package/dist/matter/ids.d.ts +1 -1
  49. package/dist/matter/ids.js +2 -2
  50. package/dist/matter/ids.js.map +1 -1
  51. package/dist/model/options.d.ts +2 -0
  52. package/dist/model/options.js +8 -3
  53. package/dist/model/options.js.map +1 -1
  54. package/dist/model/schema.d.ts +13 -1
  55. package/dist/model/schema.js +16 -4
  56. package/dist/model/schema.js.map +1 -1
  57. package/dist/mqtt/client.d.ts +17 -3
  58. package/dist/mqtt/client.js +70 -13
  59. package/dist/mqtt/client.js.map +1 -1
  60. package/dist/server/config-store.js +2 -2
  61. package/dist/server/config-store.js.map +1 -1
  62. package/dist/server/importers.d.ts +4 -2
  63. package/dist/server/importers.js.map +1 -1
  64. package/dist/server/server.d.ts +5 -0
  65. package/dist/server/server.js +42 -1
  66. package/dist/server/server.js.map +1 -1
  67. package/docs/api.md +5 -5
  68. package/docs/architecture.md +1 -1
  69. package/docs/config.md +26 -20
  70. package/docs/importers.md +43 -17
  71. package/package.json +3 -2
  72. package/ui/dist/assets/index-Bl_bpL_0.js +10 -0
  73. package/ui/dist/assets/index-DsAb-xhK.css +1 -0
  74. package/ui/dist/index.html +2 -2
  75. package/ui/dist/licenses.json +1 -1
  76. package/ui/dist/assets/index-1HdbTkGD.css +0 -1
  77. package/ui/dist/assets/index-CoG5Wu5Q.js +0 -10
@@ -4,476 +4,5 @@
4
4
  `platform`. Keys may be abbreviated (`stat_t` for `state_topic`); `~` stands for a prefix at the start
5
5
  or end of every `*_topic` value; an empty retained payload removes the config. The tables are Home
6
6
  Assistant's `abbreviations.py`; the importer expands everything once and works on the long names. */
7
- /** the entity abbreviations (`ABBREVIATIONS` in abbreviations.py) */
8
- export const ABBREVIATIONS = {
9
- act_t: 'action_topic',
10
- act_tpl: 'action_template',
11
- act_stat_t: 'activity_state_topic',
12
- act_val_tpl: 'activity_value_template',
13
- atype: 'automation_type',
14
- av_tones: 'available_tones',
15
- avty: 'availability',
16
- avty_mode: 'availability_mode',
17
- avty_t: 'availability_topic',
18
- avty_tpl: 'availability_template',
19
- b_tpl: 'blue_template',
20
- bri_cmd_tpl: 'brightness_command_template',
21
- bri_cmd_t: 'brightness_command_topic',
22
- bri_scl: 'brightness_scale',
23
- bri_stat_t: 'brightness_state_topic',
24
- bri_tpl: 'brightness_template',
25
- bri_val_tpl: 'brightness_value_template',
26
- cln_segmnts_cmd_t: 'clean_segments_command_topic',
27
- cln_segmnts_cmd_tpl: 'clean_segments_command_template',
28
- clr_temp_cmd_tpl: 'color_temp_command_template',
29
- clrm_stat_t: 'color_mode_state_topic',
30
- clrm_val_tpl: 'color_mode_value_template',
31
- clr_temp_cmd_t: 'color_temp_command_topic',
32
- clr_temp_k: 'color_temp_kelvin',
33
- clr_temp_stat_t: 'color_temp_state_topic',
34
- clr_temp_tpl: 'color_temp_template',
35
- clr_temp_val_tpl: 'color_temp_value_template',
36
- cmd_off_tpl: 'command_off_template',
37
- cmd_on_tpl: 'command_on_template',
38
- cmd_t: 'command_topic',
39
- cmd_tpl: 'command_template',
40
- cmps: 'components',
41
- cod_arm_req: 'code_arm_required',
42
- cod_dis_req: 'code_disarm_required',
43
- cod_form: 'code_format',
44
- cod_trig_req: 'code_trigger_required',
45
- cont_type: 'content_type',
46
- curr_hum_t: 'current_humidity_topic',
47
- curr_hum_tpl: 'current_humidity_template',
48
- curr_temp_t: 'current_temperature_topic',
49
- curr_temp_tpl: 'current_temperature_template',
50
- def_ent_id: 'default_entity_id',
51
- dev: 'device',
52
- dev_cla: 'device_class',
53
- dir_cmd_t: 'direction_command_topic',
54
- dir_cmd_tpl: 'direction_command_template',
55
- dir_stat_t: 'direction_state_topic',
56
- dir_val_tpl: 'direction_value_template',
57
- dsp_prc: 'display_precision',
58
- dock_cmd_t: 'dock_command_topic',
59
- dock_cmd_tpl: 'dock_command_template',
60
- e: 'encoding',
61
- en: 'enabled_by_default',
62
- ent_cat: 'entity_category',
63
- ent_pic: 'entity_picture',
64
- evt_typ: 'event_types',
65
- fanspd_lst: 'fan_speed_list',
66
- flsh: 'flash',
67
- flsh_tlng: 'flash_time_long',
68
- flsh_tsht: 'flash_time_short',
69
- fx_cmd_tpl: 'effect_command_template',
70
- fx_cmd_t: 'effect_command_topic',
71
- fx_list: 'effect_list',
72
- fx_stat_t: 'effect_state_topic',
73
- fx_tpl: 'effect_template',
74
- fx_val_tpl: 'effect_value_template',
75
- exp_aft: 'expire_after',
76
- fan_mode_cmd_tpl: 'fan_mode_command_template',
77
- fan_mode_cmd_t: 'fan_mode_command_topic',
78
- fan_mode_stat_tpl: 'fan_mode_state_template',
79
- fan_mode_stat_t: 'fan_mode_state_topic',
80
- frc_upd: 'force_update',
81
- g_tpl: 'green_template',
82
- grp: 'group',
83
- hs_cmd_t: 'hs_command_topic',
84
- hs_cmd_tpl: 'hs_command_template',
85
- hs_stat_t: 'hs_state_topic',
86
- hs_val_tpl: 'hs_value_template',
87
- ic: 'icon',
88
- img_e: 'image_encoding',
89
- img_t: 'image_topic',
90
- init: 'initial',
91
- hum_cmd_t: 'target_humidity_command_topic',
92
- hum_cmd_tpl: 'target_humidity_command_template',
93
- hum_stat_t: 'target_humidity_state_topic',
94
- hum_state_tpl: 'target_humidity_state_template',
95
- json_attr: 'json_attributes',
96
- json_attr_t: 'json_attributes_topic',
97
- json_attr_tpl: 'json_attributes_template',
98
- lrst_val_tpl: 'last_reset_value_template',
99
- max: 'max',
100
- min: 'min',
101
- max_hum: 'max_humidity',
102
- min_hum: 'min_humidity',
103
- max_mirs: 'max_mireds',
104
- min_mirs: 'min_mireds',
105
- max_k: 'max_kelvin',
106
- min_k: 'min_kelvin',
107
- max_temp: 'max_temp',
108
- min_temp: 'min_temp',
109
- migr_discvry: 'migrate_discovery',
110
- mode: 'mode',
111
- mode_cmd_tpl: 'mode_command_template',
112
- mode_cmd_t: 'mode_command_topic',
113
- mode_stat_t: 'mode_state_topic',
114
- mode_stat_tpl: 'mode_state_template',
115
- modes: 'modes',
116
- msg_exp_int: 'message_expiry_interval',
117
- name: 'name',
118
- o: 'origin',
119
- off_dly: 'off_delay',
120
- on_cmd_type: 'on_command_type',
121
- ops: 'options',
122
- opt: 'optimistic',
123
- osc_cmd_t: 'oscillation_command_topic',
124
- osc_cmd_tpl: 'oscillation_command_template',
125
- osc_stat_t: 'oscillation_state_topic',
126
- osc_val_tpl: 'oscillation_value_template',
127
- p: 'platform',
128
- pause_cmd_t: 'pause_command_topic',
129
- pause_mw_cmd_tpl: 'pause_command_template',
130
- pct_cmd_t: 'percentage_command_topic',
131
- pct_cmd_tpl: 'percentage_command_template',
132
- pct_stat_t: 'percentage_state_topic',
133
- pct_val_tpl: 'percentage_value_template',
134
- pl: 'payload',
135
- pl_arm_away: 'payload_arm_away',
136
- pl_arm_home: 'payload_arm_home',
137
- pl_arm_nite: 'payload_arm_night',
138
- pl_arm_vacation: 'payload_arm_vacation',
139
- pl_arm_custom_b: 'payload_arm_custom_bypass',
140
- pl_avail: 'payload_available',
141
- pl_cln_sp: 'payload_clean_spot',
142
- pl_cls: 'payload_close',
143
- pl_disarm: 'payload_disarm',
144
- pl_home: 'payload_home',
145
- pl_lock: 'payload_lock',
146
- pl_loc: 'payload_locate',
147
- pl_not_avail: 'payload_not_available',
148
- pl_not_home: 'payload_not_home',
149
- pl_off: 'payload_off',
150
- pl_on: 'payload_on',
151
- pl_open: 'payload_open',
152
- pl_osc_off: 'payload_oscillation_off',
153
- pl_osc_on: 'payload_oscillation_on',
154
- pl_paus: 'payload_pause',
155
- pl_prs: 'payload_press',
156
- pl_rst: 'payload_reset',
157
- pl_rst_hum: 'payload_reset_humidity',
158
- pl_rst_mode: 'payload_reset_mode',
159
- pl_rst_pct: 'payload_reset_percentage',
160
- pl_rst_pr_mode: 'payload_reset_preset_mode',
161
- pl_stop: 'payload_stop',
162
- pl_stop_tilt: 'payload_stop_tilt',
163
- pl_strt: 'payload_start',
164
- pl_ret: 'payload_return_to_base',
165
- pl_toff: 'payload_turn_off',
166
- pl_ton: 'payload_turn_on',
167
- pl_trig: 'payload_trigger',
168
- pl_unlk: 'payload_unlock',
169
- pos: 'reports_position',
170
- pos_clsd: 'position_closed',
171
- pos_open: 'position_open',
172
- pow_cmd_t: 'power_command_topic',
173
- pow_cmd_tpl: 'power_command_template',
174
- pr_mode_cmd_t: 'preset_mode_command_topic',
175
- pr_mode_cmd_tpl: 'preset_mode_command_template',
176
- pr_mode_stat_t: 'preset_mode_state_topic',
177
- pr_mode_val_tpl: 'preset_mode_value_template',
178
- pr_modes: 'preset_modes',
179
- ptrn: 'pattern',
180
- r_tpl: 'red_template',
181
- rel_s: 'release_summary',
182
- rel_u: 'release_url',
183
- ret: 'retain',
184
- rgb_cmd_tpl: 'rgb_command_template',
185
- rgb_cmd_t: 'rgb_command_topic',
186
- rgb_stat_t: 'rgb_state_topic',
187
- rgb_val_tpl: 'rgb_value_template',
188
- rgbw_cmd_tpl: 'rgbw_command_template',
189
- rgbw_cmd_t: 'rgbw_command_topic',
190
- rgbw_stat_t: 'rgbw_state_topic',
191
- rgbw_val_tpl: 'rgbw_value_template',
192
- rgbww_cmd_tpl: 'rgbww_command_template',
193
- rgbww_cmd_t: 'rgbww_command_topic',
194
- rgbww_stat_t: 'rgbww_state_topic',
195
- rgbww_val_tpl: 'rgbww_value_template',
196
- send_cmd_t: 'send_command_topic',
197
- send_if_off: 'send_if_off',
198
- set_fan_spd_t: 'set_fan_speed_topic',
199
- set_pos_tpl: 'set_position_template',
200
- set_pos_t: 'set_position_topic',
201
- pos_t: 'position_topic',
202
- pos_tpl: 'position_template',
203
- spd_rng_min: 'speed_range_min',
204
- spd_rng_max: 'speed_range_max',
205
- src_type: 'source_type',
206
- stat_cla: 'state_class',
207
- stat_clsd: 'state_closed',
208
- stat_closing: 'state_closing',
209
- stat_jam: 'state_jammed',
210
- stat_off: 'state_off',
211
- stat_on: 'state_on',
212
- stat_open: 'state_open',
213
- stat_opening: 'state_opening',
214
- stat_stopped: 'state_stopped',
215
- stat_locked: 'state_locked',
216
- stat_locking: 'state_locking',
217
- stat_unlocked: 'state_unlocked',
218
- stat_unlocking: 'state_unlocking',
219
- stat_t: 'state_topic',
220
- stat_tpl: 'state_template',
221
- stat_val_tpl: 'state_value_template',
222
- step: 'step',
223
- stop_cmd_t: 'stop_command_topic',
224
- stop_cmd_tpl: 'stop_command_template',
225
- strt_mw_cmd_t: 'start_mowing_command_topic',
226
- strt_mw_cmd_tpl: 'start_mowing_command_template',
227
- stype: 'subtype',
228
- sug_dsp_prc: 'suggested_display_precision',
229
- sup_dur: 'support_duration',
230
- sup_vol: 'support_volume_set',
231
- sup_feat: 'supported_features',
232
- sup_clrm: 'supported_color_modes',
233
- swing_h_mode_cmd_tpl: 'swing_horizontal_mode_command_template',
234
- swing_h_mode_cmd_t: 'swing_horizontal_mode_command_topic',
235
- swing_h_mode_stat_tpl: 'swing_horizontal_mode_state_template',
236
- swing_h_mode_stat_t: 'swing_horizontal_mode_state_topic',
237
- swing_h_modes: 'swing_horizontal_modes',
238
- swing_mode_cmd_tpl: 'swing_mode_command_template',
239
- swing_mode_cmd_t: 'swing_mode_command_topic',
240
- swing_mode_stat_tpl: 'swing_mode_state_template',
241
- swing_mode_stat_t: 'swing_mode_state_topic',
242
- swing_modes: 'swing_modes',
243
- temp_cmd_tpl: 'temperature_command_template',
244
- temp_cmd_t: 'temperature_command_topic',
245
- temp_hi_cmd_tpl: 'temperature_high_command_template',
246
- temp_hi_cmd_t: 'temperature_high_command_topic',
247
- temp_hi_stat_tpl: 'temperature_high_state_template',
248
- temp_hi_stat_t: 'temperature_high_state_topic',
249
- temp_lo_cmd_tpl: 'temperature_low_command_template',
250
- temp_lo_cmd_t: 'temperature_low_command_topic',
251
- temp_lo_stat_tpl: 'temperature_low_state_template',
252
- temp_lo_stat_t: 'temperature_low_state_topic',
253
- temp_stat_tpl: 'temperature_state_template',
254
- temp_stat_t: 'temperature_state_topic',
255
- temp_unit: 'temperature_unit',
256
- tilt_clsd_val: 'tilt_closed_value',
257
- tilt_cmd_t: 'tilt_command_topic',
258
- tilt_cmd_tpl: 'tilt_command_template',
259
- tilt_max: 'tilt_max',
260
- tilt_min: 'tilt_min',
261
- tilt_opnd_val: 'tilt_opened_value',
262
- tilt_opt: 'tilt_optimistic',
263
- tilt_status_t: 'tilt_status_topic',
264
- tilt_status_tpl: 'tilt_status_template',
265
- tit: 'title',
266
- t: 'topic',
267
- trns: 'transition',
268
- tz: 'timezone',
269
- uniq_id: 'unique_id',
270
- unit_of_meas: 'unit_of_measurement',
271
- url_t: 'url_topic',
272
- url_tpl: 'url_template',
273
- val_tpl: 'value_template',
274
- whit_cmd_t: 'white_command_topic',
275
- whit_scl: 'white_scale',
276
- xy_cmd_t: 'xy_command_topic',
277
- xy_cmd_tpl: 'xy_command_template',
278
- xy_stat_t: 'xy_state_topic',
279
- xy_val_tpl: 'xy_value_template',
280
- l_ver_t: 'latest_version_topic',
281
- l_ver_tpl: 'latest_version_template',
282
- pl_inst: 'payload_install',
283
- vis: 'visible_by_default',
284
- };
285
- /** the `device` block's abbreviations (`DEVICE_ABBREVIATIONS`) */
286
- export const DEVICE_ABBREVIATIONS = {
287
- cns: 'connections',
288
- cu: 'configuration_url',
289
- ids: 'identifiers',
290
- name: 'name',
291
- mf: 'manufacturer',
292
- mdl: 'model',
293
- mdl_id: 'model_id',
294
- hw: 'hw_version',
295
- sw: 'sw_version',
296
- sa: 'suggested_area',
297
- sn: 'serial_number',
298
- };
299
- /** the `origin` block's abbreviations (`ORIGIN_ABBREVIATIONS`) */
300
- export const ORIGIN_ABBREVIATIONS = {
301
- name: 'name',
302
- sw: 'sw_version',
303
- url: 'support_url',
304
- };
305
- function isRecord(value) {
306
- return typeof value === 'object' && value !== null && !Array.isArray(value);
307
- }
308
- function expandKeys(value, table) {
309
- const out = {};
310
- for (const [key, v] of Object.entries(value)) {
311
- out[table[key] ?? key] = v;
312
- }
313
- return out;
314
- }
315
- /** `~` at the start or end of a topic value */
316
- function substituteBase(value, base) {
317
- if (base === undefined || typeof value !== 'string') {
318
- return value;
319
- }
320
- if (value.startsWith('~')) {
321
- return base + value.slice(1);
322
- }
323
- if (value.endsWith('~')) {
324
- return value.slice(0, -1) + base;
325
- }
326
- return value;
327
- }
328
- function isTopicKey(key) {
329
- return key === 'topic' || key.endsWith('_topic');
330
- }
331
- /** every abbreviation expanded and `~` substituted, in the entity itself, its availability list, device and origin */
332
- export function expandEntity(raw, inherited = {}) {
333
- const expanded = expandKeys(raw, ABBREVIATIONS);
334
- const base = typeof expanded['~'] === 'string' ? expanded['~'] : undefined;
335
- delete expanded['~'];
336
- const out = {};
337
- for (const [key, value] of Object.entries(expanded)) {
338
- if (key === 'device' && isRecord(value)) {
339
- out.device = expandKeys(value, DEVICE_ABBREVIATIONS);
340
- }
341
- else if (key === 'origin' && isRecord(value)) {
342
- out.origin = expandKeys(value, ORIGIN_ABBREVIATIONS);
343
- }
344
- else if (key === 'availability') {
345
- out.availability = normaliseAvailability(value, base);
346
- }
347
- else if (isTopicKey(key)) {
348
- out[key] = substituteBase(value, base);
349
- }
350
- else {
351
- out[key] = value;
352
- }
353
- }
354
- // the device-based form: the root's device, origin, availability, qos, encoding, state and command topic
355
- // apply to every component that does not set them
356
- for (const [key, value] of Object.entries(inherited)) {
357
- if (!(key in out)) {
358
- out[key] = value;
359
- }
360
- }
361
- return out;
362
- }
363
- /** `availability` as a list of entries with long names, `~` substituted; a single object becomes a list */
364
- function normaliseAvailability(value, base) {
365
- const list = Array.isArray(value) ? value : isRecord(value) ? [value] : undefined;
366
- if (list === undefined) {
367
- return undefined;
368
- }
369
- const entries = [];
370
- for (const item of list) {
371
- if (!isRecord(item)) {
372
- continue;
373
- }
374
- const expanded = expandKeys(item, ABBREVIATIONS);
375
- const topic = substituteBase(expanded.topic, base);
376
- if (typeof topic !== 'string' || topic === '') {
377
- continue;
378
- }
379
- const entry = { topic };
380
- if (typeof expanded.payload_available === 'string') {
381
- entry.payload_available = expanded.payload_available;
382
- }
383
- if (typeof expanded.payload_not_available === 'string') {
384
- entry.payload_not_available = expanded.payload_not_available;
385
- }
386
- if (typeof expanded.value_template === 'string') {
387
- entry.value_template = expanded.value_template;
388
- }
389
- entries.push(entry);
390
- }
391
- return entries;
392
- }
393
- /** the keys of a device-based payload every component inherits */
394
- const SHARED_KEYS = [
395
- 'device',
396
- 'origin',
397
- 'availability',
398
- 'availability_topic',
399
- 'availability_mode',
400
- 'availability_template',
401
- 'payload_available',
402
- 'payload_not_available',
403
- 'qos',
404
- 'encoding',
405
- 'state_topic',
406
- 'command_topic',
407
- ];
408
- /** the device-based form: `components` each with a `platform`; returns the entities with the shared fields applied */
409
- export function expandDevicePayload(raw) {
410
- const root = expandEntity(raw);
411
- const inherited = {};
412
- for (const key of SHARED_KEYS) {
413
- if (root[key] !== undefined) {
414
- inherited[key] = root[key];
415
- }
416
- }
417
- const components = {};
418
- const list = isRecord(root.components) ? root.components : {};
419
- for (const [key, value] of Object.entries(list)) {
420
- if (!isRecord(value)) {
421
- continue;
422
- }
423
- // a component reduced to its platform alone is Home Assistant's way of removing it
424
- if (Object.keys(value).every((k) => k === 'p' || k === 'platform')) {
425
- continue;
426
- }
427
- components[key] = expandEntity(value, inherited);
428
- }
429
- return {
430
- components,
431
- ...(root.device === undefined ? {} : { device: root.device }),
432
- ...(root.origin === undefined ? {} : { origin: root.origin }),
433
- };
434
- }
435
- /** `<prefix>/<component>/[<node_id>/]<object_id>/config`, or undefined for any other topic under the prefix */
436
- export function parseDiscoveryTopic(prefix, topic) {
437
- if (!topic.startsWith(`${prefix}/`)) {
438
- return undefined;
439
- }
440
- const parts = topic.slice(prefix.length + 1).split('/');
441
- if (parts.at(-1) !== 'config') {
442
- return undefined;
443
- }
444
- const component = parts[0];
445
- if (component === undefined || component === '') {
446
- return undefined;
447
- }
448
- if (parts.length === 3) {
449
- return parts[1] === '' ? undefined : { component, objectId: parts[1] ?? '' };
450
- }
451
- if (parts.length === 4) {
452
- return parts[1] === '' || parts[2] === ''
453
- ? undefined
454
- : { component, nodeId: parts[1] ?? '', objectId: parts[2] ?? '' };
455
- }
456
- return undefined;
457
- }
458
- /** the device key material: the first identifier, else the first connection (`mac:…`) */
459
- export function deviceIdentity(device) {
460
- if (device === undefined) {
461
- return undefined;
462
- }
463
- const ids = device.identifiers;
464
- if (typeof ids === 'string' && ids !== '') {
465
- return ids;
466
- }
467
- if (Array.isArray(ids)) {
468
- const first = ids.find((id) => typeof id === 'string' && id !== '');
469
- if (first !== undefined) {
470
- return first;
471
- }
472
- }
473
- const connection = Array.isArray(device.connections) ? device.connections[0] : undefined;
474
- if (Array.isArray(connection) && typeof connection[0] === 'string' && typeof connection[1] === 'string') {
475
- return `${connection[0]}:${connection[1]}`;
476
- }
477
- return undefined;
478
- }
7
+ export { ABBREVIATIONS, DEVICE_ABBREVIATIONS, ORIGIN_ABBREVIATIONS, expandEntity, expandDevicePayload, parseDiscoveryTopic, deviceIdentity, } from 'mqtt-ha-entities';
479
8
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/importers/ha/types.ts"],"names":[],"mappings":"AAAA;;;;;uGAKuG;AAEvG,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC3D,KAAK,EAAE,cAAc;IACrB,OAAO,EAAE,iBAAiB;IAC1B,UAAU,EAAE,sBAAsB;IAClC,WAAW,EAAE,yBAAyB;IACtC,KAAK,EAAE,iBAAiB;IACxB,QAAQ,EAAE,iBAAiB;IAC3B,IAAI,EAAE,cAAc;IACpB,SAAS,EAAE,mBAAmB;IAC9B,MAAM,EAAE,oBAAoB;IAC5B,QAAQ,EAAE,uBAAuB;IACjC,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,6BAA6B;IAC1C,S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O,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/importers/ha/types.ts"],"names":[],"mappings":"AAAA;;;;;uGAKuG;AAEvG,OAAO,EACH,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,GACjB,MAAM,kBAAkB,CAAC"}
@@ -23,6 +23,16 @@ export interface Discovered {
23
23
  reason?: string;
24
24
  baseline?: DeviceInput;
25
25
  unmapped: string[];
26
+ /** Home Assistant: the binary sensors announced without a class, each with the class chosen for it */
27
+ unclassed?: UnclassedEntity[];
28
+ }
29
+ /** a binary sensor announced without a class, which the user can give one */
30
+ export interface UnclassedEntity {
31
+ /** the entity's id within the device */
32
+ id: string;
33
+ name: string;
34
+ /** the class the user chose, when one is stored */
35
+ class?: string;
26
36
  }
27
37
  export type SyncStatus =
28
38
  /** described by the source, not in the config */
@@ -59,6 +69,8 @@ export interface SyncEntry {
59
69
  covered?: string;
60
70
  /** the configured devices (not disabled, not orphaned) that stand for the same physical device */
61
71
  twins?: string[];
72
+ /** Home Assistant: the binary sensors announced without a class, each with the class chosen for it */
73
+ unclassed?: UnclassedEntity[];
62
74
  }
63
75
  export interface AdoptOptions {
64
76
  /** the new devices to add; default: every supported one */
@@ -99,7 +111,12 @@ export declare class Sync<Raw> {
99
111
  constructor(source: SyncSource<Raw>);
100
112
  isOwn(device: DeviceInput): boolean;
101
113
  orphaned(devices: DevicesInput): string[];
102
- /** the old baseline from `source.raw`, or undefined when it cannot be regenerated */
114
+ /**
115
+ * The baseline the device was adopted or last re-synced from: `source.baseline` as stored then. A device
116
+ * stored without one (adopted before the baseline was kept) gets it regenerated from `source.raw` with
117
+ * today's generator — which cannot tell a change of the generator since from an edit of the user's.
118
+ * Undefined when there is neither.
119
+ */
103
120
  private oldBaselineOf;
104
121
  /** the user's edits of a device against its baseline; empty when it is untouched or has no baseline */
105
122
  edits(device: DeviceInput): ReturnType<typeof editsOf>;
@@ -1,16 +1,34 @@
1
1
  /* What every importer does with its discoveries, once: the report over a `devices` record (`diff`) and the
2
- adoption (`adopt`) — new entries added, known ones re-synced from their stored `source.raw` with the
3
- user's edits carried over and conflicts reported, missing ones marked orphaned and never removed,
2
+ adoption (`adopt`) — new entries added, known ones re-synced: the baseline they were adopted or last
3
+ re-synced from (`source.baseline`) against the one generated now, the user's edits carried over and
4
+ conflicts reported, missing ones marked orphaned and never removed,
4
5
  orphaned ones restored when they are back, manual devices untouched. An importer brings its kind, how
5
6
  to recognise and regenerate its `source.raw`, and its discovery; everything else is here. */
6
7
  import { DeviceSchema } from "../model/index.js";
7
- import { deepEqual, editsOf, resync } from "./patch.js";
8
+ import { deepEqual, editsOf, isRecord, resync } from "./patch.js";
8
9
  import { isLive, twinsOf } from "./twins.js";
9
10
  function withoutSource(device) {
10
11
  const rest = structuredClone(device);
11
12
  delete rest.source;
12
13
  return rest;
13
14
  }
15
+ /** a stored `source.baseline` that looks like a device (its endpoints a list), else undefined */
16
+ function storedBaseline(device) {
17
+ const baseline = device.source?.baseline;
18
+ if (!isRecord(baseline) || !Array.isArray(baseline.endpoints)) {
19
+ return undefined;
20
+ }
21
+ return baseline;
22
+ }
23
+ /** a generated baseline's `source` with the baseline itself stored in it (without its own `source`), so a later
24
+ re-sync tells the user's edits from what the generator produced then */
25
+ function sourceWithBaseline(baseline) {
26
+ return { ...structuredClone(baseline.source ?? { kind: 'manual' }), baseline: withoutSource(baseline) };
27
+ }
28
+ /** a new device as adopted: the generated baseline, with itself stored in its source */
29
+ function adoptedDevice(baseline) {
30
+ return { ...structuredClone(baseline), source: sourceWithBaseline(baseline) };
31
+ }
14
32
  function validationNotes(device) {
15
33
  const parsed = DeviceSchema.safeParse(device);
16
34
  return parsed.success ? [] : parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`);
@@ -48,8 +66,17 @@ export class Sync {
48
66
  .filter(([, device]) => this.isOwn(device) && device.source?.orphaned === true)
49
67
  .map(([key]) => key);
50
68
  }
51
- /** the old baseline from `source.raw`, or undefined when it cannot be regenerated */
69
+ /**
70
+ * The baseline the device was adopted or last re-synced from: `source.baseline` as stored then. A device
71
+ * stored without one (adopted before the baseline was kept) gets it regenerated from `source.raw` with
72
+ * today's generator — which cannot tell a change of the generator since from an edit of the user's.
73
+ * Undefined when there is neither.
74
+ */
52
75
  oldBaselineOf(current) {
76
+ const stored = storedBaseline(current);
77
+ if (stored !== undefined) {
78
+ return stored;
79
+ }
53
80
  const raw = current.source?.raw;
54
81
  return this.source.isRaw(raw) ? this.source.generate(raw)?.device : undefined;
55
82
  }
@@ -70,6 +97,7 @@ export class Sync {
70
97
  notes: [],
71
98
  ...(item.area === undefined ? {} : { area: item.area }),
72
99
  ...(item.native === undefined ? {} : { native: item.native }),
100
+ ...(item.unclassed === undefined ? {} : { unclassed: item.unclassed }),
73
101
  };
74
102
  const wasOrphaned = current.source?.orphaned === true;
75
103
  const newBaseline = item.baseline;
@@ -90,7 +118,7 @@ export class Sync {
90
118
  }
91
119
  const result = resync(oldBaseline, current, newBaseline);
92
120
  const device = result.device;
93
- device.source = structuredClone(newBaseline.source);
121
+ device.source = sourceWithBaseline(newBaseline);
94
122
  const notes = validationNotes(device);
95
123
  if (notes.length > 0) {
96
124
  const kept = structuredClone(current);
@@ -154,13 +182,14 @@ export class Sync {
154
182
  status: !item.supported ? 'unsupported' : covered === undefined ? 'new' : 'covered',
155
183
  ...(item.supported && covered !== undefined ? { covered } : {}),
156
184
  ...(twins.length > 0 ? { twins } : {}),
157
- ...(item.baseline === undefined ? {} : { device: item.baseline }),
185
+ ...(item.baseline === undefined ? {} : { device: adoptedDevice(item.baseline) }),
158
186
  conflicts: [],
159
187
  edits: 0,
160
188
  unmapped: item.unmapped,
161
189
  notes: item.reason === undefined ? [] : [item.reason],
162
190
  ...(item.area === undefined ? {} : { area: item.area }),
163
191
  ...(item.native === undefined ? {} : { native: item.native }),
192
+ ...(item.unclassed === undefined ? {} : { unclassed: item.unclassed }),
164
193
  });
165
194
  }
166
195
  return entries;