removeEntityByDevice.js 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 restApi_1 = require("../apis/restApi");
  7. var CloudDualR3Controller_1 = __importDefault(require("../controller/CloudDualR3Controller"));
  8. var CloudMultiChannelSwitchController_1 = __importDefault(require("../controller/CloudMultiChannelSwitchController"));
  9. var CloudTandHModificationController_1 = __importDefault(require("../controller/CloudTandHModificationController"));
  10. var CloudUIID190Controller_1 = __importDefault(require("../controller/CloudUIID190Controller"));
  11. var CloudUIID34Controller_1 = __importDefault(require("../controller/CloudUIID34Controller"));
  12. var CloudZigbeeDoubleColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeDoubleColorBulbController"));
  13. var CloudZigbeeFiveColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeFiveColorBulbController"));
  14. var CloudZigbeeMultiSwitchController_1 = __importDefault(require("../controller/CloudZigbeeMultiSwitchController"));
  15. var CloudZigbeeUIID1000Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1000Controller"));
  16. var CloudZigbeeUIID1770Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1770Controller"));
  17. var CloudZigbeeUIID2026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID2026Controller"));
  18. var CloudZigbeeUIID3026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID3026Controller"));
  19. var CloudZigbeeUIID4026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID4026Controller"));
  20. var DiyDeviceController_1 = __importDefault(require("../controller/DiyDeviceController"));
  21. var LanDualR3Controller_1 = __importDefault(require("../controller/LanDualR3Controller"));
  22. var LanMultiChannelSwitchController_1 = __importDefault(require("../controller/LanMultiChannelSwitchController"));
  23. var LanTandHModificationController_1 = __importDefault(require("../controller/LanTandHModificationController"));
  24. var LanUIID34Controller_1 = __importDefault(require("../controller/LanUIID34Controller"));
  25. var logger_1 = require("./logger");
  26. exports.default = (function (device) {
  27. logger_1.logger.info("try to remove entity from Ha: ".concat(device.entityId));
  28. if (device instanceof DiyDeviceController_1.default) {
  29. return;
  30. }
  31. else if (device instanceof CloudTandHModificationController_1.default || device instanceof LanTandHModificationController_1.default) {
  32. (0, restApi_1.removeStates)(device.entityId);
  33. (0, restApi_1.removeStates)("sensor.".concat(device.deviceId, "_h"));
  34. (0, restApi_1.removeStates)("sensor.".concat(device.deviceId, "_t"));
  35. return;
  36. }
  37. else if (device instanceof CloudMultiChannelSwitchController_1.default || device instanceof CloudDualR3Controller_1.default || device instanceof CloudZigbeeMultiSwitchController_1.default || device instanceof CloudUIID190Controller_1.default) {
  38. for (var i = 0; i < device.maxChannel; i++) {
  39. (0, restApi_1.removeStates)("".concat(device.entityId, "_").concat(i + 1));
  40. }
  41. return;
  42. }
  43. else if (device instanceof LanMultiChannelSwitchController_1.default || device instanceof LanDualR3Controller_1.default) {
  44. if (device.maxChannel) {
  45. for (var i = 0; i < device.maxChannel; i++) {
  46. (0, restApi_1.removeStates)("".concat(device.entityId, "_").concat(i + 1));
  47. }
  48. }
  49. return;
  50. }
  51. else if (device instanceof CloudZigbeeUIID1770Controller_1.default) {
  52. (0, restApi_1.removeStates)("".concat(device.entityId, "_temperature"));
  53. (0, restApi_1.removeStates)("".concat(device.entityId, "_humidity"));
  54. (0, restApi_1.removeStates)("".concat(device.entityId, "_battery"));
  55. return;
  56. }
  57. else if (device instanceof CloudZigbeeUIID1000Controller_1.default) {
  58. (0, restApi_1.removeStates)(device.entityId);
  59. (0, restApi_1.removeStates)("".concat(device.entityId, "_battery"));
  60. return;
  61. }
  62. else if (device instanceof CloudZigbeeUIID2026Controller_1.default || device instanceof CloudZigbeeUIID3026Controller_1.default || device instanceof CloudZigbeeUIID4026Controller_1.default) {
  63. (0, restApi_1.removeStates)(device.entityId);
  64. (0, restApi_1.removeStates)("sensor.".concat(device.deviceId, "_battery"));
  65. return;
  66. }
  67. else if (device instanceof CloudUIID34Controller_1.default || device instanceof LanUIID34Controller_1.default) {
  68. (0, restApi_1.removeStates)(device.entityId);
  69. (0, restApi_1.removeStates)("fan.".concat(device.deviceId));
  70. return;
  71. }
  72. else if (device instanceof CloudZigbeeDoubleColorBulbController_1.default || device instanceof CloudZigbeeFiveColorBulbController_1.default) {
  73. (0, restApi_1.removeStates)("light.".concat(device.deviceId));
  74. return;
  75. }
  76. (0, restApi_1.removeStates)(device.entityId);
  77. });