From b7c0f57b6c08c5ca60120ed18fb6ac7e312c9b06 Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Sun, 22 Dec 2024 08:04:26 +0100 Subject: [PATCH] #228 add polling intervall an lint --- admin/jsonConfig.json | 19 +++++-- admin/words.js | 114 ++++++++++++++++++++++++++++++++++++++---- main.js | 107 +++++++++++++++++++++++++++++---------- 3 files changed, 199 insertions(+), 41 deletions(-) diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 240650d..5fa00ea 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -28,7 +28,7 @@ "items": [ { "type": "text", - "width": "20%", + "width": "25%", "title": { "en": "Name" }, @@ -60,8 +60,8 @@ "default": "" }, { - "type": "text", - "width": "20%", + "type": "number", + "width": "10%", "title": { "en": "Port" }, @@ -70,9 +70,20 @@ "sort": true, "default": "80" }, + { + "type": "number", + "width": "10%", + "title": { + "en": "Update period" + }, + "attr": "polling", + "filter": false, + "sort": true, + "default": "360" + }, { "type": "select", - "width": "20%", + "width": "15%", "title": { "en": "Type" }, diff --git a/admin/words.js b/admin/words.js index fe64a41..eb5e01d 100644 --- a/admin/words.js +++ b/admin/words.js @@ -1,5 +1,3 @@ -/* eslint-disable quote-props */ -// eslint-disable-next-line no-unused-vars /* global systemDictionary:true */ /* +===================== DO NOT MODIFY ======================+ @@ -7,14 +5,110 @@ | `translate-adapter adminLanguages2words` to update it. | +===================== DO NOT MODIFY ======================+ */ -"use strict"; +'use strict'; systemDictionary = { - "Extended logging": { en: "Extended logging", de: "Erweiterte Protokollierung", ru: "Расширенное ведение журнала", pt: "Registro estendido", nl: "Uitgebreide logboekregistratie", fr: "Journalisation étendue", it: "Registrazione estesa", es: "Registro extendido", pl: "Rozszerzone logowanie", uk: "Розширений журнал", "zh-cn": "扩展日志记录" }, - "Name": { en: "Name", de: "Name", ru: "Имя", pt: "Nome", nl: "Naam", fr: "Nom", it: "Nome", es: "Nombre", pl: "Nazwa", uk: "Ім'я", "zh-cn": "姓名" }, - "IP Adress": { en: "IP Adress", de: "IP Adresse", ru: "IP адрес", pt: "Endereço de IP", nl: "IP adres", fr: "Adresse IP", it: "Indirizzo IP", es: "Dirección IP", pl: "Adres IP", uk: "Веб-камера", "zh-cn": "IP地址" }, - "Port": { en: "Port", de: "Port", ru: "Порт", pt: "Porta", nl: "Port", fr: "Port", it: "Porta", es: "Puerto", pl: "Port", uk: "Портфоліо", "zh-cn": "港口" }, - "Smart name": { en: "Smart name", de: "Smart Name", ru: "Умное имя", pt: "Nome inteligente", nl: "Slimme naam", fr: "Nom intelligent", it: "Nome intelligente", es: "Nombre inteligente", pl: "Inteligentna nazwa", uk: "Розумне ім'я", "zh-cn": "聪明的名字" }, - "Type": { en: "Type", de: "Typ", ru: "Тип", pt: "Modelo", nl: "Type", fr: "Taper", it: "Tipo", es: "Escribe", pl: "Rodzaj", uk: "Тип", "zh-cn": "类型" }, - "blebox adapter settings": { en: "Adapter settings for blebox", de: "Adaptereinstellungen für blebox", ru: "Настройки адаптера для blebox", pt: "Configurações do adaptador para blebox", nl: "Adapterinstellingen voor blebox", fr: "Paramètres d'adaptateur pour blebox", it: "Impostazioni dell'adattatore per blebox", es: "Ajustes del adaptador para blebox", pl: "Ustawienia adaptera dla blebox", "zh-cn": "blebox的适配器设置" } + 'Extended logging': { + en: 'Extended logging', + de: 'Erweiterte Protokollierung', + ru: 'Расширенное ведение журнала', + pt: 'Registro estendido', + nl: 'Uitgebreide logboekregistratie', + fr: 'Journalisation étendue', + it: 'Registrazione estesa', + es: 'Registro extendido', + pl: 'Rozszerzone logowanie', + uk: 'Розширений журнал', + 'zh-cn': '扩展日志记录', + }, + Name: { + en: 'Name', + de: 'Name', + ru: 'Имя', + pt: 'Nome', + nl: 'Naam', + fr: 'Nom', + it: 'Nome', + es: 'Nombre', + pl: 'Nazwa', + uk: "Ім'я", + 'zh-cn': '姓名', + }, + 'IP Adress': { + en: 'IP Adress', + de: 'IP Adresse', + ru: 'IP адрес', + pt: 'Endereço de IP', + nl: 'IP adres', + fr: 'Adresse IP', + it: 'Indirizzo IP', + es: 'Dirección IP', + pl: 'Adres IP', + uk: 'Веб-камера', + 'zh-cn': 'IP地址', + }, + Port: { + en: 'Port', + de: 'Port', + ru: 'Порт', + pt: 'Porta', + nl: 'Port', + fr: 'Port', + it: 'Porta', + es: 'Puerto', + pl: 'Port', + uk: 'Портфоліо', + 'zh-cn': '港口', + }, + 'Smart name': { + en: 'Smart name', + de: 'Smart Name', + ru: 'Умное имя', + pt: 'Nome inteligente', + nl: 'Slimme naam', + fr: 'Nom intelligent', + it: 'Nome intelligente', + es: 'Nombre inteligente', + pl: 'Inteligentna nazwa', + uk: "Розумне ім'я", + 'zh-cn': '聪明的名字', + }, + Type: { + en: 'Type', + de: 'Typ', + ru: 'Тип', + pt: 'Modelo', + nl: 'Type', + fr: 'Taper', + it: 'Tipo', + es: 'Escribe', + pl: 'Rodzaj', + uk: 'Тип', + 'zh-cn': '类型', + }, + 'Update period': { + en: 'Update period', + de: 'Aktualisierungszeitraum', + ru: 'Период обновления', + pt: 'Período de atualização', + nl: 'Bijwerken periode', + fr: 'Période de mise à jour', + it: 'Periodo di aggiornamento', + es: 'Período de actualización', + pl: 'Okres aktualizacji', + uk: 'Період оновлення', + 'zh-cn': '更新期', + }, + 'blebox adapter settings': { + en: 'Adapter settings for blebox', + de: 'Adaptereinstellungen für blebox', + ru: 'Настройки адаптера для blebox', + pt: 'Configurações do adaptador para blebox', + nl: 'Adapterinstellingen voor blebox', + fr: "Paramètres d'adaptateur pour blebox", + it: "Impostazioni dell'adattatore per blebox", + es: 'Ajustes del adaptador para blebox', + pl: 'Ustawienia adaptera dla blebox', + 'zh-cn': 'blebox的适配器设置', + }, }; diff --git a/main.js b/main.js index 9efabfd..c34f22f 100644 --- a/main.js +++ b/main.js @@ -75,10 +75,18 @@ class Blebox extends utils.Adapter { tools.getBleboxData(device, 'settingsState'); tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'shutterExtendedState'); - schedule.scheduleJob('*/10 * * * *', function () { - tools.getBleboxData(device, 'deviceUptime'); - tools.getBleboxData(device, 'shutterExtendedState'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'shutterExtendedState') + .then(data => this.log.info('shutterExtendedState:', data)) + .catch(err => this.log.error('Fehler bei shutterExtendedState:', err)); + }, device.polling * 1000); + } this.subscribeStates(`${device.dev_name}.command.*`); break; case 'tvlift': @@ -86,19 +94,32 @@ class Blebox extends utils.Adapter { tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'deviceNetwork'); tools.getBleboxData(device, 'tvliftExtendedState'); - schedule.scheduleJob('*/10 * * * *', function () { - tools.getBleboxData(device, 'deviceUptime'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + }, device.polling * 1000); + } this.subscribeStates(`${device.dev_name}.command.*`); break; case 'gatebox': gatebox.init(); tools.getBleboxData(device, 'settingsState'); tools.getBleboxData(device, 'deviceState'); - schedule.scheduleJob('*/10 * * * * *', function () { - tools.getBleboxData(device, 'deviceUptime'); - tools.getBleboxData(device, 'gateExtendedState'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'gateExtendedState') + .then(data => this.log.info('gateExtendedState:', data)) + .catch(err => this.log.error('Fehler bei gateExtendedState:', err)); + }, device.polling * 1000); + } this.subscribeStates(`${device.dev_name}.command.*`); break; case 'switchbox': @@ -106,39 +127,71 @@ class Blebox extends utils.Adapter { tools.getBleboxData(device, 'settingsState'); tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'switchExtendedState'); - schedule.scheduleJob('*/10 * * * *', function () { - tools.getBleboxData(device, 'deviceUptime'); - tools.getBleboxData(device, 'switchExtendedState'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'switchExtendedState') + .then(data => this.log.info('switchExtendedState:', data)) + .catch(err => this.log.error('Fehler bei switchExtendedState:', err)); + }, device.polling * 1000); + } this.subscribeStates(`${device.dev_name}.command.*`); break; case 'tempsensor': tempsensor.init(); tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'tempsensorExtendedState'); - schedule.scheduleJob('*/10 * * * * *', function () { - tools.getBleboxData(device, 'tempsensorExtendedState'); - tools.getBleboxData(device, 'deviceUptime'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'tempsensorExtendedState') + .then(data => this.log.info('tempsensorExtendedState:', data)) + .catch(err => this.log.error('Fehler bei tempsensorExtendedState:', err)); + }, device.polling * 1000); + } break; case 'multisensor': multisensor.init(); tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'multisensorExtendedState'); - schedule.scheduleJob('*/10 * * * * *', function () { - tools.getBleboxData(device, 'multisensorExtendedState'); - tools.getBleboxData(device, 'deviceUptime'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'multisensorExtendedState') + .then(data => this.log.info('multisensorExtendedState:', data)) + .catch(err => this.log.error('Fehler bei multisensorExtendedState:', err)); + }, device.polling * 1000); + } break; case 'saunabox': saunabox.init(); tools.getBleboxData(device, 'deviceState'); tools.getBleboxData(device, 'saunaboxExtendedState'); this.subscribeStates(`${device.dev_name}.command.*`); - schedule.scheduleJob('*/30 * * * * *', function () { - tools.getBleboxData(device, 'saunaboxExtendedState'); - tools.getBleboxData(device, 'deviceUptime'); - }); + if (device.polling > 0) { + setInterval(() => { + tools + .getBleboxData(device, 'deviceUptime') + .then(data => this.log.info('deviceUptime:', data)) + .catch(err => this.log.error('Fehler bei deviceUptime:', err)); + tools + .getBleboxData(device, 'saunaboxExtendedState') + .then(data => this.log.info('saunaboxExtendedState:', data)) + .catch(err => this.log.error('Fehler bei saunaboxExtendedState:', err)); + }, device.polling * 1000); + } break; default: break;