homey-lib 2.45.0 → 2.45.2

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.
@@ -1,109 +0,0 @@
1
- 'use strict';
2
-
3
- const HomeyLib = require('..');
4
-
5
- describe('Capabilities', function () {
6
- const capabilities = {};
7
-
8
- before(function () {
9
- const allCapabilities = HomeyLib.getCapabilities();
10
-
11
- for (const [capabilityId, capability] of Object.entries(allCapabilities)) {
12
- // The original capabilities cannot be fixed if they contain errors, as that would break compatibility
13
- // with apps.
14
- if (capability.minCompatibility === undefined) continue;
15
-
16
- capabilities[capabilityId] = capability;
17
- }
18
- });
19
-
20
- // The mobile app will convert this to a 0-100 percentage slider. If the capability would have a
21
- // higher maximum, the slider would go to over 100%. For the capabilities we currently have, this doesn't make sense.
22
- it('Percentage capabilities are from 0-1 when settable', function () {
23
- const errors = [];
24
-
25
- for (const [capabilityId, capability] of Object.entries(capabilities)) {
26
- const unit = capability.units ? capability.units.en : undefined;
27
-
28
- if (capability.type === 'number' && unit === '%' && capability.setable) {
29
- if (!capability.decimals || capability.decimals < 2) {
30
- errors.push(`The capability ${capabilityId} should have at least 2 decimals`);
31
- }
32
-
33
- if (capability.min !== 0) {
34
- errors.push(`The capability ${capabilityId} should have a minimum of 0`);
35
- }
36
-
37
- if (capability.max !== 1) {
38
- errors.push(`The capability ${capabilityId} should have a maximum of 1`);
39
- }
40
- }
41
- }
42
-
43
- if (errors.length > 0) {
44
- throw new Error(errors.join('\n'));
45
- }
46
- });
47
-
48
- // The mobile app will not convert this to a percentage slider, as it is not settable. It will show the value as is.
49
- it('Percentage capabilities are from 0-100 when not settable', function () {
50
- const errors = [];
51
-
52
- for (const [capabilityId, capability] of Object.entries(capabilities)) {
53
- const unit = capability.units ? capability.units.en : undefined;
54
-
55
- if (capability.type === 'number' && unit === '%' && !capability.setable && capability.getable) {
56
- if (capability.min !== 0) {
57
- errors.push(`The capability ${capabilityId} should have a minimum of 0`);
58
- }
59
-
60
- if (capability.max !== 100) {
61
- errors.push(`The capability ${capabilityId} should have a maximum of 100`);
62
- }
63
- }
64
- }
65
-
66
- if (errors.length > 0) {
67
- throw new Error(errors.join('\n'));
68
- }
69
- });
70
-
71
- const defaultTriggerSuffix = {
72
- 'boolean': ['_true', '_false'],
73
- 'number': ['_changed'],
74
- 'string': ['_changed'],
75
- 'enum': ['_changed'],
76
- };
77
-
78
- // Homey Core will have default handlers for these triggers if they are named correctly.
79
- it('Trigger capabilities with a default suffix are valid', function () {
80
- const capabilities = HomeyLib.getCapabilities();
81
-
82
- const errors = [];
83
-
84
- for (const [capabilityId, capability] of Object.entries(capabilities)) {
85
- if (!capability.$flow || !capability.$flow.triggers) {
86
- continue;
87
- }
88
-
89
- for (const flow of capability.$flow.triggers) {
90
- const defaultSuffixes = defaultTriggerSuffix[capability.type] ? defaultTriggerSuffix[capability.type] : [];
91
- for (const suffix of defaultSuffixes) {
92
- if (!flow.id.endsWith(suffix)) {
93
- continue;
94
- }
95
-
96
- const requiredId = capabilityId + suffix;
97
-
98
- if (flow.id !== requiredId) {
99
- errors.push(`The trigger ${flow.id} should be named ${requiredId}`);
100
- }
101
- }
102
- }
103
- }
104
-
105
- if (errors.length > 0) {
106
- throw new Error(errors.join('\n'));
107
- }
108
- });
109
- });