edilkamin 0.0.5 → 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,16 +7,61 @@
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
+ ```
10
47
 
11
48
  ## Motivations
49
+
12
50
  - providing an open source web alternative
13
51
  to the [proprietary mobile app](https://play.google.com/store/apps/details?id=com.edilkamin.stufe)
14
52
  - improving the interoperability (Nest, HomeAssistant...)
15
53
 
16
54
  ## Roadmap
55
+
17
56
  - [x] AWS Amplify/ Cognito authentication
18
57
  - [x] unauthenticated endpoint call
19
- - [ ] authenticated endpoint call
20
- - [ ] list stoves
58
+ - [x] authenticated endpoint call
59
+ - [ ] ~list stoves~
21
60
  - [x] turn stove on/off
22
61
  - [ ] set temperature
62
+
63
+ ## Limitations
64
+
65
+ It seems like there's no endpoint to list stoves associated to a user.
66
+ The way the official app seem to work is by probing the stove via bluetooth.
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 { 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,8 +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, "main", { enumerable: true, get: function () { return library_1.main; } });
5
- Object.defineProperty(exports, "deviceInfo", { enumerable: true, get: function () { return library_1.deviceInfo; } });
6
- Object.defineProperty(exports, "setPower", { enumerable: true, get: function () { return library_1.setPower; } });
7
- Object.defineProperty(exports, "setPowerOff", { enumerable: true, get: function () { return library_1.setPowerOff; } });
8
- 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
@@ -1,7 +1,12 @@
1
1
  import { DeviceInfoType } from "./types";
2
- declare const deviceInfo: (macAddress: string) => Promise<import("axios").AxiosResponse<DeviceInfoType>>;
3
- declare const setPower: (macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>;
4
- declare const setPowerOn: (macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
5
- declare const setPowerOff: (macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
6
- declare const main: () => void;
7
- export { main, deviceInfo, setPower, setPowerOff, setPowerOn };
2
+ /**
3
+ * Sign in to return the JWT token.
4
+ */
5
+ declare const signIn: (username: string, password: string) => Promise<string>;
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,10 @@ 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 = void 0;
12
+ exports.configure = exports.signIn = void 0;
13
13
  const assert_1 = require("assert");
14
- const axios_1 = require("axios");
15
14
  const aws_amplify_1 = require("aws-amplify");
15
+ const axios_1 = require("axios");
16
16
  const constants_1 = require("./constants");
17
17
  const amplifyconfiguration = {
18
18
  Auth: {
@@ -22,28 +22,43 @@ const amplifyconfiguration = {
22
22
  },
23
23
  };
24
24
  aws_amplify_1.Amplify.configure(amplifyconfiguration);
25
+ const headers = (jwtToken) => ({ Authorization: `Bearer ${jwtToken}` });
26
+ /**
27
+ * Sign in to return the JWT token.
28
+ */
25
29
  const signIn = (username, password) => __awaiter(void 0, void 0, void 0, function* () {
26
- try {
27
- const user = yield aws_amplify_1.Auth.signIn(username, password);
28
- console.log("user:", user);
29
- }
30
- catch (error) {
31
- console.log("error signing in", error);
32
- }
30
+ const user = yield aws_amplify_1.Auth.signIn(username, password);
31
+ return user.getSignInUserSession().getAccessToken().jwtToken;
32
+ });
33
+ exports.signIn = signIn;
34
+ const deviceInfo = (axiosInstance) => (jwtToken, macAddress) => axiosInstance.get(`device/${macAddress}/info`, {
35
+ headers: headers(jwtToken),
33
36
  });
34
- const deviceInfo = (macAddress) => axios_1.default.get(`${constants_1.API_URL}device/${macAddress}/info`);
35
- exports.deviceInfo = deviceInfo;
36
- const mqttCommand = (macAddress, payload) => axios_1.default.put(`${constants_1.API_URL}/mqtt/command`, Object.assign({ mac_address: macAddress }, payload));
37
- const setPower = (macAddress, value) => mqttCommand(macAddress, { name: "power", value });
38
- exports.setPower = setPower;
39
- const setPowerOn = (macAddress) => setPower(macAddress, 1);
40
- exports.setPowerOn = setPowerOn;
41
- const setPowerOff = (macAddress) => setPower(macAddress, 0);
42
- exports.setPowerOff = setPowerOff;
43
- const main = () => {
44
- const { USERNAME, PASSWORD } = process.env;
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();
56
+ const main = () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const { USERNAME, PASSWORD, MAC_ADDRESS } = process.env;
45
58
  assert_1.ok(USERNAME);
46
59
  assert_1.ok(PASSWORD);
47
- signIn(USERNAME, PASSWORD);
48
- };
49
- exports.main = main;
60
+ assert_1.ok(MAC_ADDRESS);
61
+ const jwtToken = yield signIn(USERNAME, PASSWORD);
62
+ const info = yield defaultApi.deviceInfo(jwtToken, MAC_ADDRESS);
63
+ console.log({ info });
64
+ });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "edilkamin",
3
- "version": "0.0.5",
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",
10
- "format": "prettier --write src",
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": [
@@ -30,6 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@aws-amplify/cli": "^7.6.21",
32
32
  "prettier": "^2.5.1",
33
+ "ts-node": "^10.9.1",
33
34
  "typedoc": "^0.22.12"
34
35
  }
35
36
  }