initMdns.js 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var MdnsClass_1 = __importDefault(require("../class/MdnsClass"));
  7. var formatDiyDevice_1 = __importDefault(require("./formatDiyDevice"));
  8. var DiyDeviceController_1 = __importDefault(require("../controller/DiyDeviceController"));
  9. var LanSwitchController_1 = __importDefault(require("../controller/LanSwitchController"));
  10. var LanMultiChannelSwitchController_1 = __importDefault(require("../controller/LanMultiChannelSwitchController"));
  11. var dataUtil_1 = require("./dataUtil");
  12. var eventBus_1 = __importDefault(require("./eventBus"));
  13. var mergeDeviceParams_1 = __importDefault(require("./mergeDeviceParams"));
  14. var LanDualR3Controller_1 = __importDefault(require("../controller/LanDualR3Controller"));
  15. var LanPowerDetectionSwitchController_1 = __importDefault(require("../controller/LanPowerDetectionSwitchController"));
  16. var LanTandHModificationController_1 = __importDefault(require("../controller/LanTandHModificationController"));
  17. var LanDoubleColorLightController_1 = __importDefault(require("../controller/LanDoubleColorLightController"));
  18. var LanRFBridgeController_1 = __importDefault(require("../controller/LanRFBridgeController"));
  19. var LanUIID34Controller_1 = __importDefault(require("../controller/LanUIID34Controller"));
  20. var logger_1 = require("./logger");
  21. exports.default = (function () {
  22. return MdnsClass_1.default.createInstance({
  23. queryParams: {
  24. questions: [
  25. {
  26. name: '_ewelink._tcp.local',
  27. type: 'PTR',
  28. },
  29. ],
  30. },
  31. queryCb: function () {
  32. logger_1.logger.info('Finding local eWeLink devices...');
  33. },
  34. onResponseCb: function (device) {
  35. var _a;
  36. if (device instanceof DiyDeviceController_1.default) {
  37. logger_1.logger.info('found diy device');
  38. var diyDevice = (0, formatDiyDevice_1.default)(device);
  39. device.updateState((_a = diyDevice.data) === null || _a === void 0 ? void 0 : _a.switch);
  40. (0, dataUtil_1.appendData)('diy.json', [diyDevice.id, 'online'], true);
  41. }
  42. else if (device instanceof LanSwitchController_1.default || device instanceof LanPowerDetectionSwitchController_1.default) {
  43. var decryptData = device.parseEncryptedData();
  44. if (decryptData) {
  45. device.updateState(decryptData.switch);
  46. device.params = (0, mergeDeviceParams_1.default)(device.params, decryptData);
  47. }
  48. }
  49. else if (device instanceof LanMultiChannelSwitchController_1.default || device instanceof LanDualR3Controller_1.default) {
  50. var decryptData = device.parseEncryptedData();
  51. if (decryptData) {
  52. device.updateState(decryptData.switches);
  53. device.params = (0, mergeDeviceParams_1.default)(device.params, decryptData);
  54. }
  55. }
  56. else if (device instanceof LanTandHModificationController_1.default) {
  57. var decryptData = device.parseEncryptedData();
  58. if (decryptData) {
  59. device.updateState(decryptData.switch);
  60. device.updateTandH(decryptData.currentTemperature, decryptData.currentHumidity);
  61. device.params = (0, mergeDeviceParams_1.default)(device.params, decryptData);
  62. }
  63. }
  64. else if (device instanceof LanDoubleColorLightController_1.default) {
  65. var decryptData = device.parseEncryptedData();
  66. if (decryptData) {
  67. device.updateState(decryptData);
  68. device.params = (0, mergeDeviceParams_1.default)(device.params, decryptData);
  69. }
  70. }
  71. else if (device instanceof LanRFBridgeController_1.default) {
  72. var decryptData = device.parseEncryptedData();
  73. if (decryptData) {
  74. device.updateState(device.parseMdnsData2Ha(decryptData));
  75. }
  76. }
  77. else if (device instanceof LanUIID34Controller_1.default) {
  78. var decryptData = device.parseEncryptedData();
  79. if (decryptData) {
  80. var switches = device.parseMdnsData2Ck(decryptData);
  81. device.updateState(switches);
  82. device.params = (0, mergeDeviceParams_1.default)(device.params, switches);
  83. }
  84. }
  85. eventBus_1.default.emit('sse');
  86. },
  87. });
  88. });