@lumiastream/tapo-cove 0.0.1-alpha.1 → 0.0.1-alpha.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.
Files changed (87) hide show
  1. package/lib/cjs/discovery.d.ts +1 -0
  2. package/lib/cjs/discovery.d.ts.map +1 -0
  3. package/lib/cjs/discovery.js +109 -113
  4. package/lib/cjs/index.d.ts +3 -2
  5. package/lib/cjs/index.d.ts.map +1 -0
  6. package/lib/cjs/index.js +30 -5
  7. package/lib/cjs/lightstate.d.ts +9 -4
  8. package/lib/cjs/lightstate.d.ts.map +1 -0
  9. package/lib/cjs/lightstate.js +74 -74
  10. package/lib/cjs/shared/cipher.d.ts +1 -0
  11. package/lib/cjs/shared/cipher.d.ts.map +1 -0
  12. package/lib/cjs/shared/cipher.js +42 -34
  13. package/lib/cjs/shared/helpers.d.ts +1 -0
  14. package/lib/cjs/shared/helpers.d.ts.map +1 -0
  15. package/lib/cjs/shared/helpers.js +63 -69
  16. package/lib/cjs/tapo-api.d.ts +1 -6
  17. package/lib/cjs/tapo-api.d.ts.map +1 -0
  18. package/lib/cjs/tapo-api.js +76 -104
  19. package/lib/cjs/types/interfaces.d.ts +1 -0
  20. package/lib/cjs/types/interfaces.d.ts.map +1 -0
  21. package/lib/cjs/types/raw-types.d.ts +1 -0
  22. package/lib/cjs/types/raw-types.d.ts.map +1 -0
  23. package/{dist/module/shared → lib/cjs/types}/tapo.constants.d.ts +1 -0
  24. package/lib/cjs/types/tapo.constants.d.ts.map +1 -0
  25. package/{dist/module/shared → lib/cjs/types}/tapo.constants.js +0 -0
  26. package/lib/esm/discovery.d.ts +1 -0
  27. package/lib/esm/discovery.d.ts.map +1 -0
  28. package/lib/esm/discovery.js +100 -107
  29. package/lib/esm/index.d.ts +3 -2
  30. package/lib/esm/index.d.ts.map +1 -0
  31. package/lib/esm/index.js +2 -2
  32. package/lib/esm/lightstate.d.ts +9 -4
  33. package/lib/esm/lightstate.d.ts.map +1 -0
  34. package/lib/esm/lightstate.js +73 -74
  35. package/lib/esm/shared/cipher.d.ts +1 -0
  36. package/lib/esm/shared/cipher.d.ts.map +1 -0
  37. package/lib/esm/shared/cipher.js +37 -32
  38. package/lib/esm/shared/helpers.d.ts +1 -0
  39. package/lib/esm/shared/helpers.d.ts.map +1 -0
  40. package/lib/esm/shared/helpers.js +58 -67
  41. package/lib/esm/tapo-api.d.ts +1 -6
  42. package/lib/esm/tapo-api.d.ts.map +1 -0
  43. package/lib/esm/tapo-api.js +67 -99
  44. package/lib/esm/types/interfaces.d.ts +1 -0
  45. package/lib/esm/types/interfaces.d.ts.map +1 -0
  46. package/lib/esm/types/raw-types.d.ts +1 -0
  47. package/lib/esm/types/raw-types.d.ts.map +1 -0
  48. package/lib/esm/{shared → types}/tapo.constants.d.ts +1 -0
  49. package/lib/esm/types/tapo.constants.d.ts.map +1 -0
  50. package/lib/esm/{shared → types}/tapo.constants.js +3 -3
  51. package/package.json +37 -36
  52. package/dist/module/discovery.d.ts +0 -8
  53. package/dist/module/discovery.js +0 -118
  54. package/dist/module/index.d.ts +0 -5
  55. package/dist/module/index.js +0 -12
  56. package/dist/module/lightstate.d.ts +0 -39
  57. package/dist/module/lightstate.js +0 -123
  58. package/dist/module/shared/cipher.d.ts +0 -11
  59. package/dist/module/shared/cipher.js +0 -66
  60. package/dist/module/shared/color-transformer.d.ts +0 -8
  61. package/dist/module/shared/color-transformer.js +0 -42
  62. package/dist/module/shared/helpers.d.ts +0 -5
  63. package/dist/module/shared/helpers.js +0 -105
  64. package/dist/module/shared/tapo-ca-cert.d.ts +0 -2
  65. package/dist/module/shared/tapo-ca-cert.js +0 -3
  66. package/dist/module/shared/utils.d.ts +0 -23
  67. package/dist/module/shared/utils.js +0 -152
  68. package/dist/module/tapo-api.d.ts +0 -48
  69. package/dist/module/tapo-api.js +0 -142
  70. package/dist/module/types/interfaces.d.ts +0 -3
  71. package/dist/module/types/interfaces.js +0 -2
  72. package/dist/module/types/raw-types.d.ts +0 -84
  73. package/dist/module/types/raw-types.js +0 -2
  74. package/lib/cjs/shared/color-transformer.d.ts +0 -8
  75. package/lib/cjs/shared/color-transformer.js +0 -42
  76. package/lib/cjs/shared/tapo-ca-cert.d.ts +0 -2
  77. package/lib/cjs/shared/tapo-ca-cert.js +0 -3
  78. package/lib/cjs/shared/tapo.constants.d.ts +0 -21
  79. package/lib/cjs/shared/tapo.constants.js +0 -25
  80. package/lib/cjs/shared/utils.d.ts +0 -23
  81. package/lib/cjs/shared/utils.js +0 -152
  82. package/lib/esm/shared/color-transformer.d.ts +0 -8
  83. package/lib/esm/shared/color-transformer.js +0 -40
  84. package/lib/esm/shared/tapo-ca-cert.d.ts +0 -2
  85. package/lib/esm/shared/tapo-ca-cert.js +0 -1
  86. package/lib/esm/shared/utils.d.ts +0 -23
  87. package/lib/esm/shared/utils.js +0 -146
@@ -6,3 +6,4 @@ declare const discover: (config: {
6
6
  types?: ILumiaDeviceType;
7
7
  }) => Promise<any>;
8
8
  export default discover;
9
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAShH,QAAA,MAAM,QAAQ,WAAkB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;CAAE,KAAG,QAAQ,GAAG,CAqG5H,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -1,118 +1,114 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var lumia_rgb_types_1 = require("@lumiastream/lumia-rgb-types");
5
- var axios_1 = tslib_1.__importDefault(require("axios"));
6
- var local_devices_1 = tslib_1.__importDefault(require("local-devices"));
7
- var cipher_1 = require("./shared/cipher");
8
- var helpers_1 = require("./shared/helpers");
9
- var tapo_api_1 = tslib_1.__importDefault(require("./tapo-api"));
10
- var discover = function (config) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
11
- var api, token, getDeviceRequest, response, devices, localDevices;
15
+ const lumia_rgb_types_1 = require("@lumiastream/lumia-rgb-types");
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const local_devices_1 = __importDefault(require("local-devices"));
18
+ const cipher_1 = require("./shared/cipher");
19
+ const helpers_1 = require("./shared/helpers");
20
+ const tapo_api_1 = __importDefault(require("./tapo-api"));
21
+ const discover = (config) => __awaiter(void 0, void 0, void 0, function* () {
12
22
  var _a;
13
- return tslib_1.__generator(this, function (_b) {
14
- switch (_b.label) {
15
- case 0:
16
- api = new tapo_api_1.default(config);
17
- token = config.token;
18
- if (!!token) return [3, 2];
19
- return [4, api.auth({ email: config.email, password: config.password })];
20
- case 1:
21
- token = _b.sent();
22
- _b.label = 2;
23
- case 2:
24
- getDeviceRequest = {
25
- method: 'getDeviceList',
26
- };
27
- return [4, (0, axios_1.default)({
28
- method: 'post',
29
- url: "".concat(api._baseUrl, "?token=").concat(token),
30
- data: getDeviceRequest,
31
- })];
32
- case 3:
33
- response = _b.sent();
34
- (0, helpers_1.throwErrorIfFound)(response.data);
35
- devices = [];
36
- return [4, (0, local_devices_1.default)({ skipNameResolution: true })];
37
- case 4:
38
- localDevices = _b.sent();
39
- (_a = response.data.result) === null || _a === void 0 ? void 0 : _a.deviceList.map(function (deviceInfo) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
40
- var findableMac_1, found, isTapo, alias, isTapo, alias;
41
- var _a, _b;
42
- return tslib_1.__generator(this, function (_c) {
43
- if (!deviceInfo.ip) {
44
- findableMac_1 = deviceInfo.deviceMac.replace(/:/g, '').toUpperCase();
45
- found = localDevices.find(function (device) { return findableMac_1 == device.mac.replace(/:/g, '').toUpperCase(); });
46
- if (found) {
47
- deviceInfo.ip = found.ip;
48
- }
49
- else {
50
- return [2];
51
- }
52
- }
53
- switch (deviceInfo.deviceType) {
54
- case 'IOT.SMARTBULB':
55
- case 'SMART.TAPOBULB': {
56
- if (config.types && config.types !== lumia_rgb_types_1.ILumiaDeviceType.LIGHT) {
57
- return [2];
58
- }
59
- isTapo = deviceInfo.deviceType === 'SMART.TAPOBULB';
60
- alias = (_a = (isTapo ? (0, cipher_1.base64Decode)(deviceInfo.alias) : deviceInfo.alias)) !== null && _a !== void 0 ? _a : deviceInfo.deviceName;
61
- devices.push({
62
- name: alias,
63
- id: deviceInfo.deviceMac,
64
- address: "http://".concat(deviceInfo.ip),
65
- host: deviceInfo.ip,
66
- lumiaInfo: {
67
- alias: alias,
68
- identifier: deviceInfo.deviceMac,
69
- serial: deviceInfo.hwId,
70
- lumiaType: lumia_rgb_types_1.ILumiaDeviceType.LIGHT,
71
- zonable: false,
72
- maxZones: 1,
73
- zones: null,
74
- rgb: true,
75
- white: true,
76
- connectionType: lumia_rgb_types_1.ILumiaDeviceConnectionType.WIFI,
77
- brand: isTapo ? lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK : lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK,
78
- product: deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.deviceModel,
79
- },
80
- });
81
- }
82
- case 'IOT.SMARTPLUGSWITCH':
83
- case 'SMART.TAPOPLUG': {
84
- if (config.types && config.types !== lumia_rgb_types_1.ILumiaDeviceType.PLUG) {
85
- return [2];
86
- }
87
- isTapo = deviceInfo.deviceType === 'SMART.TAPOPLUG';
88
- alias = (_b = (isTapo ? (0, cipher_1.base64Decode)(deviceInfo.alias) : deviceInfo.alias)) !== null && _b !== void 0 ? _b : deviceInfo.deviceName;
89
- devices.push({
90
- name: alias,
91
- id: deviceInfo.deviceMac,
92
- address: "http://".concat(deviceInfo.ip),
93
- host: deviceInfo.ip,
94
- lumiaInfo: {
95
- alias: alias,
96
- identifier: deviceInfo.deviceMac,
97
- serial: deviceInfo.hwId,
98
- lumiaType: lumia_rgb_types_1.ILumiaDeviceType.PLUG,
99
- zonable: false,
100
- maxZones: null,
101
- zones: null,
102
- rgb: false,
103
- white: false,
104
- connectionType: lumia_rgb_types_1.ILumiaDeviceConnectionType.WIFI,
105
- brand: isTapo ? lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK : lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK,
106
- product: deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.deviceModel,
107
- },
108
- });
109
- }
110
- }
111
- return [2];
112
- });
113
- }); });
114
- return [2, devices];
115
- }
23
+ const api = new tapo_api_1.default(config);
24
+ let token = config.token;
25
+ if (!token && config.email && config.password) {
26
+ token = yield api.auth({ email: config.email, password: config.password });
27
+ }
28
+ const getDeviceRequest = {
29
+ method: 'getDeviceList',
30
+ };
31
+ const response = yield (0, axios_1.default)({
32
+ method: 'post',
33
+ url: `${api._baseUrl}?token=${token}`,
34
+ data: getDeviceRequest,
116
35
  });
117
- }); };
36
+ (0, helpers_1.throwErrorIfFound)(response.data);
37
+ const devices = [];
38
+ const localDevices = yield (0, local_devices_1.default)({ skipNameResolution: true });
39
+ (_a = response.data.result) === null || _a === void 0 ? void 0 : _a.deviceList.map((deviceInfo) => __awaiter(void 0, void 0, void 0, function* () {
40
+ var _b, _c;
41
+ if (!deviceInfo.ip) {
42
+ const findableMac = deviceInfo.deviceMac.replace(/:/g, '').toUpperCase();
43
+ const found = localDevices.find((device) => findableMac == device.mac.replace(/:/g, '').toUpperCase());
44
+ if (found) {
45
+ deviceInfo.ip = found.ip;
46
+ }
47
+ else {
48
+ return;
49
+ }
50
+ }
51
+ switch (deviceInfo.deviceType) {
52
+ case 'IOT.SMARTBULB':
53
+ case 'SMART.TAPOBULB': {
54
+ if (config.types && config.types !== lumia_rgb_types_1.ILumiaDeviceType.LIGHT) {
55
+ return;
56
+ }
57
+ const isTapo = deviceInfo.deviceType === 'SMART.TAPOBULB';
58
+ // Tapo devices alias are encrypted
59
+ const alias = (_b = (isTapo ? (0, cipher_1.base64Decode)(deviceInfo.alias) : deviceInfo.alias)) !== null && _b !== void 0 ? _b : deviceInfo.deviceName;
60
+ devices.push({
61
+ name: alias,
62
+ id: deviceInfo.deviceMac,
63
+ address: `http://${deviceInfo.ip}`,
64
+ host: deviceInfo.ip,
65
+ lumiaInfo: {
66
+ alias: alias,
67
+ identifier: deviceInfo.deviceMac,
68
+ serial: deviceInfo.hwId,
69
+ lumiaType: lumia_rgb_types_1.ILumiaDeviceType.LIGHT,
70
+ zonable: false,
71
+ maxZones: 1,
72
+ zones: [],
73
+ rgb: true,
74
+ white: true,
75
+ connectionType: lumia_rgb_types_1.ILumiaDeviceConnectionType.WIFI,
76
+ brand: isTapo ? lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK : lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK,
77
+ product: deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.deviceModel,
78
+ },
79
+ });
80
+ }
81
+ case 'IOT.SMARTPLUGSWITCH':
82
+ case 'SMART.TAPOPLUG': {
83
+ if (config.types && config.types !== lumia_rgb_types_1.ILumiaDeviceType.PLUG) {
84
+ return;
85
+ }
86
+ const isTapo = deviceInfo.deviceType === 'SMART.TAPOPLUG';
87
+ // Tapo devices alias are encrypted
88
+ const alias = (_c = (isTapo ? (0, cipher_1.base64Decode)(deviceInfo.alias) : deviceInfo.alias)) !== null && _c !== void 0 ? _c : deviceInfo.deviceName;
89
+ devices.push({
90
+ name: alias,
91
+ id: deviceInfo.deviceMac,
92
+ address: `http://${deviceInfo.ip}`,
93
+ host: deviceInfo.ip,
94
+ lumiaInfo: {
95
+ alias: alias,
96
+ identifier: deviceInfo.deviceMac,
97
+ serial: deviceInfo.hwId,
98
+ lumiaType: lumia_rgb_types_1.ILumiaDeviceType.PLUG,
99
+ zonable: false,
100
+ maxZones: 0,
101
+ zones: [],
102
+ rgb: false,
103
+ white: false,
104
+ connectionType: lumia_rgb_types_1.ILumiaDeviceConnectionType.WIFI,
105
+ brand: isTapo ? lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK : lumia_rgb_types_1.ILumiaDeviceBrands.TPLINK,
106
+ product: deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.deviceModel,
107
+ },
108
+ });
109
+ }
110
+ }
111
+ }));
112
+ return devices;
113
+ });
118
114
  exports.default = discover;
@@ -1,5 +1,6 @@
1
1
  import discover from './discovery';
2
2
  import { LightState } from './lightstate';
3
3
  import TapoApi from './tapo-api';
4
- import * as TapoConstants from './shared/tapo.constants';
5
- export { LightState, discover, TapoApi, TapoConstants, };
4
+ import * as TapoConstants from './types/tapo.constants';
5
+ export { LightState, discover, TapoApi, TapoConstants };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -1,12 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
29
  exports.TapoConstants = exports.TapoApi = exports.discover = exports.LightState = void 0;
4
- var tslib_1 = require("tslib");
5
- var discovery_1 = tslib_1.__importDefault(require("./discovery"));
30
+ const discovery_1 = __importDefault(require("./discovery"));
6
31
  exports.discover = discovery_1.default;
7
- var lightstate_1 = require("./lightstate");
32
+ const lightstate_1 = require("./lightstate");
8
33
  Object.defineProperty(exports, "LightState", { enumerable: true, get: function () { return lightstate_1.LightState; } });
9
- var tapo_api_1 = tslib_1.__importDefault(require("./tapo-api"));
34
+ const tapo_api_1 = __importDefault(require("./tapo-api"));
10
35
  exports.TapoApi = tapo_api_1.default;
11
- var TapoConstants = tslib_1.__importStar(require("./shared/tapo.constants"));
36
+ const TapoConstants = __importStar(require("./types/tapo.constants"));
12
37
  exports.TapoConstants = TapoConstants;
@@ -1,12 +1,16 @@
1
1
  declare class SuperState {
2
- protected _values: {};
2
+ protected _values: Record<string, boolean | string | number>;
3
3
  transition: (value: number) => this;
4
4
  duration: (value: number) => this;
5
- getValues: () => {};
5
+ getValues: () => Record<string, string | number | boolean>;
6
6
  }
7
7
  export declare class LightState extends SuperState {
8
- constructor(values?: any);
9
- create: (values?: any) => this;
8
+ constructor(values?: {
9
+ on: boolean;
10
+ });
11
+ create: (values?: {
12
+ [x: string]: any;
13
+ } | undefined) => this;
10
14
  on: (value?: boolean) => this;
11
15
  turnOn: (value?: boolean) => this;
12
16
  off: () => this;
@@ -37,3 +41,4 @@ export declare class LightState extends SuperState {
37
41
  }) => this;
38
42
  }
39
43
  export {};
44
+ //# sourceMappingURL=lightstate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightstate.d.ts","sourceRoot":"","sources":["../../src/lightstate.ts"],"names":[],"mappings":"AAQA,cAAM,UAAU;IACZ,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAM;IAIlE,UAAU,UAAW,MAAM,UAGzB;IAEF,QAAQ,UALa,MAAM,UAKA;IAE3B,SAAS,kDAEP;CACL;AAED,qBAAa,UAAW,SAAQ,UAAU;gBAC1B,MAAM,CAAC,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE;IAKpC,MAAM;;sBAAoC,IAAI,CAgB5C;IAEF,EAAE,uBAAmB,IAAI,CAGvB;IAEF,MAAM,uBALe,IAAI,CAKR;IAEjB,GAAG,QAAO,IAAI,CAGZ;IAEF,OAAO,QALG,IAAI,CAKK;IAEnB,IAAI,sBAAuB,IAAI,CAO7B;IAGF,GAAG,UAAW,MAAM,KAAG,IAAI,CAIzB;IAGF,GAAG,UAAW,MAAM,KAAG,IAAI,CAGzB;IAEF,UAAU,UALI,MAAM,KAAG,IAAI,CAKL;IAEtB,GAAG,UAAW,MAAM,KAAG,IAAI,CAGzB;IAEF,UAAU,UALI,MAAM,KAAG,IAAI,CAKL;IAItB,IAAI,UAAW,MAAM,KAAG,IAAI,CAG1B;IAEF,gBAAgB,UALD,MAAM,KAAG,IAAI,CAKC;IAG7B,GAAG,UAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,UAY1E;IAGF,GAAG,UAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,IAAI,CASjF;IAGF,KAAK,UAAW;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,IAAI,CAUxE;CACL"}
@@ -1,123 +1,123 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LightState = void 0;
4
- var tslib_1 = require("tslib");
5
- var color_transformer_1 = tslib_1.__importDefault(require("./shared/color-transformer"));
6
- var utils_1 = require("./shared/utils");
7
- var isFunction = function (object) {
4
+ const lumia_rgb_utils_1 = require("@lumiastream/lumia-rgb-utils");
5
+ const isFunction = function (object) {
8
6
  var getClass = {}.toString;
9
7
  return object && getClass.call(object) === '[object Function]';
10
8
  };
11
- var SuperState = (function () {
12
- function SuperState() {
13
- var _this = this;
9
+ class SuperState {
10
+ constructor() {
14
11
  this._values = {};
15
- this.transition = function (value) {
16
- _this._values['transition_period'] = value;
17
- return _this;
12
+ // In Milliseconds
13
+ // 0.0 infinity seconds
14
+ this.transition = (value) => {
15
+ this._values['transition_period'] = value;
16
+ return this;
18
17
  };
19
18
  this.duration = this.transition;
20
- this.getValues = function () {
21
- return _this._values;
19
+ this.getValues = () => {
20
+ return this._values;
22
21
  };
23
22
  }
24
- return SuperState;
25
- }());
26
- var LightState = (function (_super) {
27
- tslib_1.__extends(LightState, _super);
28
- function LightState(values) {
29
- var _this = _super.call(this) || this;
30
- _this.create = function (values) {
23
+ }
24
+ class LightState extends SuperState {
25
+ constructor(values) {
26
+ super();
27
+ this.create = (values) => {
31
28
  if (values) {
32
- Object.keys(values).forEach(function (value) {
33
- var fn;
34
- if (_this.hasOwnProperty(value)) {
35
- fn = _this[value];
36
- if (isFunction(fn) && (0, utils_1.isTruly)(values[value])) {
37
- fn.apply(_this, [values[value]]);
29
+ Object.keys(values).forEach((value) => {
30
+ let fn;
31
+ if (this.hasOwnProperty(value)) {
32
+ fn = this[value];
33
+ if (isFunction(fn) && (0, lumia_rgb_utils_1.isTruly)(values[value])) {
34
+ fn.apply(this, [values[value]]);
38
35
  }
39
36
  }
40
37
  });
41
38
  }
42
- return _this;
39
+ return this;
43
40
  };
44
- _this.on = function (value) {
45
- if (value === void 0) { value = true; }
46
- _this._values['device_on'] = value;
47
- return _this;
41
+ this.on = (value = true) => {
42
+ this._values['device_on'] = value;
43
+ return this;
48
44
  };
49
- _this.turnOn = _this.on;
50
- _this.off = function () {
51
- _this.on(false);
52
- return _this;
45
+ this.turnOn = this.on;
46
+ this.off = () => {
47
+ this.on(false);
48
+ return this;
53
49
  };
54
- _this.turnOff = _this.off;
55
- _this.mode = function (value) {
56
- if (value === void 0) { value = 'normal'; }
50
+ this.turnOff = this.off;
51
+ this.mode = (value = 'normal') => {
57
52
  if (value === 'normal') {
58
- _this._values['color_temp'] = 0;
53
+ this._values['color_temp'] = 0;
59
54
  }
60
- _this._values['mode'] = value;
61
- return _this;
55
+ this._values['mode'] = value;
56
+ return this;
62
57
  };
63
- _this.hue = function (value) {
64
- _this._values['hue'] = value;
65
- _this._values['color_temp'] = 0;
66
- return _this;
58
+ // 0 - 360
59
+ this.hue = (value) => {
60
+ this._values['hue'] = value;
61
+ this._values['color_temp'] = 0;
62
+ return this;
67
63
  };
68
- _this.bri = function (value) {
69
- _this._values['brightness'] = value;
70
- return _this;
64
+ // Bri 0-100
65
+ this.bri = (value) => {
66
+ this._values['brightness'] = value;
67
+ return this;
71
68
  };
72
- _this.brightness = _this.bri;
73
- _this.sat = function (value) {
74
- _this._values['saturation'] = value;
75
- return _this;
69
+ this.brightness = this.bri;
70
+ this.sat = (value) => {
71
+ this._values['saturation'] = value;
72
+ return this;
76
73
  };
77
- _this.saturation = _this.sat;
78
- _this.temp = function (value) {
79
- _this._values['color_temp'] = value;
80
- return _this;
74
+ this.saturation = this.sat;
75
+ // Color Temperature 2500 - 9000 in kelvin
76
+ // Will override hue if passed
77
+ this.temp = (value) => {
78
+ this._values['color_temp'] = value;
79
+ return this;
81
80
  };
82
- _this.colorTemperature = _this.temp;
83
- _this.hsv = function (value) {
84
- var convertedHsv = [];
81
+ this.colorTemperature = this.temp;
82
+ // Can take in an array or object
83
+ this.hsv = (value) => {
84
+ let convertedHsv = [];
85
85
  if (Array.isArray(value)) {
86
86
  convertedHsv = value;
87
87
  }
88
88
  else {
89
89
  convertedHsv = [value.h, value.s, value.v];
90
90
  }
91
- _this.hue(convertedHsv[0]);
92
- _this.sat(convertedHsv[1]);
93
- _this.bri(convertedHsv[2]);
94
- return _this;
91
+ this.hue(convertedHsv[0]);
92
+ this.sat(convertedHsv[1]);
93
+ this.bri(convertedHsv[2]);
94
+ return this;
95
95
  };
96
- _this.rgb = function (value) {
97
- var hsv;
96
+ // Can take in an array or object
97
+ this.rgb = (value) => {
98
+ let hsv;
98
99
  if (Array.isArray(value)) {
99
- hsv = color_transformer_1.default.rgb2hsv(value);
100
+ hsv = (0, lumia_rgb_utils_1.rgb2hsv)(value);
100
101
  }
101
102
  else {
102
- hsv = color_transformer_1.default.rgb2hsv([value.r, value.g, value.b]);
103
+ hsv = (0, lumia_rgb_utils_1.rgb2hsv)([value.r, value.g, value.b]);
103
104
  }
104
- return _this.hsv(hsv);
105
+ return this.hsv(hsv);
105
106
  };
106
- _this.color = function (value) {
107
+ // Can take in an object will first check for ct and if it exists and the light will worki with it it'll use color temp
108
+ this.color = (value) => {
107
109
  if (Array.isArray(value)) {
108
110
  value = { r: value[0], g: value[1], b: value[2] };
109
111
  }
110
112
  if (value.ct) {
111
- return _this.temp(value.ct);
113
+ return this.temp(value.ct);
112
114
  }
113
115
  else {
114
- return _this.rgb({ r: value.r, g: value.g, b: value.b });
116
+ return this.rgb({ r: value.r, g: value.g, b: value.b });
115
117
  }
116
118
  };
117
119
  if (values)
118
- _this.create(values);
119
- return _this;
120
+ this.create(values);
120
121
  }
121
- return LightState;
122
- }(SuperState));
122
+ }
123
123
  exports.LightState = LightState;
@@ -9,3 +9,4 @@ export declare const readDeviceKey: (pemKey: string, privateKey: KeyObject) => B
9
9
  export declare const base64Encode: (data: string) => string;
10
10
  export declare const base64Decode: (data: string) => string;
11
11
  export declare const shaDigest: (data: string) => string;
12
+ //# sourceMappingURL=cipher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cipher.d.ts","sourceRoot":"","sources":["../../../src/shared/cipher.ts"],"names":[],"mappings":";;AAAA,OAAO,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,eAAO,MAAM,eAAe,8CAgB3B,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,GAAG,aAAa,aAAa,KAAG,MAI7D,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,MAAM,aAAa,aAAa,KAAG,GAIhE,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,MAAM,cAAc,SAAS,KAAG,MAYrE,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,MAAM,KAAG,MAE3C,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,MAAM,KAAG,MAE3C,CAAC;AAEF,eAAO,MAAM,SAAS,SAAU,MAAM,KAAG,MAIxC,CAAC"}
@@ -1,48 +1,56 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.shaDigest = exports.base64Decode = exports.base64Encode = exports.readDeviceKey = exports.decrypt = exports.encrypt = exports.generateKeyPair = void 0;
4
- var tslib_1 = require("tslib");
5
- var crypto_1 = tslib_1.__importDefault(require("crypto"));
6
- var util_1 = tslib_1.__importDefault(require("util"));
7
- var RSA_CIPHER_ALGORITHM = 'rsa';
8
- var AES_CIPHER_ALGORITHM = 'aes-128-cbc';
9
- var PASSPHRASE = 'top secret';
10
- var generateKeyPair = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
11
- var RSA_OPTIONS, generateKeyPair;
12
- return tslib_1.__generator(this, function (_a) {
13
- RSA_OPTIONS = {
14
- modulusLength: 1024,
15
- publicKeyEncoding: {
16
- type: 'spki',
17
- format: 'pem',
18
- },
19
- privateKeyEncoding: {
20
- type: 'pkcs1',
21
- format: 'pem',
22
- cipher: 'aes-256-cbc',
23
- passphrase: PASSPHRASE,
24
- },
25
- };
26
- generateKeyPair = util_1.default.promisify(crypto_1.default.generateKeyPair);
27
- return [2, generateKeyPair(RSA_CIPHER_ALGORITHM, RSA_OPTIONS)];
28
- });
29
- }); };
16
+ const crypto_1 = __importDefault(require("crypto"));
17
+ const util_1 = __importDefault(require("util"));
18
+ const RSA_CIPHER_ALGORITHM = 'rsa';
19
+ const AES_CIPHER_ALGORITHM = 'aes-128-cbc';
20
+ const PASSPHRASE = 'top secret';
21
+ const generateKeyPair = () => __awaiter(void 0, void 0, void 0, function* () {
22
+ const RSA_OPTIONS = {
23
+ modulusLength: 1024,
24
+ publicKeyEncoding: {
25
+ type: 'spki',
26
+ format: 'pem',
27
+ },
28
+ privateKeyEncoding: {
29
+ type: 'pkcs1',
30
+ format: 'pem',
31
+ cipher: 'aes-256-cbc',
32
+ passphrase: PASSPHRASE,
33
+ },
34
+ };
35
+ const generateKeyPair = util_1.default.promisify(crypto_1.default.generateKeyPair);
36
+ return generateKeyPair(RSA_CIPHER_ALGORITHM, RSA_OPTIONS);
37
+ });
30
38
  exports.generateKeyPair = generateKeyPair;
31
- var encrypt = function (data, deviceKey) {
39
+ const encrypt = (data, deviceKey) => {
32
40
  var cipher = crypto_1.default.createCipheriv(AES_CIPHER_ALGORITHM, deviceKey.key, deviceKey.iv);
33
41
  var ciphertext = cipher.update(Buffer.from(JSON.stringify(data)));
34
42
  return Buffer.concat([ciphertext, cipher.final()]).toString('base64');
35
43
  };
36
44
  exports.encrypt = encrypt;
37
- var decrypt = function (data, deviceKey) {
45
+ const decrypt = (data, deviceKey) => {
38
46
  var cipher = crypto_1.default.createDecipheriv(AES_CIPHER_ALGORITHM, deviceKey.key, deviceKey.iv);
39
47
  var ciphertext = cipher.update(Buffer.from(data, 'base64'));
40
48
  return JSON.parse(Buffer.concat([ciphertext, cipher.final()]).toString());
41
49
  };
42
50
  exports.decrypt = decrypt;
43
- var readDeviceKey = function (pemKey, privateKey) {
44
- var keyBytes = Buffer.from(pemKey, 'base64');
45
- var deviceKey = crypto_1.default.privateDecrypt({
51
+ const readDeviceKey = (pemKey, privateKey) => {
52
+ const keyBytes = Buffer.from(pemKey, 'base64');
53
+ const deviceKey = crypto_1.default.privateDecrypt({
46
54
  key: privateKey,
47
55
  padding: crypto_1.default.constants.RSA_PKCS1_PADDING,
48
56
  passphrase: PASSPHRASE,
@@ -50,15 +58,15 @@ var readDeviceKey = function (pemKey, privateKey) {
50
58
  return deviceKey;
51
59
  };
52
60
  exports.readDeviceKey = readDeviceKey;
53
- var base64Encode = function (data) {
61
+ const base64Encode = (data) => {
54
62
  return Buffer.from(data).toString('base64');
55
63
  };
56
64
  exports.base64Encode = base64Encode;
57
- var base64Decode = function (data) {
65
+ const base64Decode = (data) => {
58
66
  return Buffer.from(data, 'base64').toString();
59
67
  };
60
68
  exports.base64Decode = base64Decode;
61
- var shaDigest = function (data) {
69
+ const shaDigest = (data) => {
62
70
  var shasum = crypto_1.default.createHash('sha1');
63
71
  shasum.update(data);
64
72
  return shasum.digest('hex');