iobroker.keenergy 0.2.0
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.
- package/LICENSE +674 -0
- package/README.md +97 -0
- package/admin/i18n/de/translations.json +29 -0
- package/admin/i18n/en/translations.json +29 -0
- package/admin/i18n/es/translations.json +29 -0
- package/admin/i18n/fr/translations.json +29 -0
- package/admin/i18n/it/translations.json +29 -0
- package/admin/i18n/nl/translations.json +29 -0
- package/admin/i18n/pl/translations.json +29 -0
- package/admin/i18n/pt/translations.json +29 -0
- package/admin/i18n/ru/translations.json +29 -0
- package/admin/i18n/zh-cn/translations.json +29 -0
- package/admin/jsonConfig.json +168 -0
- package/admin/keenergy.png +0 -0
- package/build/lib/Client.js +68 -0
- package/build/lib/Client.js.map +7 -0
- package/build/lib/Keba.js +161 -0
- package/build/lib/Keba.js.map +7 -0
- package/build/lib/KebaClient.js +160 -0
- package/build/lib/KebaClient.js.map +7 -0
- package/build/lib/KebaMiddleware.js +131 -0
- package/build/lib/KebaMiddleware.js.map +7 -0
- package/build/lib/KebaStateTransformer.js +77 -0
- package/build/lib/KebaStateTransformer.js.map +7 -0
- package/build/lib/MaskTreeParser.js +224 -0
- package/build/lib/MaskTreeParser.js.map +7 -0
- package/build/lib/conditionChecker.js +91 -0
- package/build/lib/conditionChecker.js.map +7 -0
- package/build/lib/globalUtils.js +44 -0
- package/build/lib/globalUtils.js.map +7 -0
- package/build/main.js +173 -0
- package/build/main.js.map +7 -0
- package/io-package.json +154 -0
- package/package.json +92 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Keba_exports = {};
|
|
30
|
+
__export(Keba_exports, {
|
|
31
|
+
default: () => Keba_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Keba_exports);
|
|
34
|
+
var import_globalUtils = __toESM(require("./globalUtils"));
|
|
35
|
+
var import_KebaClient = __toESM(require("./KebaClient"));
|
|
36
|
+
var import_MaskTreeParser = __toESM(require("./MaskTreeParser"));
|
|
37
|
+
class Keba {
|
|
38
|
+
kebaClient;
|
|
39
|
+
_languageCode;
|
|
40
|
+
_systemUnit;
|
|
41
|
+
_readAllUnits;
|
|
42
|
+
_readAllFormats;
|
|
43
|
+
_readMaskTree;
|
|
44
|
+
_readWriteVars;
|
|
45
|
+
constructor() {
|
|
46
|
+
this.kebaClient = new import_KebaClient.default();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @returns {Promise<boolean>}
|
|
50
|
+
*/
|
|
51
|
+
async checkConnection() {
|
|
52
|
+
const host = import_globalUtils.default.config.host;
|
|
53
|
+
if (await this.kebaClient.getDateTime()) {
|
|
54
|
+
import_globalUtils.default.log.debug(`Connection established to ${host}`);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
import_globalUtils.default.log.error(`Errors while trying to connect to ${host}`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @returns {Promise<SystemLanguageCode>}
|
|
62
|
+
*/
|
|
63
|
+
async getLanguageCode() {
|
|
64
|
+
if (!this._languageCode) {
|
|
65
|
+
if (import_globalUtils.default.config.languageCode === "auto") {
|
|
66
|
+
this._languageCode = await this.kebaClient.getLanguageCode() || "en";
|
|
67
|
+
} else {
|
|
68
|
+
this._languageCode = import_globalUtils.default.config.languageCode;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this._languageCode;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @returns {Promise<SystemUnit>}
|
|
75
|
+
*/
|
|
76
|
+
async getSystemUnit() {
|
|
77
|
+
if (!this._systemUnit) {
|
|
78
|
+
if (import_globalUtils.default.config.systemUnit === "auto") {
|
|
79
|
+
this._systemUnit = await this.kebaClient.getSystemUnit();
|
|
80
|
+
} else {
|
|
81
|
+
this._systemUnit = import_globalUtils.default.config.systemUnit;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return this._systemUnit;
|
|
85
|
+
}
|
|
86
|
+
async readAllUnits() {
|
|
87
|
+
if (!this._readAllUnits) {
|
|
88
|
+
const systemUnit = await this.getSystemUnit();
|
|
89
|
+
const unitProperty = systemUnit.toLowerCase() === "imperial" ? "textImperial" : "textIso";
|
|
90
|
+
this._readAllUnits = {};
|
|
91
|
+
const units = await this.kebaClient.readAllUnits(await this.getLanguageCode());
|
|
92
|
+
for (const unit of units) {
|
|
93
|
+
const identifierProperty = "unitId";
|
|
94
|
+
if (unit[identifierProperty] && unit[unitProperty]) {
|
|
95
|
+
this._readAllUnits[unit[identifierProperty]] = unit[unitProperty];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return this._readAllUnits;
|
|
100
|
+
}
|
|
101
|
+
async readAllFormats() {
|
|
102
|
+
if (!this._readAllFormats) {
|
|
103
|
+
this._readAllFormats = {};
|
|
104
|
+
const formats = await this.kebaClient.readAllFormats(await this.getLanguageCode());
|
|
105
|
+
for (const format of formats) {
|
|
106
|
+
const identifierProperty = "formatId";
|
|
107
|
+
const valueProperty = "formatTexts";
|
|
108
|
+
if (format[identifierProperty] && format[valueProperty]) {
|
|
109
|
+
this._readAllFormats[format[identifierProperty]] = format[valueProperty].split("|");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return this._readAllFormats;
|
|
114
|
+
}
|
|
115
|
+
async readMaskTreeGetContent() {
|
|
116
|
+
if (!this._readMaskTree) {
|
|
117
|
+
this._readMaskTree = await this.kebaClient.readMaskTreeGetContent();
|
|
118
|
+
}
|
|
119
|
+
return this._readMaskTree;
|
|
120
|
+
}
|
|
121
|
+
async readVar(id, withAttributes = false) {
|
|
122
|
+
return (await this.readVars([id], withAttributes))[0];
|
|
123
|
+
}
|
|
124
|
+
async readVars(ids, withAttributes = false) {
|
|
125
|
+
const blockSize = 50;
|
|
126
|
+
const postData = [];
|
|
127
|
+
for (const id of ids) {
|
|
128
|
+
const item = { name: id };
|
|
129
|
+
if (withAttributes) {
|
|
130
|
+
item.attr = "1";
|
|
131
|
+
}
|
|
132
|
+
postData.push(item);
|
|
133
|
+
}
|
|
134
|
+
const result = [];
|
|
135
|
+
const languageCode = await this.getLanguageCode();
|
|
136
|
+
while (postData.length > 0) {
|
|
137
|
+
const postDataSub = postData.splice(0, blockSize);
|
|
138
|
+
result.push(...await this.kebaClient.readVars(languageCode, postDataSub));
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
async writeVar(id, value) {
|
|
143
|
+
return await this.writeVars({ [id]: value });
|
|
144
|
+
}
|
|
145
|
+
async writeVars(values) {
|
|
146
|
+
const data = [];
|
|
147
|
+
for (const id in values) {
|
|
148
|
+
data.push({ name: id, value: values[id] });
|
|
149
|
+
}
|
|
150
|
+
return await this.kebaClient.writeVars(data);
|
|
151
|
+
}
|
|
152
|
+
async getReadWriteVars() {
|
|
153
|
+
if (!this._readWriteVars) {
|
|
154
|
+
const parser = new import_MaskTreeParser.default(this);
|
|
155
|
+
this._readWriteVars = await parser.getVarsFromMaskTree();
|
|
156
|
+
}
|
|
157
|
+
return this._readWriteVars;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
var Keba_default = Keba;
|
|
161
|
+
//# sourceMappingURL=Keba.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/Keba.ts"],
|
|
4
|
+
"sourcesContent": ["'use strict';\n\nimport globalUtils from './globalUtils';\nimport KebaClient, {WriteVarsRequest} from './KebaClient';\nimport MaskTreeParser from './MaskTreeParser';\n\ntype ReadWriteVarsAttribute = {\n formatId: string;\n longText: string;\n};\n\ntype ReadWriteVarsResponse = {\n name: string;\n value: string;\n attributes?: ReadWriteVarsAttribute;\n};\n\ntype ReadWriteVar = {\n name: string;\n type: 'text' | 'numeric' | 'enum' | 'bool';\n writable: boolean;\n observe?: boolean;\n};\n\ntype SystemUnit = \"ISO\" | \"imperial\";\ntype SystemLanguageCode = \"de\" | \"en\" | \"fr\";\n\nclass Keba {\n private kebaClient: KebaClient;\n private _languageCode?: SystemLanguageCode;\n private _systemUnit?: SystemUnit;\n private _readAllUnits?: Record<string, string>;\n private _readAllFormats?: Record<string, string[]>;\n private _readMaskTree?: string;\n private _readWriteVars?: Record<string, ReadWriteVar>;\n\n constructor() {\n this.kebaClient = new KebaClient();\n }\n\n /**\n * @returns {Promise<boolean>}\n */\n async checkConnection(): Promise<boolean> {\n const host = globalUtils.config.host;\n if (await this.kebaClient.getDateTime()) {\n globalUtils.log.debug(`Connection established to ${host}`);\n return true;\n }\n globalUtils.log.error(`Errors while trying to connect to ${host}`);\n return false;\n }\n\n /**\n * @returns {Promise<SystemLanguageCode>}\n */\n async getLanguageCode(): Promise<SystemLanguageCode> {\n if (!this._languageCode) {\n if (globalUtils.config.languageCode === 'auto') {\n this._languageCode = (await this.kebaClient.getLanguageCode()) || 'en';\n } else {\n this._languageCode = globalUtils.config.languageCode as SystemLanguageCode;\n }\n }\n return this._languageCode;\n }\n\n /**\n * @returns {Promise<SystemUnit>}\n */\n async getSystemUnit(): Promise<SystemUnit> {\n if (!this._systemUnit) {\n if (globalUtils.config.systemUnit === 'auto') {\n this._systemUnit = await this.kebaClient.getSystemUnit() as SystemUnit;\n } else {\n this._systemUnit = globalUtils.config.systemUnit as SystemUnit;\n }\n }\n return this._systemUnit;\n }\n\n async readAllUnits(): Promise<Record<string, string>> {\n if (!this._readAllUnits) {\n const systemUnit = await this.getSystemUnit();\n const unitProperty = systemUnit.toLowerCase() === 'imperial' ? 'textImperial' : 'textIso';\n\n this._readAllUnits = {};\n const units = await this.kebaClient.readAllUnits(await this.getLanguageCode());\n for (const unit of units) {\n const identifierProperty = 'unitId';\n if (unit[identifierProperty] && unit[unitProperty]) {\n this._readAllUnits[unit[identifierProperty]] = unit[unitProperty];\n }\n }\n }\n return this._readAllUnits;\n }\n\n async readAllFormats(): Promise<Record<string, string[]>> {\n if (!this._readAllFormats) {\n this._readAllFormats = {};\n const formats = await this.kebaClient.readAllFormats(await this.getLanguageCode());\n for (const format of formats) {\n const identifierProperty = 'formatId';\n const valueProperty = 'formatTexts';\n if (format[identifierProperty] && format[valueProperty]) {\n this._readAllFormats[format[identifierProperty]] = format[valueProperty].split('|');\n }\n }\n }\n return this._readAllFormats;\n }\n\n async readMaskTreeGetContent(): Promise<string> {\n if (!this._readMaskTree) {\n this._readMaskTree = await this.kebaClient.readMaskTreeGetContent();\n }\n return this._readMaskTree;\n }\n\n async readVar(id: string, withAttributes: boolean = false): Promise<ReadWriteVarsResponse> {\n return (await this.readVars([id], withAttributes))[0];\n }\n\n async readVars(ids: string[], withAttributes: boolean = false): Promise<ReadWriteVarsResponse[]> {\n const blockSize = 50;\n const postData: { name: string; attr?: '1' | '0' }[] = [];\n for (const id of ids) {\n const item: { name: string; attr?: '1' | '0' } = { name: id };\n if (withAttributes) {\n item.attr = '1';\n }\n postData.push(item);\n }\n const result: ReadWriteVarsResponse[] = [];\n const languageCode = await this.getLanguageCode();\n while (postData.length > 0) {\n const postDataSub = postData.splice(0, blockSize);\n result.push(...(await this.kebaClient.readVars(languageCode, postDataSub)));\n }\n return result;\n }\n\n async writeVar(id: string, value: string): Promise<boolean> {\n return await this.writeVars({ [id]: value });\n }\n\n async writeVars(values: Record<string, string>): Promise<boolean> {\n const data: WriteVarsRequest[] = [];\n for (const id in values) {\n data.push({ name: id, value: values[id] });\n }\n return await this.kebaClient.writeVars(data);\n }\n\n async getReadWriteVars(): Promise<Record<string, ReadWriteVar>> {\n if (!this._readWriteVars) {\n const parser = new MaskTreeParser(this);\n this._readWriteVars = await parser.getVarsFromMaskTree();\n }\n return this._readWriteVars;\n }\n}\n\nexport default Keba;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAwB;AACxB,wBAA2C;AAC3C,4BAA2B;AAuB3B,MAAM,KAAK;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACV,SAAK,aAAa,IAAI,kBAAAA,QAAW;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,kBAAoC;AACtC,UAAM,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K,UAAU,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC;AAAA,EAC/C;AAAA,EAEA,MAAM,UAAU,QAAkD;AAC9D,UAAM,OAA2B,CAAC;AAClC,eAAW,MAAM,QAAQ;AACrB,WAAK,KAAK,EAAE,MAAM,IAAI,OAAO,OAAO,EAAE,EAAE,CAAC;AAAA,IAC7C;AACA,WAAO,MAAM,KAAK,WAAW,UAAU,IAAI;AAAA,EAC/C;AAAA,EAEA,MAAM,mBAA0D;AAC5D,QAAI,CAAC,KAAK,gBAAgB;AACtB,YAAM,SAAS,IAAI,sBAAAC,QAAe,IAAI;AACtC,WAAK,iBAAiB,MAAM,OAAO,oBAAoB;AAAA,IAC3D;AACA,WAAO,KAAK;AAAA,EAChB;AACJ;AAEA,IAAO,eAAQ;",
|
|
6
|
+
"names": ["KebaClient", "globalUtils", "MaskTreeParser"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var KebaClient_exports = {};
|
|
30
|
+
__export(KebaClient_exports, {
|
|
31
|
+
default: () => KebaClient_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(KebaClient_exports);
|
|
34
|
+
var import_globalUtils = __toESM(require("./globalUtils"));
|
|
35
|
+
var import_Client = __toESM(require("./Client"));
|
|
36
|
+
class KebaClient {
|
|
37
|
+
client;
|
|
38
|
+
constructor() {
|
|
39
|
+
this.client = new import_Client.default(`http://${import_globalUtils.default.config.host}`, 3e3);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @returns {Promise<ResponseDateTime | null>}
|
|
43
|
+
*/
|
|
44
|
+
async getDateTime() {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
this.client.post("/dateTime?action=getDateTime").then((data) => {
|
|
47
|
+
resolve(data);
|
|
48
|
+
}).catch(() => {
|
|
49
|
+
import_globalUtils.default.log.error("Failed to get DateTime from host.");
|
|
50
|
+
resolve(null);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @returns {Promise<"de" | "en" | "fr" | null>}
|
|
56
|
+
*/
|
|
57
|
+
async getLanguageCode() {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
this.client.post("/var/readWriteVars?action=read", { name: "APPL.CtrlAppl.sParam.hmiRetainData.systemLanguage" }).then((data) => {
|
|
60
|
+
resolve(data.value);
|
|
61
|
+
}).catch(() => {
|
|
62
|
+
import_globalUtils.default.log.error("Failed to get LanguageCode from host.");
|
|
63
|
+
resolve(null);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @returns {Promise<"ISO" | "imperial" | null>}
|
|
69
|
+
*/
|
|
70
|
+
async getSystemUnit() {
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
this.client.post("/var/readWriteVars?action=read", { name: "APPL.CtrlAppl.sParam.hmiRetainData.systemUnit" }).then((data) => {
|
|
73
|
+
resolve(data.value);
|
|
74
|
+
}).catch(() => {
|
|
75
|
+
import_globalUtils.default.log.error("Failed to get SystemUnit from host.");
|
|
76
|
+
resolve(null);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} languageCode
|
|
82
|
+
* @returns {Promise<Array<UnitObject>>}
|
|
83
|
+
*/
|
|
84
|
+
async readAllUnits(languageCode) {
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
this.client.post(`/var/readAllUnits?action=getUnits&languageCode=${languageCode}`).then((data) => {
|
|
87
|
+
resolve(data.units);
|
|
88
|
+
}).catch(() => {
|
|
89
|
+
import_globalUtils.default.log.error("Failed to get all Units from host.");
|
|
90
|
+
resolve([]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @param {string} languageCode
|
|
96
|
+
* @returns {Promise<Array<FormatObject>>}
|
|
97
|
+
*/
|
|
98
|
+
async readAllFormats(languageCode) {
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
this.client.post(`/var/readAllFormats?action=getFormats&languageCode=${languageCode}`).then((data) => {
|
|
101
|
+
resolve(data.formats);
|
|
102
|
+
}).catch(() => {
|
|
103
|
+
import_globalUtils.default.log.error("Failed to get all Formats from host.");
|
|
104
|
+
resolve([]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @returns {Promise<string>}
|
|
110
|
+
*/
|
|
111
|
+
async readMaskTreeGetContent() {
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
this.client.post("/readMaskTree?action=getcontent", { filename: "DetailMask.xml" }).then(({ content: xmlContent }) => {
|
|
114
|
+
resolve(xmlContent);
|
|
115
|
+
}).catch(() => {
|
|
116
|
+
import_globalUtils.default.log.error("Failed to read mask tree from host.");
|
|
117
|
+
resolve("");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} languageCode
|
|
123
|
+
* @param {Array<ReadVarsRequest>} data
|
|
124
|
+
* @returns {Promise<Array<ReadWriteVarsResponse>>}
|
|
125
|
+
*/
|
|
126
|
+
async readVars(languageCode, data) {
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
this.client.post(`/var/readWriteVars?languageCode=${languageCode}`, data).then((responseData) => {
|
|
129
|
+
resolve(responseData);
|
|
130
|
+
}).catch(() => {
|
|
131
|
+
const nameList = data.map(({ name }) => name);
|
|
132
|
+
import_globalUtils.default.log.error(
|
|
133
|
+
`Failed reading vars (${nameList.length}):
|
|
134
|
+
"` + JSON.stringify(nameList)
|
|
135
|
+
);
|
|
136
|
+
resolve([]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @param {Array<WriteVarsRequest>} data
|
|
142
|
+
* @returns {Promise<boolean>}
|
|
143
|
+
*/
|
|
144
|
+
async writeVars(data) {
|
|
145
|
+
return new Promise((resolve) => {
|
|
146
|
+
this.client.post("/var/readWriteVars?action=set", data).then(() => {
|
|
147
|
+
resolve(true);
|
|
148
|
+
}).catch(() => {
|
|
149
|
+
const nameList = data.map(({ name }) => name);
|
|
150
|
+
import_globalUtils.default.log.error(
|
|
151
|
+
`Failed writing vars (${nameList.length}):
|
|
152
|
+
"` + JSON.stringify(nameList)
|
|
153
|
+
);
|
|
154
|
+
resolve(false);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
var KebaClient_default = KebaClient;
|
|
160
|
+
//# sourceMappingURL=KebaClient.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/KebaClient.ts"],
|
|
4
|
+
"sourcesContent": ["'use strict';\n\nimport globalUtils from './globalUtils';\nimport Client from './Client';\n\ntype ResponseDateTime = {\n hours: number;\n seconds: number;\n month: number;\n year: number;\n minutes: number;\n day: number;\n};\n\ntype UnitObject = {\n textImperial: string;\n divisor: string;\n textIso: string;\n multiplier: string;\n unitId: string;\n};\n\ntype FormatObject = {\n formatTexts: string;\n formatId: string;\n postComma: string;\n};\n\ntype ReadWriteVarsAttribute = {\n formatId: string;\n longText: string;\n};\n\ntype ReadWriteVarsResponse = {\n name: string;\n value: string;\n attributes?: ReadWriteVarsAttribute;\n};\n\ntype ReadVarsRequest = {\n name: string;\n attr?: '1' | '0';\n};\n\nexport type WriteVarsRequest = {\n name: string;\n value: string;\n};\n\nclass KebaClient {\n private client: Client;\n\n constructor() {\n // noinspection HttpUrlsUsage\n this.client = new Client(`http://${globalUtils.config.host}`, 3000);\n }\n\n /**\n * @returns {Promise<ResponseDateTime | null>}\n */\n async getDateTime(): Promise<ResponseDateTime | null> {\n return new Promise((resolve) => {\n this.client\n .post('/dateTime?action=getDateTime')\n .then((data) => {\n resolve(data as ResponseDateTime);\n })\n .catch(() => {\n globalUtils.log.error('Failed to get DateTime from host.');\n resolve(null);\n });\n });\n }\n\n /**\n * @returns {Promise<\"de\" | \"en\" | \"fr\" | null>}\n */\n async getLanguageCode(): Promise<\"de\" | \"en\" | \"fr\" | null> {\n return new Promise((resolve) => {\n this.client\n .post('/var/readWriteVars?action=read', { name: 'APPL.CtrlAppl.sParam.hmiRetainData.systemLanguage' })\n .then((data) => {\n resolve(data.value as \"de\" | \"en\" | \"fr\");\n })\n .catch(() => {\n globalUtils.log.error('Failed to get LanguageCode from host.');\n resolve(null);\n });\n });\n }\n\n /**\n * @returns {Promise<\"ISO\" | \"imperial\" | null>}\n */\n async getSystemUnit(): Promise<\"ISO\" | \"imperial\" | null> {\n return new Promise((resolve) => {\n this.client\n .post('/var/readWriteVars?action=read', { name: 'APPL.CtrlAppl.sParam.hmiRetainData.systemUnit' })\n .then((data) => {\n resolve(data.value as \"ISO\" | \"imperial\");\n })\n .catch(() => {\n globalUtils.log.error('Failed to get SystemUnit from host.');\n resolve(null);\n });\n });\n }\n\n /**\n * @param {string} languageCode\n * @returns {Promise<Array<UnitObject>>}\n */\n async readAllUnits(languageCode: string): Promise<UnitObject[]> {\n return new Promise((resolve) => {\n this.client\n .post(`/var/readAllUnits?action=getUnits&languageCode=${languageCode}`)\n .then((data) => {\n resolve(data.units as UnitObject[]);\n })\n .catch(() => {\n globalUtils.log.error('Failed to get all Units from host.');\n resolve([]);\n });\n });\n }\n\n /**\n * @param {string} languageCode\n * @returns {Promise<Array<FormatObject>>}\n */\n async readAllFormats(languageCode: string): Promise<FormatObject[]> {\n return new Promise((resolve) => {\n this.client\n .post(`/var/readAllFormats?action=getFormats&languageCode=${languageCode}`)\n .then((data) => {\n resolve(data.formats as FormatObject[]);\n })\n .catch(() => {\n globalUtils.log.error('Failed to get all Formats from host.');\n resolve([]);\n });\n });\n }\n\n /**\n * @returns {Promise<string>}\n */\n async readMaskTreeGetContent(): Promise<string> {\n return new Promise((resolve) => {\n this.client\n .post('/readMaskTree?action=getcontent', { filename: 'DetailMask.xml' })\n .then(({ content: xmlContent }) => {\n resolve(xmlContent);\n })\n .catch(() => {\n globalUtils.log.error('Failed to read mask tree from host.');\n resolve('');\n });\n });\n }\n\n /**\n * @param {string} languageCode\n * @param {Array<ReadVarsRequest>} data\n * @returns {Promise<Array<ReadWriteVarsResponse>>}\n */\n async readVars(languageCode: string, data: ReadVarsRequest[]): Promise<ReadWriteVarsResponse[]> {\n return new Promise((resolve) => {\n this.client\n .post(`/var/readWriteVars?languageCode=${languageCode}`, data)\n .then((responseData) => {\n resolve(responseData as ReadWriteVarsResponse[]);\n })\n .catch(() => {\n const nameList = data.map(({ name }) => name);\n globalUtils.log.error(\n `Failed reading vars (${nameList.length}): \\n\"` + JSON.stringify(nameList)\n );\n resolve([]);\n });\n });\n }\n\n /**\n * @param {Array<WriteVarsRequest>} data\n * @returns {Promise<boolean>}\n */\n async writeVars(data: WriteVarsRequest[]): Promise<boolean> {\n return new Promise((resolve) => {\n this.client\n .post('/var/readWriteVars?action=set', data)\n .then(() => {\n resolve(true);\n })\n .catch(() => {\n const nameList = data.map(({ name }) => name);\n globalUtils.log.error(\n `Failed writing vars (${nameList.length}): \\n\"` + JSON.stringify(nameList)\n );\n resolve(false);\n });\n });\n }\n}\n\nexport default KebaClient;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAwB;AACxB,oBAAmB;AA8CnB,MAAM,WAAW;AAAA,EACL;AAAA,EAER,cAAc;AAEV,SAAK,SAAS,IAAI,cAAAA,QAAO,UAAU,mBAAAC,QAAY,OAAO,IAAI,IAAI,GAAI;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAgD;AAClD,WAAO,IAAI,QAAQ,CAAC,YAAY;AAC5B,WAAK,OACA,KAAK,8BAA8B,EACnC,KAAK,CAAC,SAAS;AACZ,gBAAQ,IAAwB;AAAA,MACpC,CAAC,EACA,MAAM,MAAM;AACT,2BAAAA,QAAY,IAAI,MAAM,mCAAmC;AACzD,gBAAQ,IAAI;AAAA,MAChB,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,kBAAsD;AACxD,WAAO,IAAI,QAAQ,C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AACA,gBAAQ,KAAK;AAAA,MACjB,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AACJ;AAEA,IAAO,qBAAQ;",
|
|
6
|
+
"names": ["Client", "globalUtils"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var KebaMiddleware_exports = {};
|
|
30
|
+
__export(KebaMiddleware_exports, {
|
|
31
|
+
default: () => KebaMiddleware_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(KebaMiddleware_exports);
|
|
34
|
+
var import_KebaStateTransformer = __toESM(require("./KebaStateTransformer"));
|
|
35
|
+
var import_Keba = __toESM(require("./Keba"));
|
|
36
|
+
class KebaMiddleware {
|
|
37
|
+
_keba;
|
|
38
|
+
_stateConfigurations = null;
|
|
39
|
+
_idToName = {};
|
|
40
|
+
_nameToId = {};
|
|
41
|
+
constructor() {
|
|
42
|
+
this._keba = new import_Keba.default();
|
|
43
|
+
}
|
|
44
|
+
get keba() {
|
|
45
|
+
return this._keba;
|
|
46
|
+
}
|
|
47
|
+
normalizeStateValue(val, type) {
|
|
48
|
+
switch (type) {
|
|
49
|
+
case "numeric":
|
|
50
|
+
return parseFloat(val);
|
|
51
|
+
case "bool":
|
|
52
|
+
return val === "true";
|
|
53
|
+
}
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
denormalizeStateValue(val, type) {
|
|
57
|
+
switch (type) {
|
|
58
|
+
case "numeric":
|
|
59
|
+
return `${val}`;
|
|
60
|
+
case "bool":
|
|
61
|
+
return val ? "true" : "false";
|
|
62
|
+
}
|
|
63
|
+
return `${val}`;
|
|
64
|
+
}
|
|
65
|
+
async readStates(ids) {
|
|
66
|
+
const states = {};
|
|
67
|
+
const names = ids.map((id) => this.getNameFromId(id));
|
|
68
|
+
const data = await this._keba.readVars(names);
|
|
69
|
+
for (const { name, value } of data) {
|
|
70
|
+
const id = this.getIdFromName(name);
|
|
71
|
+
const stateConfiguration = await this.getStateConfiguration(id);
|
|
72
|
+
states[id] = this.normalizeStateValue(value, stateConfiguration.native.type);
|
|
73
|
+
}
|
|
74
|
+
return states;
|
|
75
|
+
}
|
|
76
|
+
async readState(id) {
|
|
77
|
+
const name = this.getNameFromId(id);
|
|
78
|
+
const { value } = await this._keba.readVar(name);
|
|
79
|
+
const stateConfiguration = await this.getStateConfiguration(id);
|
|
80
|
+
return this.normalizeStateValue(value, stateConfiguration.native.type);
|
|
81
|
+
}
|
|
82
|
+
async writeState(id, value) {
|
|
83
|
+
const stateConfiguration = await this.getStateConfiguration(id);
|
|
84
|
+
if (!stateConfiguration.common.write) {
|
|
85
|
+
throw new Error(`State ${id} is not writable.`);
|
|
86
|
+
}
|
|
87
|
+
await this._keba.writeVar(
|
|
88
|
+
stateConfiguration.native.name,
|
|
89
|
+
this.denormalizeStateValue(value, stateConfiguration.native.type)
|
|
90
|
+
);
|
|
91
|
+
return await this.readState(id);
|
|
92
|
+
}
|
|
93
|
+
async getStateConfigurations() {
|
|
94
|
+
if (!this._stateConfigurations) {
|
|
95
|
+
this._stateConfigurations = {};
|
|
96
|
+
const stateTransformer = new import_KebaStateTransformer.default();
|
|
97
|
+
const readWriteVars = await this._keba.getReadWriteVars();
|
|
98
|
+
for (const name in readWriteVars) {
|
|
99
|
+
const stateConfiguration = stateTransformer.transformVarToSate(name, readWriteVars[name]);
|
|
100
|
+
const id = stateTransformer.transformNameToId(name);
|
|
101
|
+
this._nameToId[name] = id;
|
|
102
|
+
this._idToName[id] = name;
|
|
103
|
+
this._stateConfigurations[id] = stateConfiguration;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return this._stateConfigurations;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @param {string} id
|
|
110
|
+
* @returns {Promise<StateConfiguration>}
|
|
111
|
+
*/
|
|
112
|
+
async getStateConfiguration(id) {
|
|
113
|
+
return (await this.getStateConfigurations())[id];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @param {string} name
|
|
117
|
+
* @returns {string}
|
|
118
|
+
*/
|
|
119
|
+
getIdFromName(name) {
|
|
120
|
+
return this._nameToId[name];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} id
|
|
124
|
+
* @returns {string}
|
|
125
|
+
*/
|
|
126
|
+
getNameFromId(id) {
|
|
127
|
+
return this._idToName[id];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
var KebaMiddleware_default = KebaMiddleware;
|
|
131
|
+
//# sourceMappingURL=KebaMiddleware.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/KebaMiddleware.ts"],
|
|
4
|
+
"sourcesContent": ["'use strict';\n\nimport KebaStateTransformer from './KebaStateTransformer';\nimport Keba from './Keba';\n\ntype VariableTypes = 'text' | 'numeric' | 'enum' | 'bool';\ntype StateValue = string | number | boolean;\n\ninterface StateCommon {\n name: string;\n type: 'number' | 'boolean' | 'string';\n role: string;\n read: boolean;\n write: boolean;\n unit?: string;\n states?: Record<number, string>;\n min?: number;\n max?: number;\n}\n\ninterface StateNative {\n name: string;\n type: 'numeric' | 'bool' | 'enum' | 'text';\n}\n\ninterface StateConfiguration {\n type: string;\n common: StateCommon;\n native: StateNative;\n}\n\nclass KebaMiddleware {\n private _keba: Keba;\n private _stateConfigurations: Record<string, StateConfiguration> | null = null;\n private _idToName: Record<string, string> = {};\n private _nameToId: Record<string, string> = {};\n\n constructor() {\n this._keba = new Keba();\n }\n\n get keba(): Keba {\n return this._keba;\n }\n\n private normalizeStateValue(val: string, type: VariableTypes): StateValue {\n switch (type) {\n case 'numeric':\n return parseFloat(val);\n case 'bool':\n return val === 'true';\n }\n return val;\n }\n\n private denormalizeStateValue(val: string | number | boolean, type: VariableTypes): string {\n switch (type) {\n case 'numeric':\n return `${val}`;\n case 'bool':\n return val ? 'true' : 'false';\n }\n return `${val}`;\n }\n\n async readStates(ids: string[]): Promise<Record<string, StateValue>> {\n const states: Record<string, StateValue> = {};\n\n const names = ids.map((id) => this.getNameFromId(id));\n const data = await this._keba.readVars(names);\n\n for (const { name, value } of data) {\n const id = this.getIdFromName(name);\n const stateConfiguration = await this.getStateConfiguration(id);\n states[id] = this.normalizeStateValue(value, stateConfiguration.native.type);\n }\n\n return states;\n }\n\n async readState(id: string): Promise<StateValue> {\n const name = this.getNameFromId(id);\n const { value } = await this._keba.readVar(name);\n\n const stateConfiguration = await this.getStateConfiguration(id);\n return this.normalizeStateValue(value, stateConfiguration.native.type);\n }\n\n async writeState(id: string, value: StateValue): Promise<StateValue> {\n const stateConfiguration = await this.getStateConfiguration(id);\n if (!stateConfiguration.common.write) {\n throw new Error(`State ${id} is not writable.`);\n }\n await this._keba.writeVar(\n stateConfiguration.native.name,\n this.denormalizeStateValue(value, stateConfiguration.native.type)\n );\n return await this.readState(id);\n }\n\n async getStateConfigurations(): Promise<Record<string, StateConfiguration>> {\n if (!this._stateConfigurations) {\n this._stateConfigurations = {};\n\n const stateTransformer = new KebaStateTransformer();\n\n const readWriteVars = await this._keba.getReadWriteVars();\n for (const name in readWriteVars) {\n const stateConfiguration = stateTransformer.transformVarToSate(name, readWriteVars[name]);\n const id = stateTransformer.transformNameToId(name);\n\n this._nameToId[name] = id;\n this._idToName[id] = name;\n this._stateConfigurations[id] = stateConfiguration;\n }\n }\n\n return this._stateConfigurations;\n }\n\n /**\n * @param {string} id\n * @returns {Promise<StateConfiguration>}\n */\n async getStateConfiguration(id: string): Promise<StateConfiguration> {\n return (await this.getStateConfigurations())[id];\n }\n\n /**\n * @param {string} name\n * @returns {string}\n */\n private getIdFromName(name: string): string {\n return this._nameToId[name];\n }\n\n /**\n * @param {string} id\n * @returns {string}\n */\n private getNameFromId(id: string): string {\n return this._idToName[id];\n }\n}\n\nexport default KebaMiddleware;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kCAAiC;AACjC,kBAAiB;AA4BjB,MAAM,eAAe;AAAA,EACT;AAAA,EACA,uBAAkE;AAAA,EAClE,YAAoC,CAAC;AAAA,EACrC,YAAoC,CAAC;AAAA,EAE7C,cAAc;AACV,SAAK,QAAQ,IAAI,YAAAA,QAAK;AAAA,EAC1B;AAAA,EAEA,I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AAM;AAAA,MACb,mBAAmB,OAAO;AAAA,MAC1B,KAAK,sBAAsB,OAAO,mBAAmB,OAAO,IAAI;AAAA,IACpE;AACA,WAAO,MAAM,KAAK,UAAU,EAAE;AAAA,EAClC;AAAA,EAEA,MAAM,yBAAsE;AACxE,QAAI,CAAC,KAAK,sBAAsB;AAC5B,WAAK,uBAAuB,CAAC;AAE7B,YAAM,mBAAmB,IAAI,4BAAAC,QAAqB;AAElD,YAAM,gBAAgB,MAAM,KAAK,MAAM,iBAAiB;AACxD,iBAAW,QAAQ,eAAe;AAC9B,cAAM,qBAAqB,iBAAiB,mBAAmB,MAAM,cAAc,IAAI,CAAC;AACxF,cAAM,KAAK,iBAAiB,kBAAkB,IAAI;AAElD,aAAK,UAAU,IAAI,IAAI;AACvB,aAAK,UAAU,EAAE,IAAI;AACrB,aAAK,qBAAqB,EAAE,IAAI;AAAA,MACpC;AAAA,IACJ;AAEA,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,sBAAsB,IAAyC;AACjE,YAAQ,MAAM,KAAK,uBAAuB,GAAG,EAAE;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,cAAc,MAAsB;AACxC,WAAO,KAAK,UAAU,IAAI;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,cAAc,IAAoB;AACtC,WAAO,KAAK,UAAU,EAAE;AAAA,EAC5B;AACJ;AAEA,IAAO,yBAAQ;",
|
|
6
|
+
"names": ["Keba", "KebaStateTransformer"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var KebaStateTransformer_exports = {};
|
|
20
|
+
__export(KebaStateTransformer_exports, {
|
|
21
|
+
default: () => KebaStateTransformer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(KebaStateTransformer_exports);
|
|
24
|
+
class KebaStateTransformer {
|
|
25
|
+
constructor() {
|
|
26
|
+
}
|
|
27
|
+
transformNameToId(name) {
|
|
28
|
+
const regex = /\[(\d+)]\./g;
|
|
29
|
+
return name.replace(regex, ".$1.");
|
|
30
|
+
}
|
|
31
|
+
transformVarToSate(name, readWriteVar) {
|
|
32
|
+
const typeMapping = {
|
|
33
|
+
"numeric": "number",
|
|
34
|
+
"bool": "boolean",
|
|
35
|
+
"enum": "string",
|
|
36
|
+
"text": "string"
|
|
37
|
+
};
|
|
38
|
+
let descriptiveName = readWriteVar.name;
|
|
39
|
+
if (readWriteVar.attributes && readWriteVar.attributes["longText"]) {
|
|
40
|
+
descriptiveName = readWriteVar.attributes["longText"];
|
|
41
|
+
}
|
|
42
|
+
const common = {
|
|
43
|
+
name: descriptiveName,
|
|
44
|
+
type: typeMapping[readWriteVar.type],
|
|
45
|
+
role: "value",
|
|
46
|
+
// https://www.iobroker.net/#de/documentation/basics/roles.md
|
|
47
|
+
read: true,
|
|
48
|
+
write: readWriteVar.writable
|
|
49
|
+
};
|
|
50
|
+
if (readWriteVar.unit) {
|
|
51
|
+
common.unit = readWriteVar.unit;
|
|
52
|
+
}
|
|
53
|
+
if (readWriteVar.formats) {
|
|
54
|
+
common.states = {};
|
|
55
|
+
for (let i = 0; i < readWriteVar.formats.length; i++) {
|
|
56
|
+
common.states[i] = readWriteVar.formats[i] || `UNDEFINED (${i})`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (readWriteVar.attributes) {
|
|
60
|
+
if (readWriteVar.attributes["upperLimit"]) {
|
|
61
|
+
common.max = parseInt(readWriteVar.attributes["upperLimit"]);
|
|
62
|
+
}
|
|
63
|
+
if (readWriteVar.attributes["lowerLimit"]) {
|
|
64
|
+
common.min = parseInt(readWriteVar.attributes["lowerLimit"]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
type: "state",
|
|
69
|
+
common,
|
|
70
|
+
native: {
|
|
71
|
+
name,
|
|
72
|
+
type: readWriteVar.type
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=KebaStateTransformer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/KebaStateTransformer.ts"],
|
|
4
|
+
"sourcesContent": ["'use strict';\n\ntype StateNative = {\n name: string;\n type: 'numeric' | 'bool' | 'enum' | 'text';\n};\n\ntype StateCommon = {\n name: string;\n type: 'number' | 'boolean' | 'string';\n role: string;\n read: boolean;\n write: boolean;\n unit?: string;\n states?: Record<number, string>;\n min?: number;\n max?: number;\n};\n\ntype StateConfiguration = {\n type: string;\n common: StateCommon;\n native: StateNative;\n};\n\n\nexport default class KebaStateTransformer {\n\n public constructor() {\n }\n\n public transformNameToId(name: string): string {\n const regex = /\\[(\\d+)]\\./g;\n return name.replace(regex, '.$1.');\n }\n\n public transformVarToSate(name:string, readWriteVar: any): StateConfiguration {\n\n const typeMapping = {\n 'numeric': 'number',\n 'bool': 'boolean',\n 'enum': 'string',\n 'text': 'string',\n };\n\n let descriptiveName = readWriteVar.name;\n if (readWriteVar.attributes && readWriteVar.attributes['longText']) {\n descriptiveName = readWriteVar.attributes['longText'];\n }\n const common: StateCommon = {\n name: descriptiveName,\n type: typeMapping[readWriteVar.type],\n role: 'value', // https://www.iobroker.net/#de/documentation/basics/roles.md\n read: true,\n write: readWriteVar.writable,\n };\n if (readWriteVar.unit) {\n common.unit = readWriteVar.unit;\n }\n if (readWriteVar.formats) {\n common.states = {};\n for (let i = 0; i < readWriteVar.formats.length; i++) {\n common.states[i] = readWriteVar.formats[i] || `UNDEFINED (${i})`;\n }\n }\n if (readWriteVar.attributes) {\n if (readWriteVar.attributes['upperLimit']) {\n common.max = parseInt(readWriteVar.attributes['upperLimit']);\n }\n if (readWriteVar.attributes['lowerLimit']) {\n common.min = parseInt(readWriteVar.attributes['lowerLimit']);\n }\n }\n return {\n type: 'state',\n common,\n native: {\n name: name,\n type: readWriteVar.type,\n },\n };\n }\n\n\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,MAAO,qBAAmC;AAAA,EAE/B,cAAc;AAAA,EACrB;AAAA,EAEO,kBAAkB,MAAsB;AAC3C,UAAM,QAAQ;AACd,WAAO,KAAK,QAAQ,OAAO,MAAM;AAAA,EACrC;AAAA,EAEO,mBAAmB,MAAa,cAAuC;AAE1E,UAAM,cAAc;AAAA,MAChB,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ;AAAA,IACZ;AAEA,QAAI,kBAAkB,aAAa;AACnC,QAAI,aAAa,cAAc,aAAa,WAAW,UAAU,GAAG;AAChE,wBAAkB,aAAa,WAAW,UAAU;AAAA,IACxD;AACA,UAAM,SAAsB;AAAA,MACxB,MAAM;AAAA,MACN,MAAM,YAAY,aAAa,IAAI;AAAA,MACnC,MAAM;AAAA;AAAA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