edilkamin 1.0.1 → 1.1.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.
package/README.md CHANGED
@@ -7,12 +7,52 @@
7
7
  This is a library for the [Reverse Engineered](docs/ReverseEngineering.md) "The Mind" Edilkamin API.
8
8
  The Mind offers an app/API to remote control the Edilkamin pellet stoves.
9
9
 
10
+ ## Install
11
+
12
+ Using npm:
13
+
14
+ ```sh
15
+ npm install edilkamin
16
+ ```
17
+
18
+ Using yarn:
19
+
20
+ ```sh
21
+ yarn add edilkamin
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Basic usage:
27
+
28
+ ```js
29
+ import { signIn, deviceInfo, setPowerOff } from "edilkamin";
30
+
31
+ const macAddress = "aabbccddeeff";
32
+ const token = signIn(username, password);
33
+ deviceInfo(token, macAddress).then(console.log);
34
+ setPowerOff(token, macAddress).then(console.log);
35
+ ```
36
+
37
+ It's also possible to change the default backend URL:
38
+
39
+ ```js
40
+ import { signIn, configure } from "edilkamin";
41
+
42
+ const baseUrl = "https://my-proxy.com/"
43
+ const { deviceInfo, setPower } = configure(baseUrl);
44
+ deviceInfo(token, macAddress).then(console.log);
45
+ setPower(token, macAddress, 0).then(console.log);
46
+ ```
47
+
10
48
  ## Motivations
49
+
11
50
  - providing an open source web alternative
12
51
  to the [proprietary mobile app](https://play.google.com/store/apps/details?id=com.edilkamin.stufe)
13
52
  - improving the interoperability (Nest, HomeAssistant...)
14
53
 
15
54
  ## Roadmap
55
+
16
56
  - [x] AWS Amplify/ Cognito authentication
17
57
  - [x] unauthenticated endpoint call
18
58
  - [x] authenticated endpoint call
@@ -21,6 +61,7 @@ The Mind offers an app/API to remote control the Edilkamin pellet stoves.
21
61
  - [ ] set temperature
22
62
 
23
63
  ## Limitations
64
+
24
65
  It seems like there's no endpoint to list stoves associated to a user.
25
66
  The way the official app seem to work is by probing the stove via bluetooth.
26
67
  Then cache the stove MAC address to a local database for later use.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export { API_URL } from "./constants";
1
2
  export { CommandsType, DeviceInfoType, StatusType, TemperaturesType, UserParametersType, } from "./types";
2
- export { signIn, main, deviceInfo, setPower, setPowerOff, setPowerOn, } from "./library";
3
+ export { signIn, configure } from "./library";
4
+ export declare const deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<import("./types").DeviceInfoType>>, setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>, setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>, setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var library_1 = require("./library");
4
- Object.defineProperty(exports, "signIn", { enumerable: true, get: function () { return library_1.signIn; } });
5
- Object.defineProperty(exports, "main", { enumerable: true, get: function () { return library_1.main; } });
6
- Object.defineProperty(exports, "deviceInfo", { enumerable: true, get: function () { return library_1.deviceInfo; } });
7
- Object.defineProperty(exports, "setPower", { enumerable: true, get: function () { return library_1.setPower; } });
8
- Object.defineProperty(exports, "setPowerOff", { enumerable: true, get: function () { return library_1.setPowerOff; } });
9
- Object.defineProperty(exports, "setPowerOn", { enumerable: true, get: function () { return library_1.setPowerOn; } });
4
+ exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.deviceInfo = void 0;
5
+ const library_1 = require("./library");
6
+ var constants_1 = require("./constants");
7
+ Object.defineProperty(exports, "API_URL", { enumerable: true, get: function () { return constants_1.API_URL; } });
8
+ var library_2 = require("./library");
9
+ Object.defineProperty(exports, "signIn", { enumerable: true, get: function () { return library_2.signIn; } });
10
+ Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return library_2.configure; } });
11
+ _a = library_1.configure(), exports.deviceInfo = _a.deviceInfo, exports.setPower = _a.setPower, exports.setPowerOff = _a.setPowerOff, exports.setPowerOn = _a.setPowerOn;
package/dist/library.d.ts CHANGED
@@ -3,9 +3,10 @@ import { DeviceInfoType } from "./types";
3
3
  * Sign in to return the JWT token.
4
4
  */
5
5
  declare const signIn: (username: string, password: string) => Promise<string>;
6
- declare const deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<DeviceInfoType>>;
7
- declare const setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>;
8
- declare const setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
9
- declare const setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
10
- declare const main: () => Promise<void>;
11
- export { signIn, main, deviceInfo, setPower, setPowerOff, setPowerOn };
6
+ declare const configure: (baseURL?: string) => {
7
+ deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<DeviceInfoType>>;
8
+ setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>;
9
+ setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
10
+ setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
11
+ };
12
+ export { signIn, configure };
package/dist/library.js CHANGED
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.deviceInfo = exports.main = exports.signIn = void 0;
12
+ exports.configure = exports.signIn = void 0;
13
13
  const assert_1 = require("assert");
14
14
  const aws_amplify_1 = require("aws-amplify");
15
- const axios_1 = require("./axios");
15
+ const axios_1 = require("axios");
16
+ const constants_1 = require("./constants");
16
17
  const amplifyconfiguration = {
17
18
  Auth: {
18
19
  region: "eu-central-1",
@@ -30,24 +31,34 @@ const signIn = (username, password) => __awaiter(void 0, void 0, void 0, functio
30
31
  return user.getSignInUserSession().getAccessToken().jwtToken;
31
32
  });
32
33
  exports.signIn = signIn;
33
- const deviceInfo = (jwtToken, macAddress) => axios_1.default.get(`device/${macAddress}/info`, {
34
+ const deviceInfo = (axiosInstance) => (jwtToken, macAddress) => axiosInstance.get(`device/${macAddress}/info`, {
34
35
  headers: headers(jwtToken),
35
36
  });
36
- exports.deviceInfo = deviceInfo;
37
- const mqttCommand = (jwtToken, macAddress, payload) => axios_1.default.put(`mqtt/command`, Object.assign({ mac_address: macAddress }, payload), { headers: headers(jwtToken) });
38
- const setPower = (jwtToken, macAddress, value) => mqttCommand(jwtToken, macAddress, { name: "power", value });
39
- exports.setPower = setPower;
40
- const setPowerOn = (jwtToken, macAddress) => setPower(jwtToken, macAddress, 1);
41
- exports.setPowerOn = setPowerOn;
42
- const setPowerOff = (jwtToken, macAddress) => setPower(jwtToken, macAddress, 0);
43
- exports.setPowerOff = setPowerOff;
37
+ const mqttCommand = (axiosInstance) => (jwtToken, macAddress, payload) => axiosInstance.put(`mqtt/command`, Object.assign({ mac_address: macAddress }, payload), { headers: headers(jwtToken) });
38
+ const setPower = (axiosInstance) => (jwtToken, macAddress, value) => mqttCommand(axiosInstance)(jwtToken, macAddress, { name: "power", value });
39
+ const setPowerOn = (axiosInstance) => (jwtToken, macAddress) => setPower(axiosInstance)(jwtToken, macAddress, 1);
40
+ const setPowerOff = (axiosInstance) => (jwtToken, macAddress) => setPower(axiosInstance)(jwtToken, macAddress, 0);
41
+ const configure = (baseURL = constants_1.API_URL) => {
42
+ const axiosInstance = axios_1.default.create({ baseURL });
43
+ const deviceInfoInstance = deviceInfo(axiosInstance);
44
+ const setPowerInstance = setPower(axiosInstance);
45
+ const setPowerOffInstance = setPowerOff(axiosInstance);
46
+ const setPowerOnInstance = setPowerOn(axiosInstance);
47
+ return {
48
+ deviceInfo: deviceInfoInstance,
49
+ setPower: setPowerInstance,
50
+ setPowerOff: setPowerOffInstance,
51
+ setPowerOn: setPowerOnInstance,
52
+ };
53
+ };
54
+ exports.configure = configure;
55
+ const defaultApi = configure();
44
56
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
45
57
  const { USERNAME, PASSWORD, MAC_ADDRESS } = process.env;
46
58
  assert_1.ok(USERNAME);
47
59
  assert_1.ok(PASSWORD);
48
60
  assert_1.ok(MAC_ADDRESS);
49
61
  const jwtToken = yield signIn(USERNAME, PASSWORD);
50
- const info = yield deviceInfo(jwtToken, MAC_ADDRESS);
62
+ const info = yield defaultApi.deviceInfo(jwtToken, MAC_ADDRESS);
51
63
  console.log({ info });
52
64
  });
53
- exports.main = main;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "edilkamin",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "lint": "prettier --check src docs .github",
10
- "format": "prettier --write src docs .github",
9
+ "lint": "prettier --check src docs .github *.md",
10
+ "format": "prettier --write src docs .github *.md",
11
11
  "build": "tsc"
12
12
  },
13
13
  "files": [
package/dist/axios.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const axiosInstance: import("axios").AxiosInstance;
2
- export default axiosInstance;
package/dist/axios.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const axios_1 = require("axios");
4
- const constants_1 = require("./constants");
5
- const axiosInstance = axios_1.default.create({
6
- baseURL: constants_1.API_URL,
7
- });
8
- exports.default = axiosInstance;