iobroker.telegram-menu
Advanced tools
Comparing version 0.1.0 to 0.1.1
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "e" }]*/ | ||
// Navigation---------------------------------------------------- | ||
/** | ||
* | ||
* Nav Component & Startrow in Nav | ||
* @param {string} user User Name | ||
* @returns HTML Element | ||
*/ | ||
function navElement(user) { | ||
return /*html*/ ` | ||
<tbody id="${user}"name="${user}" data-name="nav" data-nosave="true" class="user_${user} table_switch_user table_entry value table-lines table-values visibilityArrowBtn" style="display:none"> | ||
<tr class="startRow"> | ||
<td><input type="text" data-name="call" class="isString nav-call translateV startside" value="Startside" ></td> | ||
<td><input type="text" data-name="value" class="isString nav-value " value="Licht, Steckdose && Iobroker, Heizung"></td> | ||
<td><input type="text" data-name="text" class="isString nav-text" value="Wähle eine Aktion"></td> | ||
<td ></td> | ||
<td ></td> | ||
<td ></td> | ||
</tr> | ||
</tbody>`; | ||
} | ||
/** | ||
* New Navigation Row | ||
* @param {string} activuser Active User | ||
@@ -10,8 +29,11 @@ * @param {array} users List of Users | ||
const userIndex = users.indexOf(activuser); | ||
return /*html*/ `<tr> | ||
return /*html*/ ` | ||
<tr> | ||
<td><input type="text" data-name="call" class="isString nav-call "></td> | ||
<td><input type="text" data-name="value" class="isString nav-value "></td> | ||
<td><input type="text" data-name="text" class="isString nav-text " value="Wähle eine Aktion"></td> | ||
<td style="width: 5%;"><a class="deleteRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td> | ||
</tr>`; | ||
<td><a class="deleteRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td> | ||
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_down"><i class="material-icons" name="down">arrow_downward</i></a></td> | ||
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_up"><i class="material-icons" name="up">arrow_upward</i></a></td> | ||
</tr>`; | ||
} | ||
@@ -35,19 +57,2 @@ | ||
/** | ||
* | ||
* @param {string} user User Name | ||
* @returns HTML Element | ||
*/ | ||
function navElement(user) { | ||
return /*html*/ `<tbody id="${user}"name="${user}" data-name="nav" data-nosave="true" class="user_${user} table_switch_user table_entry value table-lines table-values" style="display:none"> | ||
<tr class="startRow"> | ||
<td><input type="text" data-name="call" class="isString nav-call translateV startside" value="Startside" ></td> | ||
<td><input type="text" data-name="value" class="isString nav-value " value="Licht, Steckdose && Iobroker, Heizung"></td> | ||
<td><input type="text" data-name="text" class="isString nav-text" value="Wähle eine Aktion"></td> | ||
<td style="width: 5%;"></td> | ||
</tr> | ||
</tbody>`; | ||
} | ||
function createSelectTrigger(list) { | ||
@@ -169,3 +174,3 @@ let element = '<option value="" disabled selected class="translate">Choose a trigger</option>'; | ||
function newTableRow_Action(action, result) { | ||
// console.log("ACTION " + action); | ||
// console.log("Action " + action); | ||
if (action === "get") { | ||
@@ -176,3 +181,3 @@ return /*html*/ `<tr> | ||
<td>${insertVal(result, "text")}</td> | ||
<td>${insertVal(result, "checkboxes")}</td> | ||
<td>${insertVal(result, "newline_checkbox")}</td> | ||
${actionDeleteButton} | ||
@@ -189,3 +194,3 @@ ${editButton} | ||
<td>${insertVal(result, "confirm")}</td> | ||
<td>${insertVal(result, "checkboxes")}</td> | ||
<td>${insertVal(result, "switch_checkbox")}</td> | ||
${actionDeleteButton} | ||
@@ -208,8 +213,13 @@ ${editButton} | ||
function insertVal(result, entry) { | ||
// Übernahme alter Daten in das neue Format | ||
if (entry == "switch_checkbox" || entry == "newline_checkbox") { | ||
if (result["checkboxes"]) result[entry] = result["checkboxes"]; | ||
} | ||
let newEntry = ""; | ||
if (result[entry]) { | ||
if (result[entry] && typeof result[entry] != "string") { | ||
result[entry].forEach(function (element) { | ||
let classVal = ""; | ||
if (element == "false" || element == false) classVal = "class='checkFalse'"; | ||
if (element === "false" || element === false) classVal = "class='checkFalse'"; | ||
else if (element == "true" || element == true) classVal = "class='checkTrue'"; | ||
@@ -224,4 +234,5 @@ | ||
} | ||
function newSelectInstanceRow(id) { | ||
return `<option value="${id}">${id}</option>`; | ||
} |
@@ -1,3 +0,3 @@ | ||
/*global newUserBtn,navElement ,actionElement,createSelectTrigger,newTableRow_Action,newTableRow_Action,newTrInAction, newSelectInstanceRow,userActivCheckbox $*/ | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "isStringEmty|generate|create|set|fill|reset|add|show|ins|table|get|new|show|checkValueModal|disable"}]*/ | ||
/*global newUserBtn,navElement ,actionElement,createSelectTrigger,newTableRow_Action,newTableRow_Action,newTrInAction, newSelectInstanceRow,userActivCheckbox,$*/ | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "isStringEmty|generate|create|set|fill|reset|add|show|ins|table|get|new|show|checkValueModal|disable|checkUpAndDownArrowBtn"}]*/ | ||
@@ -21,2 +21,14 @@ /** | ||
} | ||
function checkUpAndDownArrowBtn(activeuser) { | ||
const lengthOfNavList = $(`tbody#${activeuser}.visibilityArrowBtn tr`).length - 1; | ||
$(`tbody#${activeuser}.visibilityArrowBtn tr`).each(function (key) { | ||
$(this).attr("data-key", key); | ||
key == 1 | ||
? $(this).find("a i[name='up']").parent().attr("disabled", "disabled") | ||
: $(this).find("a i[name='up']").parent().removeAttr("disabled"); | ||
key == lengthOfNavList | ||
? $(this).find("a i[name='down']").parent().attr("disabled", "disabled") | ||
: $(this).find("a i[name='down']").parent().removeAttr("disabled"); | ||
}); | ||
} | ||
@@ -80,5 +92,4 @@ function generateNav() { | ||
const nav = []; | ||
let actionSet, actionGet, actionPic; | ||
const $tbody = $(this); | ||
const dataName = $(this).attr("data-name"); | ||
const $trs = $tbody.find("tr"); | ||
@@ -98,53 +109,37 @@ const saveName = $tbody.attr("name"); | ||
i++; | ||
actionSet = {}; | ||
actionGet = {}; | ||
actionPic = {}; | ||
$trs.each(function () { | ||
const dataName = $tbody.attr("data-name"); | ||
const $tr = $(this); | ||
if (dataName === "nav") { | ||
nav.push({ | ||
call: $(this).find("td input[data-name='call']").val(), | ||
value: $(this).find("td input[data-name='value']").val(), | ||
text: $(this).find("td input[data-name='text']").val(), | ||
// radio: $(this).find("td input.nav-radio").is(":checked"), | ||
}); | ||
const obj = {}; | ||
$(this) | ||
.find("td") | ||
.each(function () { | ||
const key = $(this).find("input").attr("data-name"); | ||
if (key) { | ||
obj[key] = $(this).find(`input[data-name='${key}']`).val(); | ||
} | ||
}); | ||
nav.push(obj); | ||
object.nav[saveName] = nav; | ||
} | ||
if (dataName === "set") { | ||
actionSet = { | ||
IDs: dataToArray(this, "p[data-name='IDs']"), | ||
checkboxes: dataToArray(this, "p[data-name='checkboxes']"), | ||
confirm: dataToArray(this, "p[data-name='confirm']"), | ||
trigger: dataToArray(this, "td[data-name='trigger']"), | ||
values: dataToArray(this, "p[data-name='values']"), | ||
returnText: dataToArray(this, "p[data-name='returnText']"), | ||
}; | ||
if (actionSet && actionSet.IDs) { | ||
obj.set.push(actionSet); | ||
const actionObj = {}; | ||
$($tr) | ||
.find("[data-name]") | ||
.each(function () { | ||
const naming = $(this).attr("data-name"); | ||
if (naming) { | ||
actionObj[naming] = dataToArray($tr, `[data-name="${naming}"]`); | ||
} | ||
}); | ||
if (actionObj && actionObj.IDs) { | ||
if (dataName === "set") { | ||
obj.set.push(actionObj); | ||
} else if (dataName === "get") { | ||
obj.get.push(actionObj); | ||
} else if (dataName === "pic") { | ||
obj.pic.push(actionObj); | ||
} | ||
} | ||
if (dataName === "get") { | ||
actionGet = { | ||
IDs: dataToArray(this, "p[data-name='IDs']"), | ||
checkboxes: dataToArray(this, "p[data-name='checkboxes']"), | ||
trigger: dataToArray(this, "td[data-name='trigger']"), | ||
text: dataToArray(this, "p[data-name='text']"), | ||
}; | ||
if (actionGet && actionGet.IDs) { | ||
obj.get.push(actionGet); | ||
} | ||
} | ||
if (dataName === "pic") { | ||
actionPic = { | ||
IDs: dataToArray(this, "p[data-name='IDs']"), | ||
picSendDelay: dataToArray(this, "p[data-name='picSendDelay']"), | ||
fileName: dataToArray(this, "p[data-name='fileName']"), | ||
trigger: dataToArray(this, "td[data-name='trigger']"), | ||
}; | ||
if (actionPic && actionPic.IDs) { | ||
obj.pic.push(actionPic); | ||
} | ||
} | ||
}); | ||
@@ -183,8 +178,6 @@ object.action[saveName] = obj; | ||
function setCheckbox(checkbox) { | ||
checkbox.forEach((element) => { | ||
for (const id in element) { | ||
if (element[id]) { | ||
$(`#${id}`).prop("checked", true); | ||
} else $(`#${id}`).prop("checked", false); | ||
} | ||
Object.keys(checkbox).forEach((key) => { | ||
if (checkbox[key]) { | ||
$(`#${key}`).prop("checked", true); | ||
} else $(`#${key}`).prop("checked", false); | ||
}); | ||
@@ -218,9 +211,8 @@ } | ||
const nav = data[name]; | ||
nav.forEach(function (element, key) { | ||
nav.forEach(function (element, pos) { | ||
// Erst bei Key 1 starten, da eine Row statisch ist | ||
if (key != 0) $(`#${name}`).append(newTableRow_Nav(name, users)); | ||
if (element.call) $(`#${name} tr input.nav-call`)[key].value = element.call; | ||
if (element.value) $(`#${name} tr input.nav-value`)[key].value = element.value; | ||
if (element.text) $(`#${name} tr input.nav-text`)[key].value = element.text; | ||
if (element.radio) $(`#${name} tr input.nav-radio:radio`)[key].checked = element.radio; | ||
if (pos != 0) $(`#${name}`).append(newTableRow_Nav(name, users)); | ||
Object.keys(element).forEach((key) => { | ||
if (element[key]) $(`#${name} tr input.nav-${key}:eq(${pos})`).val(element[key]); | ||
}); | ||
}); | ||
@@ -243,5 +235,5 @@ } | ||
function generatActionRow(user, action, result, rowToUpdate) { | ||
if (rowToUpdate) { | ||
$(rowToUpdate).empty().html(newTableRow_Action(action, result)?.replace("<tr>", "").replace("</tr>", "")); | ||
function generatActionRow(user, action, result, editedRowUpdate) { | ||
if (editedRowUpdate) { | ||
$(editedRowUpdate).empty().html(newTableRow_Action(action, result)?.replace("<tr>", "").replace("</tr>", "")); | ||
} else $(`.user_${user} .table_${action}`).append(newTableRow_Action(action, result)); | ||
@@ -286,3 +278,3 @@ } | ||
if (action == "set") { | ||
switchs = valuesToArray($this, "p[data-name='checkboxes']"); | ||
switchs = valuesToArray($this, "p[data-name='switch_checkbox']"); | ||
values = valuesToArray($this, "p[data-name='values']"); | ||
@@ -293,3 +285,3 @@ confirm = valuesToArray($this, "p[data-name='confirm']"); | ||
if (action == "get") { | ||
newline = valuesToArray($this, "p[data-name='checkboxes']"); | ||
newline = valuesToArray($this, "p[data-name='newline_checkbox']"); | ||
texts = valuesToArray($this, "p[data-name='text']"); | ||
@@ -307,3 +299,3 @@ } | ||
if (values) $(`#tab_${action} tbody input.set_value`).val(values[0].trim()); | ||
if (returnText) $(`#tab_${action} tbody input.returnText`).val(returnText[0].trim()); | ||
if (returnText) $(`#tab_${action} tbody input.returnText`).val(returnText[0].trim().replace(/&/g, "&")); | ||
if (texts) $(`#tab_${action} tbody input.get_text`).val(texts[0].trim().replace(/&/g, "&")); | ||
@@ -447,3 +439,3 @@ if (picSendDelay) $(`#tab_${action} tbody input.pic_picSendDelay`).val(picSendDelay[0].trim()); | ||
$(`#user_list li a[name=${activeUser}]`).addClass("active"); | ||
showHideUserCheckbox(activeUser); | ||
if (showHideUserCheckbox) showHideUserCheckbox(activeUser); | ||
} | ||
@@ -457,3 +449,2 @@ function checkValueModal(showTrigger) { | ||
show = false; | ||
console.log("auf false"); | ||
} | ||
@@ -471,3 +462,2 @@ }); | ||
) { | ||
console.log("auf false hier"); | ||
show = false; | ||
@@ -474,0 +464,0 @@ } |
{ | ||
"common": { | ||
"name": "telegram-menu", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"news": { | ||
"0.1.1": { | ||
"en": "shift rows\nsmall fixes\nDarkmode fixed\noption, return text without value\nget all Values of functions", | ||
"de": "schaltreihen\nkleine fixierungen\nDarkmode fest\noption, text ohne wert zurückgeben\nalle Werte der Funktionen", | ||
"ru": "сменные строки\nнебольшие исправления\nDarkmode фиксированный\nвариант, обратный текст без значения\nполучить все значения функций", | ||
"pt": "turnos\npequenas correções\nDarkmode corrigido\nopção, retornar texto sem valor\nobter todos os valores das funções", | ||
"nl": "quality over quantity (qoq) releases vertaling:\nkleine fixes\nDarkmode gemaakt\noptie, terugkeren zonder waarde\nalle functies krijgen", | ||
"fr": "lignes de quart\npetites corrections\nDarkmode fixed\noption, texte de retour sans valeur\nobtenir toutes les valeurs des fonctions", | ||
"it": "spostare le righe\npiccole correzioni\nDarkmode fisso\nopzione, restituire il testo senza valore\nottenere tutti i valori delle funzioni", | ||
"es": "turno de filas\npequeños accesorios\nModo oscuro fijo\nopción, devolver texto sin valor\nobtener todos los Valores de las funciones", | ||
"pl": "rzędy zwrotne\ndrobne rozwiązanie\nDarkmode fixed\nopcja zwrotu tekstu bez wartości\nuzyskuje wszystkie funkcje", | ||
"uk": "зсувні рядки\nмаленькі кріплення\nDarkmode фіксований\nваріант, повернення тексту без значення\nотримувати всі значення функцій", | ||
"zh-cn": "更替\n小型配件\n达库姆固定\n备选案文:不附加价值的返回案文\n获得所有职能的价值" | ||
}, | ||
"0.1.0": { | ||
@@ -7,0 +20,0 @@ "en": "Fixes\nStyle\nConfirmation, that the value has been set\nSecond User Menu fixed", |
@@ -1,2 +0,1 @@ | ||
/*global $*/ | ||
const sendToTelegram = require("./telegram").sendToTelegram; | ||
@@ -37,26 +36,62 @@ | ||
} | ||
// Licht an Auswerten | ||
// ID by Selctor Auswerten | ||
/** | ||
* | ||
* | ||
* @param {*} _this | ||
* @param {string} selector | ||
* @param {*} text | ||
* @param {*} userToSend | ||
* @param {*} newline | ||
*/ | ||
const lichtAn = async (_this) => { | ||
const light_list = Array.prototype.slice.apply($("state[id=*](functions=licht)")); | ||
// let listLightsOn = ""; | ||
const idBySelector = async (_this, selector, text, userToSend, newline) => { | ||
let text2Send = ""; | ||
try { | ||
if (selector.includes("functions")) { | ||
const functions = selector.replace("functions=", ""); | ||
let enums = []; | ||
const result = await _this.getEnumsAsync(); | ||
if (result && result["enum.functions"][`enum.functions.${functions}`]) { | ||
enums = result["enum.functions"][`enum.functions.${functions}`].common.members; | ||
if (enums) { | ||
const promises = enums.map(async (id) => { | ||
const value = await _this.getForeignStateAsync(id); | ||
if (value && value.val) { | ||
_this.log.debug("Value " + JSON.stringify(value.val)); | ||
_this.log.debug("text " + JSON.stringify(text)); | ||
let newtext = text; | ||
let name; | ||
if (text.includes("{common.name}")) { | ||
_this.log.debug("test "); | ||
name = await _this.getForeignObjectAsync(id); | ||
_this.log.debug("Name " + JSON.stringify(name)); | ||
// _this.log.debug("Name " + JSON.stringify(await _this.getForeignObjectAsync(id))); | ||
if (name && name.common.name) | ||
newtext = newtext.replace("{common.name}", name.common.name); | ||
} | ||
if (text.includes("&&")) text2Send += newtext.replace("&&", value.val); | ||
else { | ||
text2Send += newtext; | ||
text2Send += " " + value.val; | ||
} | ||
} | ||
if (newline == "true" || newline == true) text2Send += "\n"; | ||
else text2Send += " "; | ||
_this.log.debug("text2send " + JSON.stringify(text2Send)); | ||
}); | ||
Promise.all(promises) | ||
.then(() => { | ||
_this.log.debug("text2send " + JSON.stringify(text2Send)); | ||
_this.log.debug("usertosend " + JSON.stringify(userToSend)); | ||
for (const element of light_list) { | ||
const obj = await _this.getObjectAsync(element); | ||
if (obj) { | ||
const val = await _this.getStateAsync(obj?._id); | ||
if (val && val.val) { | ||
// const text = ` ${obj.common.name}: ${val.val} \n` | ||
// .replace("_", " ") | ||
// .replace("_", " ") | ||
// .replace("POWER", ""); | ||
// listLightsOn += text; | ||
sendToTelegram(_this, userToSend, text2Send); | ||
}) | ||
.catch((e) => { | ||
_this.log.debug("Error " + JSON.stringify(e)); | ||
}); | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
_this.log.debug("Error " + JSON.stringify(error)); | ||
} | ||
// sendToTelegram(this, "", listLightsOn); | ||
}; | ||
@@ -72,5 +107,9 @@ | ||
const wertUebermitteln = async (_this, user, id, textVorVal, textNachVal) => { | ||
const value = await _this.getStateAsync(id); | ||
if (value && value.val && typeof value.val == "string") { | ||
sendToTelegram(this, user, `${textVorVal} ${value.val} ${textNachVal}`); | ||
try { | ||
const value = await _this.getStateAsync(id); | ||
if (value && value.val && typeof value.val == "string") { | ||
sendToTelegram(this, user, `${textVorVal} ${value.val} ${textNachVal}`); | ||
} | ||
} catch (e) { | ||
_this.log.debug("Error " + JSON.stringify(e)); | ||
} | ||
@@ -126,4 +165,3 @@ }; | ||
listOfSetStateIds.push(id); | ||
const toggle = element.checkboxes[key] === "true"; | ||
const toggle = element.switch_checkbox[key] === "true"; | ||
let value; | ||
@@ -134,2 +172,3 @@ // Aus true oder false einen boolean machen | ||
} else value = element.values[key]; | ||
const newObj = { | ||
@@ -156,3 +195,3 @@ id: element.IDs[key], | ||
text: element.text[key].replace(/&/g, "&"), | ||
newline: element.checkboxes[key], | ||
newline: element.newline_checkbox[key], | ||
nav: element.nav, | ||
@@ -188,3 +227,3 @@ }; | ||
editArrayButtons, | ||
lichtAn, | ||
idBySelector, | ||
wertUebermitteln, | ||
@@ -191,0 +230,0 @@ generateNewObjectStructure, |
const sendToTelegram = require("./telegram").sendToTelegram; | ||
const idBySelector = require("./action").idBySelector; | ||
function getstate(_this, part, userToSend) { | ||
@@ -6,29 +7,37 @@ try { | ||
let i = 1; | ||
part.getData.forEach((element) => { | ||
part.getData.forEach(async (element) => { | ||
_this.log.debug("Get Value ID " + JSON.stringify(element.id)); | ||
_this.getForeignStateAsync(element.id).then((value) => { | ||
if (value) { | ||
_this.log.debug("Value " + JSON.stringify(value)); | ||
} | ||
if (value) { | ||
const val = JSON.stringify(value.val); | ||
_this.log.debug("GetValue " + JSON.stringify(value.val)); | ||
_this.log.debug("Element.text " + JSON.stringify(element.text)); | ||
let newline = ""; | ||
if (element.newline) { | ||
newline = "\n"; | ||
const specificatorSelektor = "functions="; | ||
const id = element.id; | ||
if (id.indexOf(specificatorSelektor) != -1) { | ||
// const selector = id.replace(/\"/g, ""); | ||
idBySelector(_this, id, element.text, userToSend, element.newline); | ||
} else { | ||
_this.getForeignStateAsync(element.id).then((value) => { | ||
if (value) { | ||
_this.log.debug("Value " + JSON.stringify(value)); | ||
} | ||
if (element.text) { | ||
if (element.text.indexOf("&&") != -1) text += `${element.text.replace("&&", val)}${newline}`; | ||
else text += element.text + " " + val + newline; | ||
} else text += `${val} ${newline}`; | ||
_this.log.debug("Text " + JSON.stringify(text)); | ||
} | ||
_this.log.debug("Length & i: " + JSON.stringify({ length: part.getData.length, i: i })); | ||
if (i == part.getData.length) { | ||
_this.log.debug("User to send: " + JSON.stringify(userToSend)); | ||
if (userToSend) sendToTelegram(_this, userToSend, text); | ||
} | ||
i++; | ||
}); | ||
if (value) { | ||
const val = JSON.stringify(value.val); | ||
_this.log.debug("GetValue " + JSON.stringify(value.val)); | ||
_this.log.debug("Element.text " + JSON.stringify(element.text)); | ||
let newline = ""; | ||
if (element.newline) { | ||
newline = "\n"; | ||
} | ||
if (element.text) { | ||
if (element.text.indexOf("&&") != -1) | ||
text += `${element.text.replace("&&", val)}${newline}`; | ||
else text += element.text + " " + val + newline; | ||
} else text += `${val} ${newline}`; | ||
_this.log.debug("Text " + JSON.stringify(text)); | ||
} | ||
_this.log.debug("Length & i: " + JSON.stringify({ length: part.getData.length, i: i })); | ||
if (i == part.getData.length) { | ||
_this.log.debug("User to send: " + JSON.stringify(userToSend)); | ||
if (userToSend) sendToTelegram(_this, userToSend, text); | ||
} | ||
i++; | ||
}); | ||
} | ||
}); | ||
@@ -35,0 +44,0 @@ } catch (error) { |
320
main.js
@@ -26,2 +26,3 @@ "use strict"; | ||
let setStateIdsToListenTo; | ||
let restartAdapter = false; | ||
@@ -55,2 +56,19 @@ // Load your modules here, e.g.: | ||
/** | ||
* @type {{}} | ||
*/ | ||
const checkbox = this.config.checkbox; | ||
const globalUserActiv = checkbox["globalUserActiv"]; | ||
const one_time_keyboard = checkbox["oneTiKey"]; | ||
const resize_keyboard = checkbox["resKey"]; | ||
const userList = this.config.users; | ||
const globalUserList = this.config.usersForGlobal.split(","); | ||
const startsides = this.config.startsides; | ||
let token = this.config.tokenGrafana; | ||
const directoryPicture = this.config.directory; | ||
const userActiveCheckbox = this.config.userActiveCheckbox; | ||
const menu = { | ||
data: {}, | ||
}; | ||
const _this = this; | ||
this.getForeignObject(datapoint, async (err, obj) => { | ||
@@ -63,3 +81,7 @@ if (err || obj == null) { | ||
// Datenpunkt wurde gefunden | ||
telegramState = await this.getForeignStateAsync(datapoint); | ||
try { | ||
telegramState = await this.getForeignStateAsync(datapoint); | ||
} catch (e) { | ||
this.log.debug("Error " + JSON.stringify(e)); | ||
} | ||
telegramAktiv = telegramState?.val; | ||
@@ -72,6 +94,3 @@ if (!telegramAktiv) { | ||
this.setState("info.connection", true, true); | ||
const menu = { | ||
data: {}, | ||
}; | ||
const _this = this; | ||
const data = this.config.data; | ||
@@ -100,13 +119,2 @@ const nav = data["nav"]; | ||
const checkbox = this.config.checkbox; | ||
const globalUserActiv = this.config.checkbox[0]["globalUserActiv"]; | ||
const one_time_keyboard = this.config.checkbox[2]["oneTiKey"]; | ||
const resize_keyboard = this.config.checkbox[1]["resKey"]; | ||
const userList = this.config.users; | ||
const globalUserList = this.config.usersForGlobal.split(","); | ||
const startsides = this.config.startsides; | ||
let token = this.config.tokenGrafana; | ||
const directoryPicture = this.config.directory; | ||
const userActiveCheckbox = this.config.userActiveCheckbox; | ||
this.log.debug("Checkbox " + JSON.stringify(checkbox)); | ||
@@ -117,33 +125,17 @@ this.log.debug("UserList: " + JSON.stringify(userList)); | ||
if (globalUserActiv) { | ||
this.log.debug("Global Users sendto "); | ||
globalUserList.forEach((user) => { | ||
const startside = [startsides["Global"]].toString(); | ||
if (!restartAdapter) { | ||
if (globalUserActiv) { | ||
this.log.debug("Global Users sendto "); | ||
globalUserList.forEach((user) => { | ||
const startside = [startsides["Global"]].toString(); | ||
if (startside && typeof startside == "string") | ||
this.log.debug("Text Global " + JSON.stringify(menu)); | ||
if (startside && typeof startside == "string") | ||
this.log.debug("Text Global " + JSON.stringify(menu)); | ||
if (startside && typeof startside == "string") | ||
sendToTelegram( | ||
this, | ||
user, | ||
menu.data.Global[startside].text, | ||
menu.data.Global[startside].nav, | ||
instanceTelegram, | ||
resize_keyboard, | ||
one_time_keyboard, | ||
); | ||
}); | ||
} else { | ||
try { | ||
this.log.debug("UserList " + JSON.stringify(userList)); | ||
userList.forEach((user) => { | ||
this.log.debug("User " + JSON.stringify(user)); | ||
const startside = [startsides[user]].toString(); | ||
if (user != "Global" && userActiveCheckbox[user]) | ||
if (startside && typeof startside == "string") | ||
sendToTelegram( | ||
_this, | ||
this, | ||
user, | ||
menu.data[user][startside].text, | ||
menu.data[user][startside].nav, | ||
menu.data.Global[startside].text, | ||
menu.data.Global[startside].nav, | ||
instanceTelegram, | ||
@@ -154,41 +146,14 @@ resize_keyboard, | ||
}); | ||
} catch (error) { | ||
console.log("Error read UserList" + error); | ||
} | ||
} | ||
this.on("stateChange", async (id, state) => { | ||
let userToSend; | ||
if (state && typeof state.val === "string" && state.val != "" && id == telegramID) { | ||
const value = state.val; | ||
const user = value.slice(1, value.indexOf("]")); | ||
const toDo = value.slice(value.indexOf("]") + 1, value.length); | ||
this.log.debug("Value: " + JSON.stringify(value)); | ||
this.log.debug("User: " + JSON.stringify(user)); | ||
this.log.debug("Todo: " + JSON.stringify(toDo)); | ||
let nav; | ||
userToSend = null; | ||
if (globalUserActiv) { | ||
nav = menu.data["Global"]; | ||
if (globalUserList.indexOf(user) != -1) userToSend = user; | ||
} else { | ||
nav = menu.data[user]; | ||
userToSend = user; | ||
} | ||
this.log.debug("Nav " + JSON.stringify(nav)); | ||
this.log.debug("Menu " + JSON.stringify(menu.data)); | ||
if (nav[toDo] && userToSend && userActiveCheckbox[userToSend]) { | ||
const part = nav[toDo]; | ||
this.log.debug("Part " + JSON.stringify(part)); | ||
// Navigation | ||
if (part.nav) { | ||
this.log.debug("User to send: " + JSON.stringify(userToSend)); | ||
this.log.debug("Todo " + JSON.stringify(toDo)); | ||
this.log.debug("Part.nav: " + JSON.stringify(part.nav)); | ||
if (userToSend) | ||
} else { | ||
try { | ||
this.log.debug("UserList " + JSON.stringify(userList)); | ||
userList.forEach((user) => { | ||
this.log.debug("User " + JSON.stringify(user)); | ||
const startside = [startsides[user]].toString(); | ||
if (user != "Global" && userActiveCheckbox[user]) | ||
sendToTelegram( | ||
this, | ||
userToSend, | ||
part.text, | ||
part.nav, | ||
_this, | ||
user, | ||
menu.data[user][startside].text, | ||
menu.data[user][startside].nav, | ||
instanceTelegram, | ||
@@ -198,67 +163,141 @@ resize_keyboard, | ||
); | ||
}); | ||
} catch (error) { | ||
console.log("Error read UserList" + error); | ||
} | ||
} | ||
restartAdapter = false; | ||
} | ||
} | ||
//TODO - heraus nehmen damit auf den connection state reagiert wird | ||
let oldValue; | ||
this.on("stateChange", async (id, state) => { | ||
try { | ||
let userToSend; | ||
if (telegramAktiv) { | ||
if (state && typeof state.val === "string" && state.val != "" && id == telegramID) { | ||
const value = state.val; | ||
const user = value.slice(1, value.indexOf("]")); | ||
const toDo = value.slice(value.indexOf("]") + 1, value.length); | ||
this.log.debug("Value: " + JSON.stringify(value)); | ||
this.log.debug("User: " + JSON.stringify(user)); | ||
this.log.debug("Todo: " + JSON.stringify(toDo)); | ||
let nav; | ||
userToSend = null; | ||
if (globalUserActiv) { | ||
nav = menu.data["Global"]; | ||
if (globalUserList.indexOf(user) != -1) userToSend = user; | ||
} else { | ||
nav = menu.data[user]; | ||
userToSend = user; | ||
} | ||
// Schalten | ||
if (part.switch) { | ||
setStateIdsToListenTo = setstate(_this, part, userToSend); | ||
} | ||
if (part.getData) { | ||
getstate(_this, part, userToSend); | ||
} | ||
if (part.sendPic) { | ||
try { | ||
this.log.debug("Send Picture"); | ||
this.log.debug("Nav " + JSON.stringify(nav)); | ||
this.log.debug("Menu " + JSON.stringify(menu.data)); | ||
if (nav[toDo] && userToSend && userActiveCheckbox[userToSend]) { | ||
const part = nav[toDo]; | ||
this.log.debug("Part " + JSON.stringify(part)); | ||
// Navigation | ||
if (part.nav) { | ||
this.log.debug("User to send: " + JSON.stringify(userToSend)); | ||
this.log.debug("Todo " + JSON.stringify(toDo)); | ||
this.log.debug("Part.nav: " + JSON.stringify(part.nav)); | ||
if (userToSend) | ||
sendToTelegram( | ||
this, | ||
userToSend, | ||
part.text, | ||
part.nav, | ||
instanceTelegram, | ||
resize_keyboard, | ||
one_time_keyboard, | ||
); | ||
} | ||
// Schalten | ||
if (part.switch) { | ||
setStateIdsToListenTo = setstate(_this, part, userToSend); | ||
} | ||
if (part.getData) { | ||
getstate(_this, part, userToSend); | ||
} | ||
if (part.sendPic) { | ||
try { | ||
this.log.debug("Send Picture"); | ||
part.sendPic.forEach((element) => { | ||
// this.log.debug("Element " + JSON.stringify(element)); | ||
token = token.trim(); | ||
const url = element.id; | ||
const newUrl = url.replace(/&/g, "&"); | ||
exec( | ||
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`, | ||
); | ||
this.log.debug( | ||
"url " + | ||
part.sendPic.forEach((element) => { | ||
// this.log.debug("Element " + JSON.stringify(element)); | ||
token = token.trim(); | ||
const url = element.id; | ||
const newUrl = url.replace(/&/g, "&"); | ||
exec( | ||
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`, | ||
); | ||
timeoutKey += 1; | ||
const path = `${directoryPicture}${element.fileName}`; | ||
const timeout = setTimeout(async () => { | ||
sendToTelegram(_this, userToSend, path); | ||
); | ||
this.log.debug( | ||
"url " + | ||
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`, | ||
); | ||
timeoutKey += 1; | ||
const path = `${directoryPicture}${element.fileName}`; | ||
const timeout = setTimeout(async () => { | ||
sendToTelegram(_this, userToSend, path); | ||
let timeoutToClear = {}; | ||
timeoutToClear = timeouts.filter((item) => item.key == timeoutKey); | ||
clearTimeout(timeoutToClear.timeout); | ||
timeouts = timeouts.filter((item) => item.key !== timeoutKey); | ||
}, element.delay); | ||
timeouts.push({ key: timeoutKey, timeout: timeout }); | ||
}); | ||
} catch (e) { | ||
this.log.error("Error :" + JSON.stringify(e)); | ||
let timeoutToClear = {}; | ||
timeoutToClear = timeouts.filter((item) => item.key == timeoutKey); | ||
clearTimeout(timeoutToClear.timeout); | ||
timeouts = timeouts.filter((item) => item.key !== timeoutKey); | ||
}, element.delay); | ||
timeouts.push({ key: timeoutKey, timeout: timeout }); | ||
}); | ||
} catch (e) { | ||
this.log.error("Error :" + JSON.stringify(e)); | ||
} | ||
} | ||
} else { | ||
if (typeof userToSend == "string") | ||
sendToTelegram(this, userToSend, "Eintrag wurde nicht gefunden!"); | ||
} | ||
} else { | ||
if (typeof userToSend == "string") | ||
sendToTelegram(this, userToSend, "Eintrag wurde nicht gefunden!"); | ||
// Auf Setstate reagieren und Wert schicken | ||
} else if ( | ||
state && | ||
setStateIdsToListenTo && | ||
setStateIdsToListenTo.find((element) => element.id == id) | ||
) { | ||
this.log.debug("State, which is listen to was changed " + JSON.stringify(id)); | ||
setStateIdsToListenTo.forEach((element, key) => { | ||
if (element.id == id) { | ||
this.log.debug("Send Value " + JSON.stringify(element)); | ||
if (element.confirm != "false") { | ||
this.log.debug("User " + JSON.stringify(element.userToSend)); | ||
let textToSend = element.returnText; | ||
// Wenn eine Rückkgabe des Value an den User nicht gewünscht ist soll value durch einen leeren String ersetzt werden | ||
let value; | ||
textToSend?.toString().includes("{novalue}") | ||
? (value = "") | ||
: (value = state.val); | ||
textToSend = textToSend.replace("{novalue}", ""); | ||
textToSend.indexOf("&&") != -1 | ||
? (textToSend = textToSend.replace("&&", value)) | ||
: (textToSend += " " + value); | ||
sendToTelegram(this, element.userToSend, textToSend); | ||
// Die Elemente auf die Reagiert wurde entfernen | ||
setStateIdsToListenTo.splice(key, 1); | ||
} | ||
} | ||
}); | ||
} | ||
// Auf Setstate reagieren und Wert schicken | ||
} else if (state && setStateIdsToListenTo.find((element) => element.id == id)) { | ||
this.log.debug("State, which is listen to was changed " + JSON.stringify(id)); | ||
setStateIdsToListenTo.forEach((element, key) => { | ||
if (element.id == id) { | ||
this.log.debug("Send Value " + JSON.stringify(element)); | ||
if (element.confirm != "false") { | ||
this.log.debug("User " + JSON.stringify(element.userToSend)); | ||
let textToSend = element.returnText; | ||
textToSend.indexOf("&$amp;") != -1 | ||
? textToSend.replace("&$amp;", state.val) | ||
: (textToSend += " " + state.val); | ||
sendToTelegram(this, element.userToSend, textToSend); | ||
// Die Elemente auf die Reagiert wurde entfernen | ||
setStateIdsToListenTo.splice(key, 1); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
if (state && id == `${instanceTelegram}.info.connection`) { | ||
this.log.debug("Oldvalue " + JSON.stringify(oldValue)); | ||
if (!oldValue) { | ||
this.log.debug("Restart Adapter Telegram Menu"); | ||
restartAdapter = true; | ||
this.restart(); | ||
} | ||
oldValue = state.val; | ||
if (!state.val) telegramAktiv = false; | ||
} | ||
} catch (e) { | ||
this.log.debug("Error " + JSON.stringify(e)); | ||
} | ||
}); | ||
} | ||
@@ -301,5 +340,5 @@ }); | ||
this.subscribeForeignStatesAsync("telegram.0.communicate.request"); | ||
this.subscribeForeignStatesAsync(telegramID); | ||
this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`); | ||
this.subscribeStates(telegramID); | ||
/* | ||
@@ -368,2 +407,3 @@ setState examples | ||
// if (state) { | ||
// // The state was changed | ||
@@ -370,0 +410,0 @@ // this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); |
{ | ||
"name": "iobroker.telegram-menu", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Easily create Telegram Menus", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -36,2 +36,10 @@ ![Logo](admin/telegram-menu.png) | ||
--> | ||
### 0.1.1 (2023-05-18) | ||
- shift rows | ||
- small fixes | ||
- Darkmode fixed | ||
- option, return text without value | ||
- get all Values of functions | ||
### 0.1.0 (2023-05-07) | ||
@@ -38,0 +46,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
393208
2134
92