homey-lib 2.35.2 → 2.35.4

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/lib/App/index.js CHANGED
@@ -60,6 +60,18 @@ const BATTERY_CAPABILITIES = [
60
60
  'alarm_battery',
61
61
  ];
62
62
 
63
+ const RESERVED_SETTING_PREFIXES = new Set([
64
+ 'homey:',
65
+ 'zw_',
66
+ 'zb_',
67
+ 'mtr_',
68
+ 'thread_',
69
+ 'zone_',
70
+ 'energy_',
71
+ 'satellite_mode_',
72
+ 'homekit_',
73
+ ])
74
+
63
75
  class App {
64
76
 
65
77
  constructor(path) {
@@ -355,47 +367,9 @@ class App {
355
367
  }
356
368
  }
357
369
 
358
-
359
- const reservedPrefixes = new Set([
360
- 'homey:',
361
- 'zw_',
362
- 'zb_',
363
- 'mtr_',
364
- 'thread_',
365
- 'zone_',
366
- 'energy_',
367
- 'satellite_mode_',
368
- 'homekit_',
369
- ])
370
-
371
370
  if (Array.isArray(driver.settings)) {
372
371
  for (const setting of driver.settings) {
373
- if (
374
- setting.type &&
375
- setting.type === "group" &&
376
- setting.children &&
377
- Array.isArray(setting.children)
378
- ) {
379
- for (const childSettings of setting.children) {
380
- for (const prefix of reservedPrefixes) {
381
- if (childSettings.id.startsWith(prefix)) {
382
- console.warn(
383
- `drivers.${driver.id} invalid setting id: ${setting.id}, cannot start with reserved prefix: ${prefix}`
384
- );
385
- // throw new Error(`drivers.${driver.id} invalid setting id: ${setting.id}, cannot start with reserved prefix: ${prefix}`);
386
- }
387
- }
388
- }
389
- } else {
390
- for (const prefix of reservedPrefixes) {
391
- if (setting.id.startsWith(prefix)) {
392
- console.warn(
393
- `drivers.${driver.id} invalid setting id: ${setting.id}, cannot start with reserved prefix: ${prefix}`
394
- );
395
- // throw new Error(`drivers.${driver.id} invalid setting id: ${setting.id}, cannot start with reserved prefix: ${prefix}`);
396
- }
397
- }
398
- }
372
+ this._checkPrivateSettingPrefixUse(setting, driver);
399
373
  }
400
374
  }
401
375
 
@@ -491,16 +465,18 @@ class App {
491
465
  });
492
466
  }
493
467
 
494
- if (driver.energy.cumulative === true) {
468
+ const hasMeterPowerCapability = driver.capabilities.some(capability => Capability.isInstanceOfId(capability, 'meter_power'));
469
+
470
+ if (driver.energy.cumulative === true && hasMeterPowerCapability) {
495
471
  if (typeof driver.energy.cumulativeImportedCapability !== 'string') {
496
- console.warn(`Warning: drivers.${driver.id} has energy.cumulative set to true, but is missing 'cumulativeImportedCapability'. Disregard this warning if the driver does not have \`meter_power\` capabilities.`);
472
+ console.warn(`Warning: drivers.${driver.id} has energy.cumulative set to true, but is missing 'cumulativeImportedCapability'.`);
497
473
  }
498
474
  if (typeof driver.energy.cumulativeExportedCapability !== 'string') {
499
- console.warn(`Warning: drivers.${driver.id} has energy.cumulative set to true, but is missing 'cumulativeExportedCapability'. Disregard this warning if the driver does not have \`meter_power\` capabilities.`);
475
+ console.warn(`Warning: drivers.${driver.id} has energy.cumulative set to true, but is missing 'cumulativeExportedCapability'.`);
500
476
  }
501
477
  }
502
478
 
503
- if (driver.energy.homeBattery === true) {
479
+ if (driver.energy.homeBattery === true && hasMeterPowerCapability) {
504
480
  if (typeof driver.energy.meterPowerImportedCapability !== 'string') {
505
481
  console.warn(`Warning: drivers.${driver.id} has energy.homeBattery set to true, but is missing 'meterPowerImportedCapability'.`);
506
482
  }
@@ -509,6 +485,12 @@ class App {
509
485
  }
510
486
  }
511
487
 
488
+ if (driver.energy.evCharger === true && hasMeterPowerCapability) {
489
+ if (typeof driver.energy.meterPowerImportedCapability !== 'string') {
490
+ console.warn(`Warning: drivers.${driver.id} has energy.evCharger set to true, but is missing 'meterPowerImportedCapability'.`);
491
+ }
492
+ }
493
+
512
494
  if (typeof driver.energy.cumulativeImportedCapability === 'string' && Capability.isInstanceOfId(driver.energy.cumulativeImportedCapability, 'meter_power') === false) {
513
495
  throw new Error(`drivers.${driver.id} has 'cumulativeImportedCapability': '${driver.energy.cumulativeImportedCapability}' but only instances of 'meter_power' are allowed.`);
514
496
  }
@@ -719,6 +701,27 @@ class App {
719
701
  this.debug('Validated successfully');
720
702
  }
721
703
 
704
+ _checkPrivateSettingPrefixUse(setting, driver) {
705
+ if (
706
+ setting.type &&
707
+ setting.type === "group" &&
708
+ setting.children &&
709
+ Array.isArray(setting.children)
710
+ ) {
711
+ for (const childSetting of setting.children) {
712
+ this._checkPrivateSettingPrefixUse(childSetting, driver);
713
+ }
714
+ } else {
715
+ for (const prefix of RESERVED_SETTING_PREFIXES) {
716
+ if (setting.id.startsWith(prefix)) {
717
+ console.warn(
718
+ `drivers.${driver.id} invalid setting id: ${setting.id}, cannot start with reserved prefix: ${prefix}`
719
+ );
720
+ }
721
+ }
722
+ }
723
+ }
724
+
722
725
  _checkZwaveForSetting(driver, setting) {
723
726
  if (!driver || !setting || !setting.zwave) return;
724
727
  if (typeof setting.zwave.index !== 'number' || typeof setting.zwave.size !== 'number') throw new Error(`Missing property in "zwave" at ${driver.id}, ${setting.id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-lib",
3
- "version": "2.35.2",
3
+ "version": "2.35.4",
4
4
  "description": "Shared Library for Homey",
5
5
  "main": "index.js",
6
6
  "scripts": {