@kohost/api-client 1.0.0-alpha.0 → 1.0.0-alpha.1

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/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const Ajv = require("ajv");
2
2
  const ajv = new Ajv({ allErrors: true });
3
3
 
4
+ const deviceSchema = require("./schemas/device.json");
4
5
  const switchSchema = require("./schemas/switch.json");
5
6
  const alarmSchema = require("./schemas/alarm.json");
6
7
  const dimmerSchema = require("./schemas/dimmer.json");
@@ -10,6 +11,8 @@ const sceneControllerSchema = require("./schemas/sceneController.json");
10
11
  const thermostatSchema = require("./schemas/thermostat.json");
11
12
  const windowCoveringSchema = require("./schemas/windowCovering.json");
12
13
 
14
+ ajv.addSchema(deviceSchema);
15
+
13
16
  // compile all schemas
14
17
  const Switch = createClass(ajv.compile(switchSchema), "Switch");
15
18
  const Alarm = createClass(ajv.compile(alarmSchema), "Alarm");
@@ -27,9 +30,10 @@ const WindowCovering = createClass(
27
30
  );
28
31
 
29
32
  function createClass(validator, name) {
30
- class Factory {
33
+ class Generic {
31
34
  constructor(data) {
32
35
  // apply schema properties to the class
36
+ //this._validator = validator;
33
37
  this.validate(data);
34
38
  Object.keys(validator.schema.properties).forEach((key) => {
35
39
  if (data[key] !== undefined) this[key] = data[key];
@@ -37,17 +41,23 @@ function createClass(validator, name) {
37
41
  }
38
42
 
39
43
  validate(data) {
40
- const valid = validator(data);
44
+ const valid = this._validator(data);
41
45
  if (!valid)
42
- throw new Error(`Invalid ${name}`, { cause: validator.errors[0] });
46
+ throw new Error(`Invalid ${name}`, { cause: this._validator.errors });
43
47
  }
44
48
  }
45
49
 
46
50
  // change the name of the class
47
- Object.defineProperty(Factory, "name", { value: name });
48
- return Factory;
51
+ Object.defineProperty(Generic, "name", { value: name });
52
+ Generic.prototype._validator = validator;
53
+ return Generic;
49
54
  }
50
55
 
56
+ // Thermostat.prototype.toCelsius = function () {
57
+ // if (this.temperatureScale === "farenheit")
58
+ // this.currentTemperature = ((this.currentTemperature - 32) * 5) / 9;
59
+ // };
60
+
51
61
  // export all classes on the Models object
52
62
  module.exports = {
53
63
  Models: {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "ajv": "^8.11.0"
4
4
  },
5
5
  "name": "@kohost/api-client",
6
- "version": "1.0.0-alpha.0",
6
+ "version": "1.0.0-alpha.1",
7
7
  "description": "API client for Kohost utils",
8
8
  "main": "index.js",
9
9
  "devDependencies": {},
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/alarm.json",
3
4
  "title": "Alarm",
4
5
  "description": "Any smart alarm system",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "alarm"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "areas": {
38
24
  "type": "array",
@@ -1,38 +1,25 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/courtesy.json",
3
4
  "title": "Courtesy",
4
5
  "description": "Any smart courtesy system",
5
6
  "type": "object",
7
+ "allOf": [{ "$ref": "https://api.kohost.app/schemas/v3/device.json" }],
6
8
  "properties": {
7
9
  "id": {
8
- "type": "string"
10
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
11
  },
10
12
  "type": {
11
- "type": "string",
12
- "const": "courtesy"
13
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
14
+ },
15
+ "systemData": {
16
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
17
  },
14
18
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
19
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
20
  },
21
21
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
22
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
23
  },
37
24
  "supportedStates": {
38
25
  "type": "array",
@@ -47,5 +34,5 @@
47
34
  }
48
35
  },
49
36
  "additionalProperties": false,
50
- "required": ["id", "type", "systemData", "supportedStates", "state"]
37
+ "required": ["supportedStates", "state"]
51
38
  }
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/device.json",
4
+ "definitions": {
5
+ "id": {
6
+ "type": "string"
7
+ },
8
+ "systemData": {
9
+ "type": "object"
10
+ },
11
+ "type": {
12
+ "type": "string"
13
+ },
14
+ "supportedNotifications": {
15
+ "type": "array",
16
+ "uniqueItems": true,
17
+ "items": {
18
+ "enum": [
19
+ "idle",
20
+ "powerHasBeedApplied",
21
+ "acMainsDisconnected",
22
+ "acMainsReconnected",
23
+ "replaceBatterySoon",
24
+ "replaceBatteryNow",
25
+ "hardwareFailure",
26
+ "softwareFailure",
27
+ "hardwareFailureWithCode",
28
+ "softwareFailureWithCode",
29
+ "motionDetection"
30
+ ]
31
+ }
32
+ },
33
+ "notification": {
34
+ "type": "object",
35
+ "properties": {
36
+ "name": {
37
+ "type": "string",
38
+ "$ref": "#/definitions/supportedNotifications/items"
39
+ },
40
+ "timestamp": {
41
+ "type": "number",
42
+ "minimum": 1655907956593
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/dimmer.json",
3
4
  "title": "Dimmer",
4
5
  "description": "Any smart dimmer",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "dimmer"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "level": {
38
24
  "type": "number",
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/gateway.json",
3
4
  "title": "Gateway",
4
5
  "description": "Any smart gateway",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "gateway"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "status": {
38
24
  "type": "string"
package/schemas/lock.json CHANGED
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/lock.json",
3
4
  "title": "Lock",
4
5
  "description": "Any smart lock",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "lock"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "state": {
38
24
  "type": "string",
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/sceneController.json",
3
4
  "title": "Scene Controller",
4
5
  "description": "Any smart scene controller",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "sceneController"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "supportedScenes": {
38
24
  "type": "array",
@@ -41,7 +27,7 @@
41
27
  "type": "string"
42
28
  }
43
29
  },
44
- "lastScene": {
30
+ "scene": {
45
31
  "type": "object",
46
32
  "properties": {
47
33
  "name": {
@@ -56,5 +42,5 @@
56
42
  }
57
43
  },
58
44
  "additionalProperties": false,
59
- "required": ["id", "type", "systemData", "supportedScenes", "lastScene"]
45
+ "required": ["id", "type", "systemData", "supportedScenes", "scene"]
60
46
  }
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/switch.json",
3
4
  "title": "Switch",
4
5
  "description": "Any smart switch",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "switch"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "state": {
38
24
  "type": "string",
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/thermostat.json",
3
4
  "title": "Thermostat",
4
5
  "description": "Any smart thermostat",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "thermostat"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "currentTemperature": {
38
24
  "type": "number",
@@ -85,74 +71,47 @@
85
71
  },
86
72
  "setpoints": {
87
73
  "type": "object",
88
- "propertyNames": {
89
- "enum": ["cool", "heat", "auto"]
90
- },
91
74
  "properties": {
92
75
  "cool": {
93
- "type": "object",
94
- "properties": {
95
- "value": {
96
- "type": "number",
97
- "minimum": 0,
98
- "maximum": 99
99
- },
100
- "min": {
101
- "type": "number",
102
- "minimum": 0,
103
- "maximum": 99
104
- },
105
- "max": {
106
- "type": "number",
107
- "minimum": 0,
108
- "maximum": 99
109
- }
110
- }
76
+ "$ref": "#/$defs/setpoint"
111
77
  },
112
78
  "heat": {
113
- "type": "object",
114
- "properties": {
115
- "value": {
116
- "type": "number",
117
- "minimum": 0,
118
- "maximum": 99
119
- },
120
- "min": {
121
- "type": "number",
122
- "minimum": 0,
123
- "maximum": 99
124
- },
125
- "max": {
126
- "type": "number",
127
- "minimum": 0,
128
- "maximum": 99
129
- }
130
- }
79
+ "$ref": "#/$defs/setpoint"
131
80
  },
132
81
  "auto": {
133
- "type": "object",
134
- "properties": {
135
- "value": {
136
- "type": "number",
137
- "minimum": 0,
138
- "maximum": 99
139
- },
140
- "min": {
141
- "type": "number",
142
- "minimum": 0,
143
- "maximum": 99
144
- },
145
- "max": {
146
- "type": "number",
147
- "minimum": 0,
148
- "maximum": 99
149
- }
150
- }
82
+ "$ref": "#/$defs/setpoint"
151
83
  }
152
84
  }
153
85
  }
154
86
  },
155
87
  "additionalProperties": false,
88
+ "$defs": {
89
+ "setpoint": {
90
+ "type": "object",
91
+ "additionalProperties": false,
92
+ "properties": {
93
+ "value": {
94
+ "$ref": "#/$defs/setpointValue"
95
+ },
96
+ "min": {
97
+ "$ref": "#/$defs/setpointMinMax"
98
+ },
99
+ "max": {
100
+ "$ref": "#/$defs/setpointMinMax"
101
+ }
102
+ }
103
+ },
104
+ "setpointValue": {
105
+ "type": "number",
106
+ "minimum": 0,
107
+ "maximum": 99
108
+ },
109
+ "setpointMinMax": {
110
+ "type": ["number", "null"],
111
+ "minimum": 0,
112
+ "maximum": 99
113
+ }
114
+ },
156
115
  "required": [
157
116
  "id",
158
117
  "type",
@@ -1,38 +1,24 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/windowCovering.json",
3
4
  "title": "Window Covering",
4
5
  "description": "Any smart window covering",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "id": {
8
- "type": "string"
9
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
10
  },
10
11
  "type": {
11
- "type": "string",
12
- "const": "windowCovering"
12
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
13
+ },
14
+ "systemData": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
13
16
  },
14
17
  "supportedNotifications": {
15
- "type": "array",
16
- "uniqueItems": true,
17
- "items": {
18
- "enum": ["idle", "motionDetected"]
19
- }
18
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
20
19
  },
21
20
  "notification": {
22
- "type": "object",
23
- "properties": {
24
- "name": {
25
- "type": "string",
26
- "$ref": "#/properties/supportedNotifications/items"
27
- },
28
- "timestamp": {
29
- "type": "number",
30
- "minimum": 1655907956593
31
- }
32
- }
33
- },
34
- "systemData": {
35
- "type": "object"
21
+ "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
36
22
  },
37
23
  "position": {
38
24
  "type": "number",