123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- "use strict";
- var __assign = (this && this.__assign) || function () {
- __assign = Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
- 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;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- var __values = (this && this.__values) || function(o) {
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
- if (m) return m.call(o);
- if (o && typeof o.length === "number") return {
- next: function () {
- if (o && i >= o.length) o = void 0;
- return { value: o && o[i++], done: !o };
- }
- };
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
- };
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var lodash_1 = __importDefault(require("lodash"));
- var HASocketClass_1 = __importDefault(require("../class/HASocketClass"));
- var CloudDoubleColorBulbController_1 = __importDefault(require("../controller/CloudDoubleColorBulbController"));
- var CloudDualR3Controller_1 = __importDefault(require("../controller/CloudDualR3Controller"));
- var CloudDW2WiFiController_1 = __importDefault(require("../controller/CloudDW2WiFiController"));
- var CloudMultiChannelSwitchController_1 = __importDefault(require("../controller/CloudMultiChannelSwitchController"));
- var CloudPowerDetectionSwitchController_1 = __importDefault(require("../controller/CloudPowerDetectionSwitchController"));
- var CloudRGBBulbController_1 = __importDefault(require("../controller/CloudRGBBulbController"));
- var CloudRGBLightStripController_1 = __importDefault(require("../controller/CloudRGBLightStripController"));
- var CloudSwitchController_1 = __importDefault(require("../controller/CloudSwitchController"));
- var CloudTandHModificationController_1 = __importDefault(require("../controller/CloudTandHModificationController"));
- var CloudUIID104Controller_1 = __importDefault(require("../controller/CloudUIID104Controller"));
- var CloudUIID130Controller_1 = __importDefault(require("../controller/CloudUIID130Controller"));
- var CloudUIID137Controller_1 = __importDefault(require("../controller/CloudUIID137Controller"));
- var CloudUIID173Controller_1 = __importDefault(require("../controller/CloudUIID173Controller"));
- var CloudUIID181Controller_1 = __importDefault(require("../controller/CloudUIID181Controller"));
- var CloudUIID182Controller_1 = __importDefault(require("../controller/CloudUIID182Controller"));
- var CloudUIID190Controller_1 = __importDefault(require("../controller/CloudUIID190Controller"));
- var CloudZigbeeDoubleColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeDoubleColorBulbController"));
- var CloudZigbeeFiveColorBulbController_1 = __importDefault(require("../controller/CloudZigbeeFiveColorBulbController"));
- var CloudZigbeeMultiSwitchController_1 = __importDefault(require("../controller/CloudZigbeeMultiSwitchController"));
- var CloudZigbeeUIID1000Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1000Controller"));
- var CloudZigbeeUIID1770Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID1770Controller"));
- var CloudZigbeeUIID2026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID2026Controller"));
- var CloudZigbeeUIID3026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID3026Controller"));
- var CloudZigbeeUIID4026Controller_1 = __importDefault(require("../controller/CloudZigbeeUIID4026Controller"));
- var Controller_1 = __importDefault(require("../controller/Controller"));
- var DiyDeviceController_1 = __importDefault(require("../controller/DiyDeviceController"));
- var LanDualR3Controller_1 = __importDefault(require("../controller/LanDualR3Controller"));
- var LanMultiChannelSwitchController_1 = __importDefault(require("../controller/LanMultiChannelSwitchController"));
- var LanPowerDetectionSwitchController_1 = __importDefault(require("../controller/LanPowerDetectionSwitchController"));
- var LanSwitchController_1 = __importDefault(require("../controller/LanSwitchController"));
- var LanTandHModificationController_1 = __importDefault(require("../controller/LanTandHModificationController"));
- var generateLovelace = function () { return __awaiter(void 0, void 0, void 0, function () {
- var res, title, views, lovelace_1, isDeviceExist, singalSwitchCard, _loop_1, _a, _b, device;
- var e_1, _c;
- return __generator(this, function (_d) {
- switch (_d.label) {
- case 0: return [4, HASocketClass_1.default.getLovelace()];
- case 1:
- res = _d.sent();
- if (!(res && Array.isArray(res.views))) return [3, 3];
- title = res.title, views = res.views;
- lovelace_1 = { path: '', title: 'eWeLink Smart Home', badges: [], cards: [] };
- if (views.length) {
- lovelace_1 = views[0];
- }
- isDeviceExist = function (deviceId) {
- try {
- var tmp = JSON.stringify(lovelace_1);
- return tmp.includes(deviceId);
- }
- catch (error) {
- return false;
- }
- };
- singalSwitchCard = {
- type: 'entities',
- title: 'Switch',
- state_color: true,
- show_header_toggle: false,
- entities: [],
- };
- _loop_1 = function (device) {
- if (isDeviceExist(device.entityId)) {
- return "continue";
- }
- if (device instanceof DiyDeviceController_1.default || device instanceof CloudSwitchController_1.default || device instanceof CloudPowerDetectionSwitchController_1.default) {
- singalSwitchCard.entities.push(device.entityId);
- return "continue";
- }
- if (device instanceof LanSwitchController_1.default || device instanceof LanPowerDetectionSwitchController_1.default) {
- if (device.selfApikey && device.devicekey) {
- singalSwitchCard.entities.push(device.entityId);
- }
- return "continue";
- }
- if (device instanceof CloudMultiChannelSwitchController_1.default ||
- device instanceof LanMultiChannelSwitchController_1.default ||
- device instanceof CloudDualR3Controller_1.default ||
- device instanceof LanDualR3Controller_1.default ||
- device instanceof CloudZigbeeMultiSwitchController_1.default ||
- device instanceof CloudUIID130Controller_1.default ||
- device instanceof CloudUIID182Controller_1.default) {
- if (device.maxChannel === 1 && device.deviceName) {
- singalSwitchCard.entities.push("".concat(device.entityId, "_1"));
- return "continue";
- }
- if (!device.maxChannel || !device.deviceName) {
- return "continue";
- }
- var entities = Array.from({ length: device.maxChannel }, function (v, k) {
- return "".concat(device.entityId, "_").concat(k + 1);
- });
- var tmpCard = {
- type: 'entities',
- entities: entities,
- title: device.deviceName,
- state_color: true,
- show_header_toggle: true,
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudTandHModificationController_1.default || device instanceof LanTandHModificationController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: ["switch.".concat(device.deviceId), "sensor.".concat(device.deviceId, "_t"), "sensor.".concat(device.deviceId, "_h")],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false,
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeUIID1000Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "sensor.".concat(device.deviceId),
- "sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeUIID1770Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "sensor.".concat(device.deviceId, "_humidity"),
- "sensor.".concat(device.deviceId, "_temperature"),
- "sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeUIID2026Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "binary_sensor.".concat(device.deviceId),
- "sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeUIID3026Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "binary_sensor.".concat(device.deviceId),
- "sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeUIID4026Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "binary_sensor.".concat(device.deviceId),
- "sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudRGBBulbController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudRGBLightStripController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudDW2WiFiController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "binary_sensor.".concat(device.deviceId, "_lock"),
- "binary_sensor.".concat(device.deviceId, "_battery")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudDoubleColorBulbController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudUIID104Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudUIID181Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "switch.".concat(device.deviceId)
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudUIID190Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'entities',
- entities: [
- "switch.".concat(device.deviceId, "_1")
- ],
- title: device.deviceName,
- state_color: true,
- show_header_toggle: false
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeDoubleColorBulbController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudZigbeeFiveColorBulbController_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- if (device instanceof CloudUIID137Controller_1.default || device instanceof CloudUIID173Controller_1.default) {
- if (!device.deviceName) {
- return "continue";
- }
- var tmpCard = {
- type: 'light',
- entity: "light.".concat(device.deviceId),
- };
- var index = lodash_1.default.findIndex(lovelace_1.cards, { title: device.deviceName });
- if (~index) {
- lovelace_1.cards[index] = tmpCard;
- }
- else {
- lovelace_1.cards.push(tmpCard);
- }
- }
- };
- try {
- for (_a = __values(Controller_1.default.deviceMap.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
- device = _b.value;
- _loop_1(device);
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
- }
- finally { if (e_1) throw e_1.error; }
- }
- if (singalSwitchCard.entities.length) {
- lovelace_1.cards.unshift(singalSwitchCard);
- }
- if (views) {
- views[0] = lovelace_1;
- }
- return [4, HASocketClass_1.default.query({
- type: 'lovelace/config/save',
- config: __assign(__assign({}, res), { title: title, views: views }),
- })];
- case 2: return [2, _d.sent()];
- case 3: return [2];
- }
- });
- }); };
- exports.default = generateLovelace;
|