getThings.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 __generator = (this && this.__generator) || function (thisArg, body) {
  12. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  13. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  14. function verb(n) { return function (v) { return step([n, v]); }; }
  15. function step(op) {
  16. if (f) throw new TypeError("Generator is already executing.");
  17. while (g && (g = 0, op[0] && (_ = 0)), _) try {
  18. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  19. if (y = 0, t) op = [op[0] & 2, t.value];
  20. switch (op[0]) {
  21. case 0: case 1: t = op; break;
  22. case 4: _.label++; return { value: op[1], done: false };
  23. case 5: _.label++; y = op[1]; op = [0]; continue;
  24. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25. default:
  26. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  27. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  28. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  29. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  30. if (t[2]) _.ops.pop();
  31. _.trys.pop(); continue;
  32. }
  33. op = body.call(thisArg, _);
  34. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  35. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  36. }
  37. };
  38. var __read = (this && this.__read) || function (o, n) {
  39. var m = typeof Symbol === "function" && o[Symbol.iterator];
  40. if (!m) return o;
  41. var i = m.call(o), r, ar = [], e;
  42. try {
  43. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  44. }
  45. catch (error) { e = { error: error }; }
  46. finally {
  47. try {
  48. if (r && !r.done && (m = i["return"])) m.call(i);
  49. }
  50. finally { if (e) throw e.error; }
  51. }
  52. return ar;
  53. };
  54. var __importDefault = (this && this.__importDefault) || function (mod) {
  55. return (mod && mod.__esModule) ? mod : { "default": mod };
  56. };
  57. Object.defineProperty(exports, "__esModule", { value: true });
  58. var coolkit_api_1 = __importDefault(require("coolkit-api"));
  59. var Controller_1 = __importDefault(require("../controller/Controller"));
  60. var DiyDeviceController_1 = __importDefault(require("../controller/DiyDeviceController"));
  61. var LanDeviceController_1 = __importDefault(require("../controller/LanDeviceController"));
  62. var CloudSwitchController_1 = __importDefault(require("../controller/CloudSwitchController"));
  63. var CloudTandHModificationController_1 = __importDefault(require("../controller/CloudTandHModificationController"));
  64. var CloudRGBBulbController_1 = __importDefault(require("../controller/CloudRGBBulbController"));
  65. var CloudDimmingController_1 = __importDefault(require("../controller/CloudDimmingController"));
  66. var CloudPowerDetectionSwitchController_1 = __importDefault(require("../controller/CloudPowerDetectionSwitchController"));
  67. var CloudMultiChannelSwitchController_1 = __importDefault(require("../controller/CloudMultiChannelSwitchController"));
  68. var CloudRGBLightStripController_1 = __importDefault(require("../controller/CloudRGBLightStripController"));
  69. var LanMultiChannelSwitchController_1 = __importDefault(require("../controller/LanMultiChannelSwitchController"));
  70. var channelMap_1 = require("../config/channelMap");
  71. var CloudDoubleColorBulbController_1 = __importDefault(require("../controller/CloudDoubleColorBulbController"));
  72. var LanSwitchController_1 = __importDefault(require("../controller/LanSwitchController"));
  73. var CloudDualR3Controller_1 = __importDefault(require("../controller/CloudDualR3Controller"));
  74. var dataUtil_1 = require("./dataUtil");
  75. var LanDualR3Controller_1 = __importDefault(require("../controller/LanDualR3Controller"));
  76. var LanTandHModificationController_1 = __importDefault(require("../controller/LanTandHModificationController"));
  77. var LanPowerDetectionSwitchController_1 = __importDefault(require("../controller/LanPowerDetectionSwitchController"));
  78. var CloudDW2WiFiController_1 = __importDefault(require("../controller/CloudDW2WiFiController"));
  79. var LanDoubleColorLightController_1 = __importDefault(require("../controller/LanDoubleColorLightController"));
  80. var CloudUIID104Controller_1 = __importDefault(require("../controller/CloudUIID104Controller"));
  81. var CloudZigbeeUIID2026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID2026Controller"));
  82. var CloudZigbeeUIID4026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID4026Controller"));
  83. var CloudZigbeeUIID3026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID3026Controller"));
  84. var CloudZigbeeUIID1770Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1770Controller"));
  85. var CloudZigbeeUIID1000Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1000Controller"));
  86. var CloudCoverController_1 = __importDefault(require("../controller/CloudCoverController"));
  87. var CloudRFBridgeController_1 = __importDefault(require("../controller/CloudRFBridgeController"));
  88. var LanRFBridgeController_1 = __importDefault(require("../controller/LanRFBridgeController"));
  89. var uiid_1 = require("../config/uiid");
  90. var CloudUIID44Controller_1 = __importDefault(require("../controller/CloudUIID44Controller"));
  91. var CloudUIID34Controller_1 = __importDefault(require("../controller/CloudUIID34Controller"));
  92. var LanUIID34Controller_1 = __importDefault(require("../controller/LanUIID34Controller"));
  93. var CloudNSPanelController_1 = __importDefault(require("../controller/CloudNSPanelController"));
  94. var logger_1 = require("./logger");
  95. var CloudUIID181Controller_1 = __importDefault(require("../controller/CloudUIID181Controller"));
  96. var CloudUIID190Controller_1 = __importDefault(require("../controller/CloudUIID190Controller"));
  97. var CloudZigbeeDoubleColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeDoubleColorBulbController"));
  98. var CloudZigbeeFiveColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeFiveColorBulbController"));
  99. var CloudZigbeeMultiSwitchController_1 = __importDefault(require("../controller/CloudZigbeeMultiSwitchController"));
  100. var CloudUIID137Controller_1 = __importDefault(require("../controller/CloudUIID137Controller"));
  101. var CloudUIID173Controller_1 = __importDefault(require("../controller/CloudUIID173Controller"));
  102. var CloudUIID182Controller_1 = __importDefault(require("../controller/CloudUIID182Controller"));
  103. var CloudUIID130Controller_1 = __importDefault(require("../controller/CloudUIID130Controller"));
  104. exports.default = (function () { return __awaiter(void 0, void 0, void 0, function () {
  105. var userData, lang, loginParams, _a, error, data, thingList, _loop_1, i;
  106. var _b, _c;
  107. return __generator(this, function (_d) {
  108. switch (_d.label) {
  109. case 0:
  110. userData = (0, dataUtil_1.getDataSync)('user.json', []) || {};
  111. lang = userData.lang === 'cn' ? 'cn' : 'en';
  112. loginParams = userData.login;
  113. if (!loginParams) {
  114. return [2, -1];
  115. }
  116. return [4, coolkit_api_1.default.device.getThingList({
  117. lang: lang,
  118. num: 0
  119. })];
  120. case 1:
  121. _a = _d.sent(), error = _a.error, data = _a.data;
  122. if (error === 0) {
  123. thingList = data.thingList;
  124. logger_1.logger.verbose("getThing: thingList: ".concat(JSON.stringify(thingList)));
  125. _loop_1 = function (i) {
  126. var item = thingList[i];
  127. var deviceIndex = item.index;
  128. if (item.itemType === 1 || item.itemType === 2) {
  129. var _e = item.itemData, extra = _e.extra, deviceid = _e.deviceid, name_1 = _e.name, params = _e.params, devicekey = _e.devicekey, apikey = _e.apikey, tags = _e.tags;
  130. var old_1 = Controller_1.default.getDevice(deviceid);
  131. if (old_1 instanceof DiyDeviceController_1.default) {
  132. return "continue";
  133. }
  134. if (old_1 instanceof LanDeviceController_1.default && !uiid_1.unsupportedLanModeUiidSet.has(extra.uiid) && !uiid_1.unsupportedLanModeModelSet.has(extra.model)) {
  135. old_1.devicekey = devicekey;
  136. old_1.selfApikey = apikey;
  137. old_1.deviceName = name_1;
  138. old_1.extra = extra;
  139. old_1.params = params;
  140. old_1.index = deviceIndex;
  141. if (old_1 instanceof LanSwitchController_1.default) {
  142. var decryptData = old_1.parseEncryptedData();
  143. if (decryptData) {
  144. old_1.updateState(decryptData.switch);
  145. }
  146. ((_c = (_b = item.itemData) === null || _b === void 0 ? void 0 : _b.tags) === null || _c === void 0 ? void 0 : _c.ck_channel_name) && (old_1.channelName = item.itemData.tags.ck_channel_name);
  147. }
  148. if (old_1 instanceof LanMultiChannelSwitchController_1.default) {
  149. old_1.channelName = tags === null || tags === void 0 ? void 0 : tags.ck_channel_name;
  150. old_1.maxChannel = (0, channelMap_1.getMaxChannelByUiid)(extra.uiid);
  151. var decryptData = old_1.parseEncryptedData();
  152. if (decryptData) {
  153. old_1.updateState(decryptData.switches);
  154. }
  155. }
  156. if (old_1 instanceof LanDualR3Controller_1.default) {
  157. old_1.channelName = tags === null || tags === void 0 ? void 0 : tags.ck_channel_name;
  158. var decryptData = old_1.parseEncryptedData();
  159. if (decryptData) {
  160. old_1.updateState(decryptData.switches);
  161. }
  162. }
  163. if (old_1 instanceof LanPowerDetectionSwitchController_1.default) {
  164. var decryptData = old_1.parseEncryptedData();
  165. if (decryptData) {
  166. old_1.updateState(decryptData.switch);
  167. }
  168. }
  169. if (old_1 instanceof LanDoubleColorLightController_1.default) {
  170. var decryptData = old_1.parseEncryptedData();
  171. if (decryptData) {
  172. old_1.updateState(decryptData);
  173. }
  174. }
  175. if (old_1 instanceof LanTandHModificationController_1.default) {
  176. var decryptData = old_1.parseEncryptedData();
  177. if (decryptData) {
  178. old_1.updateState(decryptData.switch);
  179. }
  180. }
  181. if (old_1 instanceof LanUIID34Controller_1.default) {
  182. var decryptData = old_1.parseEncryptedData();
  183. if (decryptData) {
  184. var switches = old_1.parseMdnsData2Ck(decryptData);
  185. old_1.updateState(switches);
  186. }
  187. }
  188. if (old_1 instanceof LanRFBridgeController_1.default) {
  189. old_1.tags = tags;
  190. if (Array.isArray(params.rfList)) {
  191. params.rfList.forEach(function (_a) {
  192. var rfChl = _a.rfChl, rfVal = _a.rfVal;
  193. old_1.rfValMap.set(rfChl, rfVal);
  194. });
  195. }
  196. if ((tags === null || tags === void 0 ? void 0 : tags.zyx_info) && old_1.rfValMap.size) {
  197. tags.zyx_info.forEach(function (_a) {
  198. var name = _a.name, buttonName = _a.buttonName, remote_type = _a.remote_type;
  199. buttonName.forEach(function (item) {
  200. var _a = __read(Object.entries(item)[0], 2), key = _a[0], childName = _a[1];
  201. var entityName = "".concat(name, "-").concat(childName);
  202. var suffix = old_1.rfValMap.get(+key);
  203. var entityId = "".concat(old_1.entityId, "_").concat(suffix);
  204. if (suffix) {
  205. old_1.entityMap.set(+key, {
  206. entityId: entityId,
  207. name: entityName,
  208. icon: +remote_type < 6 ? 'mdi:remote' : 'mdi:alert',
  209. });
  210. }
  211. });
  212. });
  213. }
  214. old_1.updateState();
  215. }
  216. return "continue";
  217. }
  218. var device = Controller_1.default.setDevice({
  219. id: deviceid,
  220. type: 12,
  221. data: item.itemData,
  222. index: deviceIndex,
  223. });
  224. if (device instanceof CloudSwitchController_1.default) {
  225. !device.disabled && device.updateState(params.switch);
  226. }
  227. if (device instanceof CloudTandHModificationController_1.default || device instanceof LanTandHModificationController_1.default) {
  228. !device.disabled && device.updateState(params.switch);
  229. !device.disabled && device.updateTandH(params.currentTemperature, params.currentHumidity);
  230. }
  231. if (device instanceof CloudRGBBulbController_1.default) {
  232. !device.disabled && device.updateState(device.parseCkData2Ha(params));
  233. }
  234. if (device instanceof CloudDimmingController_1.default) {
  235. !device.disabled &&
  236. device.updateState({
  237. status: params.switch,
  238. bright: params.bright,
  239. });
  240. }
  241. if (device instanceof CloudPowerDetectionSwitchController_1.default) {
  242. var status_1 = params.switch, power = params.power, voltage = params.voltage, current = params.current;
  243. !device.disabled &&
  244. device.updateState({
  245. status: status_1,
  246. power: power,
  247. voltage: voltage,
  248. current: current,
  249. });
  250. }
  251. if (device instanceof CloudMultiChannelSwitchController_1.default || device instanceof CloudZigbeeMultiSwitchController_1.default) {
  252. !device.disabled && device.updateState(params.switches);
  253. }
  254. if (device instanceof CloudRGBLightStripController_1.default) {
  255. !device.disabled && device.updateState(device.parseCkData2Ha(params));
  256. }
  257. if (device instanceof CloudDoubleColorBulbController_1.default) {
  258. !device.disabled && device.updateState(params);
  259. }
  260. if (device instanceof CloudUIID104Controller_1.default) {
  261. !device.disabled && device.updateState(params);
  262. }
  263. if (device instanceof CloudDualR3Controller_1.default) {
  264. !device.disabled && device.updateState(params.switches);
  265. }
  266. if (device instanceof CloudDW2WiFiController_1.default) {
  267. !device.disabled && device.updateState(params);
  268. }
  269. if (device instanceof CloudZigbeeUIID1000Controller_1.default) {
  270. !device.disabled && device.updateState(params);
  271. }
  272. if (device instanceof CloudZigbeeUIID1770Controller_1.default) {
  273. !device.disabled && device.updateState(params);
  274. }
  275. if (device instanceof CloudZigbeeUIID2026Controller_1.default) {
  276. !device.disabled && device.updateState(params);
  277. }
  278. if (device instanceof CloudZigbeeUIID3026Controller_1.default) {
  279. !device.disabled && device.updateState(params);
  280. }
  281. if (device instanceof CloudZigbeeUIID4026Controller_1.default) {
  282. !device.disabled && device.updateState(params);
  283. }
  284. if (device instanceof CloudCoverController_1.default) {
  285. !device.disabled && device.updateState(params);
  286. }
  287. if (device instanceof CloudRFBridgeController_1.default) {
  288. !device.disabled && device.updateState();
  289. }
  290. if (device instanceof CloudUIID44Controller_1.default) {
  291. !device.disabled && device.updateState(params);
  292. }
  293. if (device instanceof CloudUIID34Controller_1.default) {
  294. !device.disabled && device.updateState(params.switches);
  295. }
  296. if (device instanceof CloudNSPanelController_1.default) {
  297. }
  298. if (device instanceof CloudUIID181Controller_1.default) {
  299. !device.disabled && device.updateState(params.switch);
  300. }
  301. if (device instanceof CloudUIID190Controller_1.default) {
  302. !device.disabled && device.updateState(params.switches);
  303. }
  304. if (device instanceof CloudZigbeeDoubleColorBulbController_1.default || device instanceof CloudZigbeeFiveColorBulbController_1.default) {
  305. !device.disabled && device.updateState(params);
  306. }
  307. if (device instanceof CloudUIID137Controller_1.default || device instanceof CloudUIID173Controller_1.default) {
  308. !device.disabled && device.updateState(params);
  309. }
  310. if (device instanceof CloudUIID182Controller_1.default || device instanceof CloudUIID130Controller_1.default) {
  311. !device.disabled && device.updateState(params.switches);
  312. }
  313. }
  314. };
  315. for (i = 0; i < thingList.length; i++) {
  316. _loop_1(i);
  317. }
  318. return [2, 0];
  319. }
  320. return [2, -1];
  321. }
  322. });
  323. }); });