From cded34fbd4209379a865364d3a0cb92d387e452d Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:41:28 +0100 Subject: [PATCH 1/3] v4.3.2.1 - Update NsPanelTs.ts - Upgrade TFT 53 / 4.3.2 - Fix formatDate/Date.parse with moment.js --- ioBroker/NsPanelTs.ts | 82 ++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index 6bd7496ec..f28fb5c91 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -TypeScript v4.3.1.7 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @Sternmiere / @Britzelpuf / @ravenS0ne -- abgestimmt auf TFT 53 / v4.3.1 / BerryDriver 9 / Tasmota 13.1.0 +TypeScript v4.3.2.1 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @Sternmiere / @Britzelpuf / @ravenS0ne +- abgestimmt auf TFT 53 / v4.3.2 / BerryDriver 9 / Tasmota 13.2.0 @joBr99 Projekt: https://github.com/joBr99/nspanel-lovelace-ui/tree/main/ioBroker NsPanelTs.ts (dieses TypeScript in ioBroker) Stable: https://github.com/joBr99/nspanel-lovelace-ui/blob/main/ioBroker/NsPanelTs.ts icon_mapping.ts: https://github.com/joBr99/nspanel-lovelace-ui/blob/main/ioBroker/icon_mapping.ts (TypeScript muss in global liegen) @@ -19,7 +19,7 @@ Achtung Änderung des Sonoff ESP-Temperatursensors !!! Bitte "SetOption146 1" in der Tasmota-Console ausführen !!! ************************************************************************************************ In bestimmten Situationen kommt es vor, dass sich das Panel mit FlashNextion -unter Tasmota > 12.2.0 nicht flashen lässt. Für den Fall ein Tasmota Dowengrade +unter Tasmota > 12.2.0 nicht flashen lässt. Für den Fall ein Tasmota Downgrade durchführen und FlashNextion wiederholen. ************************************************************************************************ Ab Tasmota > 13.0.0 ist für ein Upgrade ggfs. eine Umpartitionierung erforderlich @@ -178,9 +178,10 @@ ReleaseNotes: - 03.10.2023 - v4.3.1.4 Removing the examples from the NSPanelTs.ts --> https://github.com/joBr99/nspanel-lovelace-ui/wiki/NSPanel-Page-%E2%80%90-Typen_How-2_Beispiele - 03.10.2023 - v4.3.1.4 Delete NsPanelTs_without_Examples.ts - 12.10.2023 - v4.3.1.5 Fix Datapoint for Role timetable -> Attention use new script from TT-Tom https://github.com/tt-tom17/MyScripts/blob/main/Sonoff_NSPanel/Fahrplan_to_NSPanel.ts - - 19.10.2023 - v4.3.1.6 Add more Alias Device-Types to Navigation (createEntity) / Minor Fixes - - 22.10.2023 - v4.3.1.7 Fix CreateEntity (navigate) role 'light' and 'socket' and 'temperature' - + - 19.10.2023 - v4.3.1.6 Add more Alias Device-Types to Navigation / Minor Fixes + - 30.10.2023 - v4.3.2 Upgrade TFT 53 / 4.3.2 + - 30.10.2023 - v4.3.2.1 Fix formatDate/Date.parse with moment.js (Bugs in JS-Methodes) + Todo: - XX.XX.XXXX - v4.4.0 Change the bottomScreensaverEntity (rolling) if more than 6 entries are defined @@ -272,7 +273,7 @@ Erforderliche Adapter: Upgrades in Konsole: Tasmota BerryDriver : Backlog UpdateDriverVersion https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be; Restart 1 - TFT EU STABLE Version : FlashNextion http://nspanel.pky.eu/lovelace-ui/github/nspanel-v4.3.1.tft + TFT EU STABLE Version : FlashNextion http://nspanel.pky.eu/lovelace-ui/github/nspanel-v4.3.2.tft --------------------------------------------------------------------------------------- */ @@ -743,7 +744,7 @@ export const config = { ScreensaverEntity: 'accuweather.0.Daily.Day1.Sunrise', ScreensaverEntityFactor: 1, ScreensaverEntityDecimalPlaces: 0, - ScreensaverEntityDateFormat: 'hh:mm', // like DD.MM or DD.MM.YY or YYYY/MM/DD or hh:mm + ScreensaverEntityDateFormat: { hour: '2-digit', minute: '2-digit' }, // Description at Wiki-Pages ScreensaverEntityIconOn: 'weather-sunset-up', ScreensaverEntityIconOff: null, ScreensaverEntityText: 'Sonne', @@ -873,9 +874,12 @@ export const config = { // _________________________________ Ab hier keine Konfiguration mehr _____________________________________ const request = require('request'); +const moment = require('moment'); +const parseFormat = require('moment-parseformat'); +moment.locale(getState(NSPanel_Path + 'Config.locale').val); //Desired Firmware -const tft_version: string = 'v4.3.1'; +const tft_version: string = 'v4.3.2'; const desired_display_firmware_version = 53; const berry_driver_version = 9; const tasmotaOtaUrl: string = 'http://ota.tasmota.com/tasmota32/release/'; @@ -3020,8 +3024,9 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = case 'sensor.window': case 'thermostat': + type = 'text'; - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'temperature' || o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); let unit = ''; optVal = '0'; @@ -3034,6 +3039,10 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); } + if (o.common.role == 'value.temperature') { + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('thermometer'); + } + iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); if (pageItem.colorScale != undefined) { @@ -3074,9 +3083,10 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconId = optVal; } } - - buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; - break; + + if (Debug) console.log('CreateEntity Icon role info, humidity, temperature, value.temperature, value.humidity, sensor.door, sensor.window, thermostat'); + if (Debug) console.log('CreateEntity ~' + type + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit); + return '~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit; case 'warning': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); @@ -3343,7 +3353,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = case 'thermostat': type = 'text'; - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'temperature' || o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); let unit = ''; optVal = '0'; @@ -3355,7 +3365,11 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = optVal = getState(pageItem.id + '.ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); } - + + if (o.common.role == 'value.temperature') { + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('thermometer'); + } + iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); if (pageItem.colorScale != undefined) { @@ -6919,8 +6933,15 @@ function HandleScreensaverUpdate(): void { } else if (typeof(val) == 'string') { iconColor = GetScreenSaverEntityColor(config.leftScreensaverEntity[i]); - if (!isNaN(Date.parse(val))) { - val = formatDate(getDateObject(val), config.leftScreensaverEntity[i].ScreensaverEntityDateFormat); + let pformat = parseFormat(val); + if (Debug) console.log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid()); + if (moment(val, pformat, true).isValid()) { + let DatumZeit = moment(val, pformat).unix(); // Umwandlung in Unix Time-Stamp + if (config.leftScreensaverEntity[i].ScreensaverEntityDateFormat !== undefined) { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val, config.leftScreensaverEntity[i].ScreensaverEntityDateFormat); + } else { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val); + } } } @@ -7053,10 +7074,15 @@ function HandleScreensaverUpdate(): void { } else if (typeof(val) == 'string') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[4]); - if (!isNaN(Date.parse(getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val))) { - val = formatDate(getDateObject(getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val), config.bottomScreensaverEntity[4].ScreensaverEntityDateFormat); - } else { - val = getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val; + let pformat = parseFormat(val); + if (Debug) console.log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid()); + if (moment(val, pformat, true).isValid()) { + let DatumZeit = moment(val, pformat).unix(); // Umwandlung in Unix Time-Stamp + if (config.bottomScreensaverEntity[4].ScreensaverEntityDateFormat !== undefined) { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val, config.bottomScreensaverEntity[4].ScreensaverEntityDateFormat); + } else { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val); + } } } if (existsObject(config.bottomScreensaverEntity[4].ScreensaverEntityIconColor)) { @@ -7102,10 +7128,18 @@ function HandleScreensaverUpdate(): void { } else if (typeof(val) == 'string') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[i]); - if (!isNaN(Date.parse(val))) { - val = formatDate(getDateObject(val), config.bottomScreensaverEntity[i].ScreensaverEntityDateFormat); + let pformat = parseFormat(val); + if (Debug) console.log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid()); + if (moment(val, pformat, true).isValid()) { + let DatumZeit = moment(val, pformat).unix(); // Umwandlung in Unix Time-Stamp + if (config.bottomScreensaverEntity[i].ScreensaverEntityDateFormat !== undefined) { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val, config.bottomScreensaverEntity[i].ScreensaverEntityDateFormat); + } else { + val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val); + } } } + if (existsObject(config.bottomScreensaverEntity[i].ScreensaverEntityIconColor)) { iconColor = getState(config.bottomScreensaverEntity[i].ScreensaverEntityIconColor).val; } @@ -8174,7 +8208,7 @@ type ScreenSaverElement = { ScreensaverEntity: string | null, ScreensaverEntityFactor: number | 1, ScreensaverEntityDecimalPlaces: number | 0, - ScreensaverEntityDateFormat: string | null, + ScreensaverEntityDateFormat: any | null, ScreensaverEntityIconOn: string | null, ScreensaverEntityIconOff: string | null, ScreensaverEntityText: string | null, From 34181234e19ef4a94063987be4d437656b459235 Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:55:56 +0100 Subject: [PATCH 2/3] v4.3.2.1 - Update - Upgrade TFT 53 / 4.3.2 - Fix formatDate/Date.parse with moment.js (Bugs in JS-Methodes) --- ioBroker/NsPanelTs.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index f28fb5c91..15e9501a4 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -3024,9 +3024,8 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = case 'sensor.window': case 'thermostat': - type = 'text'; - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'temperature' || o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); let unit = ''; optVal = '0'; @@ -3039,10 +3038,6 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); } - if (o.common.role == 'value.temperature') { - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('thermometer'); - } - iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); if (pageItem.colorScale != undefined) { @@ -3083,10 +3078,9 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconId = optVal; } } - - if (Debug) console.log('CreateEntity Icon role info, humidity, temperature, value.temperature, value.humidity, sensor.door, sensor.window, thermostat'); - if (Debug) console.log('CreateEntity ~' + type + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit); - return '~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit; + + buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; + break; case 'warning': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); @@ -3353,7 +3347,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = case 'thermostat': type = 'text'; - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); + iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : o.common.role == 'temperature' || o.common.role == 'value.temperature' || o.common.role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); let unit = ''; optVal = '0'; @@ -3365,11 +3359,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = optVal = getState(pageItem.id + '.ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); } - - if (o.common.role == 'value.temperature') { - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('thermometer'); - } - + iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); if (pageItem.colorScale != undefined) { From 31c237252056092d51b43ec6927587095fd6cd94 Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:03:29 +0100 Subject: [PATCH 3/3] v4.3.2.1 - Update - Upgrade TFT 53 / 4.3.2 - Fix formatDate/Date.parse with moment.js --- ioBroker/NsPanelTs.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index 15e9501a4..109d54e1d 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -179,6 +179,7 @@ ReleaseNotes: - 03.10.2023 - v4.3.1.4 Delete NsPanelTs_without_Examples.ts - 12.10.2023 - v4.3.1.5 Fix Datapoint for Role timetable -> Attention use new script from TT-Tom https://github.com/tt-tom17/MyScripts/blob/main/Sonoff_NSPanel/Fahrplan_to_NSPanel.ts - 19.10.2023 - v4.3.1.6 Add more Alias Device-Types to Navigation / Minor Fixes + - 22.10.2023 - v4.3.1.7 Fix CreateEntity (navigate) role 'light' and 'socket' and 'temperature' - 30.10.2023 - v4.3.2 Upgrade TFT 53 / 4.3.2 - 30.10.2023 - v4.3.2.1 Fix formatDate/Date.parse with moment.js (Bugs in JS-Methodes)