From a2b805f4e189add18d2b967402fe911d8536ca8e Mon Sep 17 00:00:00 2001 From: ticaki Date: Fri, 12 Jan 2024 20:38:47 +0100 Subject: [PATCH 01/17] SendTime - optimated --- ioBroker/DEV/NSPanelTs.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 14dad67e..13c99002 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -3267,11 +3267,12 @@ function SendDate(): void { function SendTime(): void { try { - const d = new Date(); + /*const d = new Date(); const hr = (d.getHours() < 10 ? '0' : '') + d.getHours(); const min = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(); - SendToPanel({ payload: 'time~' + hr + ':' + min }); + SendToPanel({ payload: 'time~' + hr + ':' + min });*/ + SendToPanel({ payload: `time~${new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`, }); } catch (err: any) { log('error at function SendTime: ' + err.message, 'warn'); } From b7fd06413dea74fef986b6e826bda5b4729f21c7 Mon Sep 17 00:00:00 2001 From: ticaki Date: Fri, 12 Jan 2024 20:42:54 +0100 Subject: [PATCH 02/17] remove all --- ioBroker/DEV/NSPanelTs.ts | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 13c99002..27164030 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -3049,7 +3049,7 @@ on({ id: NSPanel_Alarm_Path + 'Alarm.AlarmState', change: 'ne' }, async (obj) => } }); -function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | undefined, words: Array | undefined): void { +function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | undefined, words: string[] | undefined): void { try { if (typ == 'event') { switch (method as NSPanel.EventMethod) { @@ -3254,7 +3254,7 @@ function SendDate(): void { const options: any = { weekday: dpWeekday, year: 'numeric', month: dpMonth, day: 'numeric' }; const _SendDate = dpCustomFormat != '' ? dayjs().format(dpCustomFormat) : date.toLocaleDateString(getState(NSPanel_Path + 'Config.locale').val, options); - SendToPanel({ payload: 'date~' + _SendDate }); + SendToPanel({ payload: 'date~' + _SendDate }); } } catch (err: any) { if (err.message = 'Cannot convert undefined or null to object') { @@ -3271,8 +3271,8 @@ function SendTime(): void { const hr = (d.getHours() < 10 ? '0' : '') + d.getHours(); const min = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(); - SendToPanel({ payload: 'time~' + hr + ':' + min });*/ - SendToPanel({ payload: `time~${new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`, }); + SendToPanel({ payload: 'time~' + hr + ':' + min });*/ + SendToPanel({ payload: `time~${new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`, }); } catch (err: any) { log('error at function SendTime: ' + err.message, 'warn'); } @@ -3280,7 +3280,7 @@ function SendTime(): void { function GenerateEntitiesPage(page: NSPanel.PageEntities): NSPanel.Payload[] { try { - let out_msgs: Array; + let out_msgs: NSPanel.Payload[]; out_msgs = [{ payload: 'pageType~cardEntities' }] out_msgs.push({ payload: GeneratePageElements(page) }); return out_msgs @@ -3292,7 +3292,7 @@ function GenerateEntitiesPage(page: NSPanel.PageEntities): NSPanel.Payload[] { function GenerateGridPage(page: NSPanel.PageGrid): NSPanel.Payload[] { try { - let out_msgs: Array = [{ payload: 'pageType~cardGrid' }]; + let out_msgs: NSPanel.Payload[] = [{ payload: 'pageType~cardGrid' }]; out_msgs.push({ payload: GeneratePageElements(page) }); return out_msgs; } catch (err: any) { @@ -3303,7 +3303,7 @@ function GenerateGridPage(page: NSPanel.PageGrid): NSPanel.Payload[] { function GenerateGridPage2(page: NSPanel.PageGrid2): NSPanel.Payload[] { try { - let out_msgs: Array = [{ payload: 'pageType~cardGrid2' }]; + let out_msgs: NSPanel.Payload[] = [{ payload: 'pageType~cardGrid2' }]; out_msgs.push({ payload: GeneratePageElements(page) }); return out_msgs; } catch (err: any) { @@ -4311,7 +4311,7 @@ function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { try { UnsubscribeWatcher(); let id = page.items[0].id - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardThermo' }); // ioBroker @@ -5047,7 +5047,7 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { if (!page.items[0].id) throw new Error ('Missing page id for cardMedia!'); let id = page.items[0].id; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; if (!page.items[0].adapterPlayerInstance!) throw new Error('page.items[0].adapterPlayerInstance is undefined!') let vInstance = page.items[0].adapterPlayerInstance!; @@ -5335,7 +5335,7 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { //------------------------------------------------------------------------------------------------------------- // All Alexa devices (the online / player and commands directory is available) are listed and linked below // If the constant alexaSpeakerList contains at least one entry, the constant is used - otherwise all devices from the Alexa adapter - let speakerListArray: Array = []; + let speakerListArray: string[] = []; if (page.items[0].speakerList && page.items[0].speakerList.length > 0) { for (let i_index in page.items[0].speakerList) { speakerListArray.push(page.items[0].speakerList[i_index]); @@ -5666,7 +5666,7 @@ function GenerateAlarmPage(page: NSPanel.PageAlarm): NSPanel.Payload[] { let id = page.items[0].id let name = page.heading; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardAlarm' }); let nsPath = NSPanel_Alarm_Path + 'Alarm'; @@ -5824,7 +5824,7 @@ function GenerateUnlockPage(page: NSPanel.PageUnlock): NSPanel.Payload[] { let id = page.items[0].id let name = page.heading; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardAlarm' }); let dpPath : string = '' @@ -5905,7 +5905,7 @@ function GenerateQRPage(page: NSPanel.PageQR): NSPanel.Payload[] { activePage = page; if (!page.items[0].id) throw new Error ('Missing pageItem.id for cardQRPage!'); let id = page.items[0].id; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardQR' }); let dpPath : string = '' @@ -6046,7 +6046,7 @@ function GeneratePowerPage(page: NSPanel.PagePower): NSPanel.Payload[] { obj = JSON.parse((getState(page.items[0].id + '.ACTUAL').val)); } - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; // Leave the display on if the alwaysOnDisplay parameter is specified (true) if (page.type == 'cardPower' && pageCounter == 0 && page.items[0].alwaysOnDisplay != undefined) { @@ -6145,7 +6145,7 @@ function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] { activePage = page; let id = page.items[0].id; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~' + page.type }); let heading = page.heading !== undefined ? page.heading : "Chart..."; @@ -7408,7 +7408,7 @@ function GetNavigationString(pageId: number): string { function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOptional | undefined, pageItem: PageItem, placeId: number | undefined): NSPanel.Payload[] { if (Debug) log('GenerateDetailPage Übergabe Type: ' + type + ' - optional: ' + optional + ' - pageItem.id: ' + pageItem.id, 'info'); try { - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; let id = pageItem.id; if (id && existsObject(id)) { @@ -8210,7 +8210,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti // Playlist browsing not supported by squeezeboxrpc adapter. But Favorites can be used actualState = ''; // Not supported by squeezeboxrpc adapter let tempPlayList: string[] = []; - let pathParts: Array = pageItem.adapterPlayerInstance!.split('.'); + let pathParts: string[] = pageItem.adapterPlayerInstance!.split('.'); for (let favorite_index = 0; favorite_index < 45; favorite_index++) { let favorite_name_selector: string = [pathParts[0], pathParts[1], 'Favorites', favorite_index, 'Name'].join('.'); if (!existsObject(favorite_name_selector)) { @@ -8812,7 +8812,7 @@ function HandleScreensaverUpdate(): void { } if (Debug) log('HandleScreensaverUpdate payload: weatherUpdate~' + payloadString, 'info'); - SendToPanel({ payload: 'weatherUpdate~' + payloadString }); + SendToPanel({ payload: 'weatherUpdate~' + payloadString }); HandleScreensaverStatusIcons(); } @@ -9009,7 +9009,7 @@ function HandleScreensaverStatusIcons() : void { payloadString += '~'; } - SendToPanel({ payload: 'statusUpdate~' + payloadString }); + SendToPanel({ payload: 'statusUpdate~' + payloadString }); } catch (err: any) { log('error at function HandleScreensaverStatusIcons: ' + err.message, 'warn'); @@ -9104,7 +9104,7 @@ function HandleScreensaverColors(): void { rgb_dec565(sctMainTextAlt) + '~' + //tMainTextAlt rgb_dec565(sctTimeAdd); //tTimeAdd - SendToPanel({ payload: payloadString }); + SendToPanel({ payload: payloadString }); } catch (err: any) { log('error at function HandleScreensaverColors: '+ err.message, 'warn'); } @@ -9538,7 +9538,7 @@ function Interpolate(color1: RGB, color2: RGB, fraction: number): RGB { let r: number = InterpolateNum(color1.red, color2.red, fraction); let g: number = InterpolateNum(color1.green, color2.green, fraction); let b: number = InterpolateNum(color1.blue, color2.blue, fraction); - return { red: Math.round(r), green: Math.round(g), blue: Math.round(b) }; + return { red: Math.round(r), green: Math.round(g), blue: Math.round(b) }; } function InterpolateNum(d1: number, d2: number, fraction: number): number { From f65ff57a953ddf101c92ca80dab75c74b6ee04b6 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 15:55:46 +0100 Subject: [PATCH 03/17] HandleScreensaverStatusIcons rewritten fixed #1098 types: Number of PageItems defined --- ioBroker/DEV/NSPanelTs.ts | 329 ++++++++++++++++++++++++-------------- 1 file changed, 206 insertions(+), 123 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 1bd70320..827bf247 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -3154,9 +3154,9 @@ function findPageItem(searching: String): PageItem { function GeneratePage(page: PageType): void { try { activePage = page; - setIfExists(NSPanel_Path + 'ActivePage.type', activePage!.type); - setIfExists(NSPanel_Path + 'ActivePage.heading', activePage!.heading); - setIfExists(NSPanel_Path + 'ActivePage.id0', activePage!.items[0].id); + setIfExists(NSPanel_Path + 'ActivePage.type', activePage.type); + setIfExists(NSPanel_Path + 'ActivePage.heading', activePage.heading); + setIfExists(NSPanel_Path + 'ActivePage.id0', activePage.items[0] !== undefined ? activePage.items[0].id : ''); switch (page.type) { case 'cardEntities': SendToPanel(GenerateEntitiesPage(page)); @@ -4696,8 +4696,9 @@ function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { function unsubscribeMediaSubscriptions(): void { for (let i = 0; i < config.pages.length; i++) { - if (config.pages[i].type == 'cardMedia') { - let mediaID = config.pages[i].items[0].id; + const page: NSPanel.PageType = config.pages[i]; + if (isPageMedia(page)) { + let mediaID = page.items[0].id; unsubscribe(mediaID + '.STATE'); unsubscribe(mediaID + '.ARTIST'); unsubscribe(mediaID + '.TITLE'); @@ -4711,8 +4712,9 @@ function unsubscribeMediaSubscriptions(): void { } } for (let i = 0; i < config.subPages.length; i++) { - if (config.subPages[i].type == 'cardMedia') { - let mediaID = config.subPages[i].items[0].id; + const page: NSPanel.PageType = config.subPages[i]; + if (isPageMedia(page)) { + let mediaID = page.items[0].id; unsubscribe(mediaID + '.STATE'); unsubscribe(mediaID + '.ARTIST'); unsubscribe(mediaID + '.TITLE'); @@ -5999,14 +6001,16 @@ function GenerateQRPage(page: NSPanel.PageQR): NSPanel.Payload[] { function unsubscribePowerSubscriptions(): void { for (let i = 0; i < config.pages.length; i++) { - if (config.pages[i].type == 'cardPower') { - let powerID = config.pages[i].items[0].id; + const page: NSPanel.PageType = config.pages[i]; + if (isPagePower(page)) { + let powerID = page.items[0].id; unsubscribe(powerID + '.ACTUAL'); } } for (let i = 0; i < config.subPages.length; i++) { - if (config.subPages[i].type == 'cardPower') { - let powerID = config.subPages[i].items[0].id; + const page: NSPanel.PageType = config.pages[i]; + if (isPagePower(page)) { + let powerID = page.items[0].id; unsubscribe(powerID + '.ACTUAL'); } } @@ -8844,97 +8848,155 @@ function RegisterScreensaverEntityWatcher(id: string): void { function HandleScreensaverStatusIcons() : void { try { let payloadString = ''; - let hwBtn1Col: any = config.mrIcon1ScreensaverEntity.ScreensaverEntityOffColor; - if (config.mrIcon1ScreensaverEntity.ScreensaverEntity != null) { - // Prüfung ob ScreensaverEntity vom Typ String ist - if (typeof (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val) == 'string') { - if (Debug) log('Entity ist String', 'info') - let hwBtn1: string = getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val; - if (hwBtn1 == 'ON') { - hwBtn1Col = config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor; - } - if (Debug) log('Value: ' + hwBtn1 + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') + const iconData: Record<'mrIcon1' | 'mrIcon2', NSPanel.ScreenSaverMRDataElement> = { + mrIcon1: { + ScreensaverEntity: config.mrIcon1ScreensaverEntity.ScreensaverEntity != null + && existsState(config.mrIcon1ScreensaverEntity.ScreensaverEntity) + ? getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val + : null, + ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn != null + ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn) + : null, + ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff != null + ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff) + : null, + ScreensaverEntityOnColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor, + ScreensaverEntityOffColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOffColor, + ScreensaverEntityValue: config.mrIcon1ScreensaverEntity.ScreensaverEntityValue === null + ? null + : getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val, + ScreensaverEntityValueDecimalPlace: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace, + ScreensaverEntityValueUnit: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit, + - // Icon ermitteln - if (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val) { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn); - if (Debug) log('Icon if true '+payloadString, 'info') - } else { - if (config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff != null) { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff); - if (Debug) log('Icon else true '+payloadString, 'info') - } else { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn); - if (Debug) log('Icon else false '+payloadString, 'info') - } - } - if (config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit; - if (Debug) log('Value ist eine Zahl ' + payloadString, 'info') - } else { - payloadString += getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val - if (Debug) log('Value ist keine Zahl ' + payloadString, 'info') - } + }, + mrIcon2: { + ScreensaverEntity: config.mrIcon2ScreensaverEntity.ScreensaverEntity != null + && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity) + ? getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val + : null, + ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn != null + ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn) + : null, + ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null + ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff) + : null, + ScreensaverEntityOnColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor, + ScreensaverEntityOffColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor, + ScreensaverEntityValue: config.mrIcon2ScreensaverEntity.ScreensaverEntityValue === null + ? null + : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val, + ScreensaverEntityValueDecimalPlace: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace, + ScreensaverEntityValueUnit: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit, + } + } + for (const a in iconData) { + if (iconData[a].ScreensaverEntityValue === null) { + switch (typeof iconData[a].ScreensaverEntityValue) { + case "string": + if (iconData[a].ScreensaverEntityValue === '' || isNaN(iconData[a].ScreensaverEntityValue)) break; + case "number": + case "bigint": + iconData[a].ScreensaverEntityValue = Number(iconData[a].ScreensaverEntityValue).toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); + break; + case "boolean": + break; + case "symbol": + case "undefined": + case "object": + case "function": + iconData[a].ScreensaverEntityValue = null; } - payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; - } else if (typeof (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val) == 'boolean') { - let hwBtn1: boolean = getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val; - if (hwBtn1) { - hwBtn1Col = config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor; - } - if (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val) { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn); - } else { - if (config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff != null) { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff); - } else { - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn); + } + let hwBtn1Col: RGB = iconData[a].ScreensaverEntityOffColor; + if (iconData[a].ScreensaverEntity != null) { + // Prüfung ob ScreensaverEntity vom Typ String ist + if (typeof (iconData[a].ScreensaverEntity) == 'string') { + if (Debug) log('Entity ist String', 'info') + let hwBtn1: string = iconData[a].ScreensaverEntity; + if (hwBtn1 == 'ON') { + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; } - } - if (config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit; + if (Debug) log('Value: ' + hwBtn1 + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') + + // Icon ermitteln + if (iconData[a].ScreensaverEntity) { + payloadString += iconData[a].ScreensaverEntityIconOn; + if (Debug) log('Icon if true '+payloadString, 'info') } else { - payloadString += getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val + if (iconData[a].ScreensaverEntityIconOff != null) { + payloadString += iconData[a].ScreensaverEntityIconOff; + if (Debug) log('Icon1 else true '+payloadString, 'info') + } else { + payloadString += iconData[a].ScreensaverEntityIconOn; + if (Debug) log('Icon1 else false '+payloadString, 'info') + } + } + + if (iconData[a].ScreensaverEntityValue != null) { + payloadString += iconData[a].ScreensaverEntityValue; + if (typeof iconData[a].ScreensaverEntityValue == 'number') { + //payloadString += iconData[a].ScreensaverEntityValue.toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); + payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; + if (Debug) log('Value ist eine Zahl ' + payloadString, 'info') + } else { + if (Debug) log('Value ist keine Zahl ' + payloadString, 'info') + } + } + + payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; + } else if (typeof (iconData[a].ScreensaverEntity) == 'boolean') { + let hwBtn1: boolean = iconData[a].ScreensaverEntity; + if (hwBtn1) { + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + } + if (iconData[a].ScreensaverEntity) { + payloadString += iconData[a].ScreensaverEntityIconOn; + } else { + if (iconData[a].ScreensaverEntityIconOff != null) { + payloadString += iconData[a].ScreensaverEntityIconOff; + } else { + payloadString += iconData[a].ScreensaverEntityIconOn; + } + } + if (iconData[a].ScreensaverEntityValue != null) { + payloadString += iconData[a].ScreensaverEntityValue; + if (typeof iconData[a].ScreensaverEntityValue == 'number') { + //payloadString += iconData[a].ScreensaverEntityValue.toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); + payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; + } + } + payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; + } + } else if (iconData[a].ScreensaverEntity == null && iconData[a].ScreensaverEntityValue != null){ + if(iconData[a].ScreensaverEntityOnColor != null){ + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + } + if(iconData[a].ScreensaverEntityIconOn != null){ + payloadString += iconData[a].ScreensaverEntityIconOn; + } + if (iconData[a].ScreensaverEntityValue != null) { + payloadString += iconData[a].ScreensaverEntityValue; + if (typeof iconData[a].ScreensaverEntityValue == 'number') { + //payloadString += (iconData[a].ScreensaverEntityValue).toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); + payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; } } payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; } - } else if (config.mrIcon1ScreensaverEntity.ScreensaverEntity == null && config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null){ - - if(config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor != null){ - hwBtn1Col = config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor; + else { + hwBtn1Col = Black; + payloadString += '~~'; } - if(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn != null){ - payloadString += Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn); - } - - if (config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit; - } else { - payloadString += getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val - } - } - payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; } - else { - hwBtn1Col = Black; - payloadString += '~~'; - } - - let hwBtn2Col: any = config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor; - if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null) { - if (typeof (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val) == 'string') { - let hwBtn2: string = getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val; + /*let hwBtn2Col: any = config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor; + if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity)) { + if (typeof (iconData.mrIcon2.ScreensaverEntity) == 'string') { + let hwBtn2: string = iconData.mrIcon2.ScreensaverEntity; if (hwBtn2 == 'ON') { hwBtn2Col = config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor; } - if (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val) { + if (iconData.mrIcon2.ScreensaverEntity) { payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); } else { if (config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null) { @@ -8943,21 +9005,22 @@ function HandleScreensaverStatusIcons() : void { payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); } } - if (config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; + const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; + if (value != null) { + if (value != '' && isNaN(value) == false) { + payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); + payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; } else { - payloadString += getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val - } - } + payloadString += value; + } + } payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; - } else if (typeof (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val) == 'boolean') { - let hwBtn2: boolean = getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val; + } else if (typeof (iconData.mrIcon2.ScreensaverEntity) == 'boolean') { + let hwBtn2: boolean = iconData.mrIcon2.ScreensaverEntity; if (hwBtn2) { hwBtn2Col = config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor; } - if (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val) { + if (iconData.mrIcon2.ScreensaverEntity) { payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); } else { if (config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null) { @@ -8966,14 +9029,15 @@ function HandleScreensaverStatusIcons() : void { payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); } } - if (config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); + const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; + if (value != null) { + if (value != '' && isNaN(value) == false) { + payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; } else { - payloadString += getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val - } - } + payloadString += value; + } + } payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; } } else if (config.mrIcon2ScreensaverEntity.ScreensaverEntity == null && config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null){ @@ -8986,20 +9050,21 @@ function HandleScreensaverStatusIcons() : void { payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); } - if (config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null) { - if (isNaN(getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val) == false) { - payloadString += (getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val).toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; - } else { - payloadString += getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val - } - } + const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; + if (value != null) { + if (value != '' && isNaN(value) == false) { + payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); + payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; + } else { + payloadString += value; + } + } payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; } else { hwBtn2Col = Black; payloadString += '~~'; } - + */ let alternateScreensaverMFRIcon1Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1').val let alternateScreensaverMFRIcon2Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2').val //Alternate MRIcon Size @@ -9811,6 +9876,13 @@ function isPageThermoItem(F: PageItem | NSPanel.PageThermoItem):F is NSPanel.Pag return 'popupThermoMode1' in F; } +function isPageMedia(F: NSPanel.PageType | NSPanel.PageMedia):F is NSPanel.PageMedia { + return F.type == 'cardMedia'; +} +function isPagePower(F: NSPanel.PageType | NSPanel.PagePower):F is NSPanel.PagePower { + return F.type == 'cardPower'; +} + namespace NSPanel { export type PopupType = 'popupFan' | 'popupInSel' | 'popupLight' | 'popupLightNew' | 'popupNotify' | 'popupShutter' | 'popupThermo' | 'popupTimer' @@ -9870,48 +9942,49 @@ namespace NSPanel { export type PageEntities = { type: 'cardEntities', - items: PageItem[], + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], } & PageBaseType export type PageGrid = { type: 'cardGrid', - items: PageItem[], + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], } & PageBaseType export type PageGrid2 = { type: 'cardGrid2', - items: PageItem[], + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], } & PageBaseType export type PageThermo = { type: 'cardThermo', - items: PageThermoItem[], + items: [PageThermoItem], } & Omit export type PageMedia = { type: 'cardMedia', - items: PageMediaItem[], + items: [PageMediaItem], } & Omit + export type PageAlarm = { type: 'cardAlarm', - items: PageItem[], + items: [PageItem], } & Omit export type PageUnlock = { type: 'cardUnlock', - items: PageItem[], + items: [PageItem], } & Omit & Partial> export type PageQR = { type: 'cardQR', - items: PageItem[], + items: [PageItem], } & Omit export type PagePower = { type: 'cardPower', - items: PageItem[], + items: [PageItem], } & Omit export type PageChart = { @@ -10060,6 +10133,16 @@ namespace NSPanel { ScreensaverEntityOnColor: RGB, ScreensaverEntityOffColor: RGB } + export type ScreenSaverMRDataElement = { + ScreensaverEntity: string | number | boolean | null, + ScreensaverEntityIconOn: string | null, + ScreensaverEntityIconOff: string | null, + ScreensaverEntityValue: string | number | boolean | null, + ScreensaverEntityValueDecimalPlace: number | null, + ScreensaverEntityValueUnit: string | null, + ScreensaverEntityOnColor: RGB, + ScreensaverEntityOffColor: RGB + } export type IconScaleElement = { val_min:number, From e7a6a05a1bcad7e25176ab32352b68eebbef55e3 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 15:59:28 +0100 Subject: [PATCH 04/17] Update Version and Changelog --- ioBroker/DEV/NSPanelTs.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 827bf247..46c2bd16 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------- -TypeScript v4.3.3.37 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @ticaki / @Britzelpuf / @Sternmiere / @ravenS0ne +TypeScript v4.3.3.38 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @ticaki / @Britzelpuf / @Sternmiere / @ravenS0ne - abgestimmt auf TFT 53 / v4.3.3 / BerryDriver 9 / Tasmota 13.3.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 @@ -98,7 +98,10 @@ ReleaseNotes: - 09.01.2024 - v4.3.3.36 Fix: schedule SendTime - 09.01.2024 - v4.3.3.36 Fix: Function _schedule SummerTime/WinterTime - 15.01.2024 - v4.3.3.37 Change: Allow data points to be flushed for popUpNotify. Activate screensaver with one click. - + - 16.01.2024 - v4.3.3.38 Fix: joBr99#1098 + - 16.01.2024 - v4.3.3.38 Types: Number of PageItems defined & HandleScreensaverStatusIcons rewritten + - 16.01.2024 - v4.3.3.38 Optimate: function SendTime() + Todo: - XX.XX.XXXX - v5.0.0 Change the bottomScreensaverEntity (rolling) if more than 6 entries are defined @@ -964,7 +967,7 @@ export const config: Config = { // _________________________________ DE: Ab hier keine Konfiguration mehr _____________________________________ // _________________________________ EN: No more configuration from here _____________________________________ -const scriptVersion: string = 'v4.3.3.37'; +const scriptVersion: string = 'v4.3.3.38'; const tft_version: string = 'v4.3.3'; const desired_display_firmware_version = 53; const berry_driver_version = 9; From f3b545fd9026652f5ff5acb78fbee6c96cd42046 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 16:04:22 +0100 Subject: [PATCH 05/17] remove commented out code --- ioBroker/DEV/NSPanelTs.ts | 77 +-------------------------------------- 1 file changed, 1 insertion(+), 76 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 46c2bd16..f0898c1f 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8992,82 +8992,7 @@ function HandleScreensaverStatusIcons() : void { payloadString += '~~'; } } - /*let hwBtn2Col: any = config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor; - if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity)) { - if (typeof (iconData.mrIcon2.ScreensaverEntity) == 'string') { - let hwBtn2: string = iconData.mrIcon2.ScreensaverEntity; - if (hwBtn2 == 'ON') { - hwBtn2Col = config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor; - } - if (iconData.mrIcon2.ScreensaverEntity) { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); - } else { - if (config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null) { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff); - } else { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); - } - } - const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; - if (value != null) { - if (value != '' && isNaN(value) == false) { - payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; - } else { - payloadString += value; - } - } - payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; - } else if (typeof (iconData.mrIcon2.ScreensaverEntity) == 'boolean') { - let hwBtn2: boolean = iconData.mrIcon2.ScreensaverEntity; - if (hwBtn2) { - hwBtn2Col = config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor; - } - if (iconData.mrIcon2.ScreensaverEntity) { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); - } else { - if (config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null) { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff); - } else { - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); - } - } - const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; - if (value != null) { - if (value != '' && isNaN(value) == false) { - payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; - } else { - payloadString += value; - } - } - payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; - } - } else if (config.mrIcon2ScreensaverEntity.ScreensaverEntity == null && config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null){ - - if(config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor != null){ - hwBtn2Col = config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor; - } - - if(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn != null){ - payloadString += Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn); - } - - const value = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue == null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val; - if (value != null) { - if (value != '' && isNaN(value) == false) { - payloadString += value.toFixed(config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace); - payloadString += (config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit == null) ? '' : config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit; - } else { - payloadString += value; - } - } - payloadString += '~' + rgb_dec565(hwBtn2Col) + '~'; - } else { - hwBtn2Col = Black; - payloadString += '~~'; - } - */ + let alternateScreensaverMFRIcon1Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1').val let alternateScreensaverMFRIcon2Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2').val //Alternate MRIcon Size From 5a3478d91630223337aebb83173faea4f706dda1 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 16:06:47 +0100 Subject: [PATCH 06/17] ups :D --- ioBroker/DEV/NSPanelTs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index f0898c1f..08859d14 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8894,7 +8894,7 @@ function HandleScreensaverStatusIcons() : void { } } for (const a in iconData) { - if (iconData[a].ScreensaverEntityValue === null) { + if (iconData[a].ScreensaverEntityValue !== null) { switch (typeof iconData[a].ScreensaverEntityValue) { case "string": if (iconData[a].ScreensaverEntityValue === '' || isNaN(iconData[a].ScreensaverEntityValue)) break; From 01392bcbf807aa17c25f86d6a86fe5c12d3b6e65 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 16:32:38 +0100 Subject: [PATCH 07/17] fix unsubscribePowerSubscriptions --- ioBroker/DEV/NSPanelTs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 08859d14..b686805b 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -6011,7 +6011,7 @@ function unsubscribePowerSubscriptions(): void { } } for (let i = 0; i < config.subPages.length; i++) { - const page: NSPanel.PageType = config.pages[i]; + const page: NSPanel.PageType = config.subPages[i]; if (isPagePower(page)) { let powerID = page.items[0].id; unsubscribe(powerID + '.ACTUAL'); From 117798a3f526cb99f2cfc2e1e5d6d9975e82f1bd Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 17:34:09 +0100 Subject: [PATCH 08/17] icon fix --- ioBroker/DEV/NSPanelTs.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index b686805b..93966019 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8859,10 +8859,10 @@ function HandleScreensaverStatusIcons() : void { : null, ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn != null ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn) - : null, + : '', ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff != null ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff) - : null, + : '', ScreensaverEntityOnColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor, ScreensaverEntityOffColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOffColor, ScreensaverEntityValue: config.mrIcon1ScreensaverEntity.ScreensaverEntityValue === null @@ -8880,10 +8880,10 @@ function HandleScreensaverStatusIcons() : void { : null, ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn != null ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn) - : null, + : '', ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff) - : null, + : '', ScreensaverEntityOnColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor, ScreensaverEntityOffColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor, ScreensaverEntityValue: config.mrIcon2ScreensaverEntity.ScreensaverEntityValue === null From 2bd3d0d290ace0da8043a459893d24b9cf38a551 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 20:51:24 +0100 Subject: [PATCH 09/17] reduce HandleScreensaverStatusIcons --- ioBroker/DEV/NSPanelTs.ts | 102 +++++++++++++------------------------- 1 file changed, 35 insertions(+), 67 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 93966019..14f1da7d 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8912,82 +8912,50 @@ function HandleScreensaverStatusIcons() : void { } } let hwBtn1Col: RGB = iconData[a].ScreensaverEntityOffColor; - if (iconData[a].ScreensaverEntity != null) { + if (iconData[a].ScreensaverEntity != null || iconData[a].ScreensaverEntityValue != null) { // Prüfung ob ScreensaverEntity vom Typ String ist - if (typeof (iconData[a].ScreensaverEntity) == 'string') { - if (Debug) log('Entity ist String', 'info') - let hwBtn1: string = iconData[a].ScreensaverEntity; - if (hwBtn1 == 'ON') { - hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + if (iconData[a].ScreensaverEntity != null) { + if (typeof (iconData[a].ScreensaverEntity) == 'string') { + if (Debug) log('Entity ist String', 'info') + if (iconData[a].ScreensaverEntity == 'ON') { + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + } + if (Debug) log('Value: ' + iconData[a].ScreensaverEntity + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') + // Alles was kein String ist in Boolean umwandeln + } else { + if (Debug) log('Entity ist kein String', 'info') + if (!!iconData[a].ScreensaverEntity) { + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + } } - if (Debug) log('Value: ' + hwBtn1 + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') + } - // Icon ermitteln - if (iconData[a].ScreensaverEntity) { - payloadString += iconData[a].ScreensaverEntityIconOn; - if (Debug) log('Icon if true '+payloadString, 'info') - } else { - if (iconData[a].ScreensaverEntityIconOff != null) { - payloadString += iconData[a].ScreensaverEntityIconOff; - if (Debug) log('Icon1 else true '+payloadString, 'info') - } else { - payloadString += iconData[a].ScreensaverEntityIconOn; - if (Debug) log('Icon1 else false '+payloadString, 'info') - } - } - - if (iconData[a].ScreensaverEntityValue != null) { - payloadString += iconData[a].ScreensaverEntityValue; - if (typeof iconData[a].ScreensaverEntityValue == 'number') { - //payloadString += iconData[a].ScreensaverEntityValue.toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); - payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; - if (Debug) log('Value ist eine Zahl ' + payloadString, 'info') - } else { - if (Debug) log('Value ist keine Zahl ' + payloadString, 'info') - } - } - - payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; - } else if (typeof (iconData[a].ScreensaverEntity) == 'boolean') { - let hwBtn1: boolean = iconData[a].ScreensaverEntity; - if (hwBtn1) { - hwBtn1Col = iconData[a].ScreensaverEntityOnColor; - } - if (iconData[a].ScreensaverEntity) { - payloadString += iconData[a].ScreensaverEntityIconOn; - } else { - if (iconData[a].ScreensaverEntityIconOff != null) { - payloadString += iconData[a].ScreensaverEntityIconOff; - } else { - payloadString += iconData[a].ScreensaverEntityIconOn; - } - } - if (iconData[a].ScreensaverEntityValue != null) { - payloadString += iconData[a].ScreensaverEntityValue; - if (typeof iconData[a].ScreensaverEntityValue == 'number') { - //payloadString += iconData[a].ScreensaverEntityValue.toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); - payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; - } - } - payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; - } - } else if (iconData[a].ScreensaverEntity == null && iconData[a].ScreensaverEntityValue != null){ - if(iconData[a].ScreensaverEntityOnColor != null){ - hwBtn1Col = iconData[a].ScreensaverEntityOnColor; - } - if(iconData[a].ScreensaverEntityIconOn != null){ + // Icon ermitteln + if (iconData[a].ScreensaverEntity) { payloadString += iconData[a].ScreensaverEntityIconOn; - } + if (Debug) log('Icon if true '+payloadString, 'info') + } else { + if (iconData[a].ScreensaverEntityIconOff != null) { + payloadString += iconData[a].ScreensaverEntityIconOff; + if (Debug) log('Icon1 else true '+payloadString, 'info') + } else { + payloadString += iconData[a].ScreensaverEntityIconOn; + if (Debug) log('Icon1 else false '+payloadString, 'info') + } + } + if (iconData[a].ScreensaverEntityValue != null) { payloadString += iconData[a].ScreensaverEntityValue; if (typeof iconData[a].ScreensaverEntityValue == 'number') { - //payloadString += (iconData[a].ScreensaverEntityValue).toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; - } - } + if (Debug) log('Value ist eine Zahl ' + payloadString, 'info') + } else { + if (Debug) log('Value ist keine Zahl ' + payloadString, 'info') + } + } + payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; - } - else { + } else { hwBtn1Col = Black; payloadString += '~~'; } From 8449257628e365e08d274e9c70179deb8cdc3ab2 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 16 Jan 2024 21:39:43 +0100 Subject: [PATCH 10/17] fix number/string --- ioBroker/DEV/NSPanelTs.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 14f1da7d..b55c9576 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8946,13 +8946,8 @@ function HandleScreensaverStatusIcons() : void { if (iconData[a].ScreensaverEntityValue != null) { payloadString += iconData[a].ScreensaverEntityValue; - if (typeof iconData[a].ScreensaverEntityValue == 'number') { - payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; - if (Debug) log('Value ist eine Zahl ' + payloadString, 'info') - } else { - if (Debug) log('Value ist keine Zahl ' + payloadString, 'info') - } - } + payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; + } payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; } else { @@ -9785,6 +9780,11 @@ namespace NSPanel { export type EventMethod = 'startup' | 'sleepReached' | 'pageOpenDetail' | 'buttonPress2' | 'renderCurrentPage' | 'button1' | 'button2' + export type panelRecvType = { + event: 'event'; + method: EventMethod + } + export type SerialType = 'button' | 'light' | 'shutter' | 'text' | 'input_sel' | 'timer' | 'number' | 'fan' From f76f2ca3936a055b68091235f40f81cf688174da Mon Sep 17 00:00:00 2001 From: ticaki Date: Wed, 17 Jan 2024 17:25:51 +0100 Subject: [PATCH 11/17] tweak HandleScreensaverStatusIcons --- ioBroker/DEV/NSPanelTs.ts | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index b55c9576..905381cc 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -8857,10 +8857,10 @@ function HandleScreensaverStatusIcons() : void { && existsState(config.mrIcon1ScreensaverEntity.ScreensaverEntity) ? getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val : null, - ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn != null + ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn) : '', - ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff != null + ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff) : '', ScreensaverEntityOnColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor, @@ -8870,6 +8870,10 @@ function HandleScreensaverStatusIcons() : void { : getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val, ScreensaverEntityValueDecimalPlace: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace, ScreensaverEntityValueUnit: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit, + ScreensaverEntityIconSelect: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect + && typeof config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect === 'object' + ? config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect + : null, }, @@ -8878,10 +8882,10 @@ function HandleScreensaverStatusIcons() : void { && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity) ? getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val : null, - ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn != null + ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn) : '', - ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff != null + ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff) : '', ScreensaverEntityOnColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor, @@ -8891,6 +8895,10 @@ function HandleScreensaverStatusIcons() : void { : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val, ScreensaverEntityValueDecimalPlace: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace, ScreensaverEntityValueUnit: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit, + ScreensaverEntityIconSelect: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect + && typeof config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect === 'object' + ? config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect + : null, } } for (const a in iconData) { @@ -8917,8 +8925,16 @@ function HandleScreensaverStatusIcons() : void { if (iconData[a].ScreensaverEntity != null) { if (typeof (iconData[a].ScreensaverEntity) == 'string') { if (Debug) log('Entity ist String', 'info') - if (iconData[a].ScreensaverEntity == 'ON') { - hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + switch (String(iconData[a].ScreensaverEntity).toUpperCase()) { + case 'ON': + case 'OK': + case 'AN': + case 'YES': + case 'TRUE': + case 'ONLINE': + hwBtn1Col = iconData[a].ScreensaverEntityOnColor; + break; + default: } if (Debug) log('Value: ' + iconData[a].ScreensaverEntity + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') // Alles was kein String ist in Boolean umwandeln @@ -8931,11 +8947,17 @@ function HandleScreensaverStatusIcons() : void { } // Icon ermitteln - if (iconData[a].ScreensaverEntity) { + if (iconData[a].ScreensaverEntityIconSelect && iconData[a].ScreensaverEntity != null) { + const icon = iconData[a].ScreensaverEntityIconSelect[iconData[a].ScreensaverEntity]; + if (icon !== undefined) { + payloadString += Icons.GetIcon(icon); + if (Debug) log('SelectIcon: '+payloadString, 'info') + } + } else if (iconData[a].ScreensaverEntity) { payloadString += iconData[a].ScreensaverEntityIconOn; if (Debug) log('Icon if true '+payloadString, 'info') } else { - if (iconData[a].ScreensaverEntityIconOff != null) { + if (iconData[a].ScreensaverEntityIconOff) { payloadString += iconData[a].ScreensaverEntityIconOff; if (Debug) log('Icon1 else true '+payloadString, 'info') } else { @@ -10022,6 +10044,7 @@ namespace NSPanel { export type ScreenSaverMRElement = { ScreensaverEntity: string | null, ScreensaverEntityIconOn: string | null, + ScreensaverEntityIconSelect?: {[key: string]: string} | null | undefined, ScreensaverEntityIconOff: string | null, ScreensaverEntityValue: string | null, ScreensaverEntityValueDecimalPlace: number | null, @@ -10038,6 +10061,7 @@ namespace NSPanel { ScreensaverEntityValueUnit: string | null, ScreensaverEntityOnColor: RGB, ScreensaverEntityOffColor: RGB + ScreensaverEntityIconSelect: {[key: string]: string} | null, } export type IconScaleElement = { From db32de68e3cae55c74df1f2b11c50e3ac369d67f Mon Sep 17 00:00:00 2001 From: ticaki Date: Wed, 17 Jan 2024 23:14:54 +0100 Subject: [PATCH 12/17] add ScreensaverEntityValue to on() --- ioBroker/DEV/NSPanelTs.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 905381cc..903cd29d 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -101,6 +101,8 @@ ReleaseNotes: - 16.01.2024 - v4.3.3.38 Fix: joBr99#1098 - 16.01.2024 - v4.3.3.38 Types: Number of PageItems defined & HandleScreensaverStatusIcons rewritten - 16.01.2024 - v4.3.3.38 Optimate: function SendTime() + - 17.01.2024 - v4.3.3.38 Add: ScreensaverEntityIconSelect for MRIcons is like common.states for states. + - 17.01.2024 - v4.3.3.38 Add: Changing the ScreensaverEntityValue value updates the screensaver. Todo: - XX.XX.XXXX - v5.0.0 Change the bottomScreensaverEntity (rolling) if more than 6 entries are defined @@ -1431,7 +1433,7 @@ Init_Screensaver_Backckground_Color_Switch(); on({id: NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', change: "ne"}, async function (obj) { try { bgColorScrSaver = obj.state.val; - if (bgColorScrSaver < 4) { + if (bgColorScrSaver < 6) { HandleScreensaverUpdate(); } } catch (err: any) { @@ -1787,9 +1789,11 @@ on({id: [String(NSPanel_Path) + 'Relay.1',String(NSPanel_Path) + 'Relay.2'], cha async function SubscribeMRIcons () { try { - if (config.mrIcon1ScreensaverEntity.ScreensaverEntity != null) { - on({id: config.mrIcon1ScreensaverEntity.ScreensaverEntity, change: "ne"}, async function (obj) { - if (obj.id!.substring(0,4) == 'mqtt') { + let arr = config.mrIcon1ScreensaverEntity.ScreensaverEntity != null ? [config.mrIcon1ScreensaverEntity.ScreensaverEntity] : []; + arr = config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null ? [...arr, config.mrIcon1ScreensaverEntity.ScreensaverEntityValue] : arr; + if (arr.length > 0) { + on({id: arr, change: "ne"}, async function (obj) { + if (obj.id!.substring(0,4) == 'mqtt') { let Button = obj.id!.split('.'); if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6)).val != obj.state.val) { await setStateAsync(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6), obj.state.val == 'ON' ? true : false); @@ -1799,8 +1803,10 @@ async function SubscribeMRIcons () { } }); } - if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null) { - on({id: config.mrIcon2ScreensaverEntity.ScreensaverEntity, change: "ne"}, async function (obj) { + arr = config.mrIcon2ScreensaverEntity.ScreensaverEntity != null ? [config.mrIcon2ScreensaverEntity.ScreensaverEntity] : []; + arr = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null ? [...arr, config.mrIcon2ScreensaverEntity.ScreensaverEntityValue] : arr; + if (arr.length > 0) { + on({id: arr, change: "ne"}, async function (obj) { if (obj.id!.substring(0,4) == 'mqtt') { let Button = obj.id!.split('.'); if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6)).val != obj.state.val) { From c3ded4d817f705dcfe04eca5b84619051f793c3f Mon Sep 17 00:00:00 2001 From: ticaki Date: Thu, 18 Jan 2024 22:15:04 +0100 Subject: [PATCH 13/17] buildNSPanelString --- ioBroker/DEV/NSPanelTs.ts | 46 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 903cd29d..846d5955 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -1050,7 +1050,7 @@ async function CheckConfigParameters() { const i = n.shift(); if (a === 'mqtt' && !isNaN(Number(i))) { - sendTo(`${a}.${i}`, 'sendMessage2Client', {topic: n.join('/'), message: 'time~12:00'}); + sendTo(`${a}.${i}`, 'sendMessage2Client', {topic: n.join('/'), message: buildNSPanelString('time', '12:00')}); await sleep(500); } if (await existsObjectAsync(config.panelSendTopic) == false) { @@ -9075,23 +9075,25 @@ function HandleScreensaverColors(): void { scrSvrBGCol = rgb_dec565({ red: 100, green: 0, blue: 0 }); } - let payloadString = 'color' + '~' + - scrSvrBGCol + '~' + //background - rgb_dec565(sctime) + '~' + //time - rgb_dec565(sctimeAMPM) + '~' + //timeAMPM~ - rgb_dec565(scdate) + '~' + //date~ - rgb_dec565(sctMainText) + '~' + //tMainText~ - rgb_dec565(sctForecast1) + '~' + //tForecast1~ - rgb_dec565(sctForecast2) + '~' + //tForecast2~ - rgb_dec565(sctForecast3) + '~' + //tForecast3~ - rgb_dec565(sctForecast4) + '~' + //tForecast4~ - rgb_dec565(sctForecast1Val) + '~' + //tForecast1Val~ - rgb_dec565(sctForecast2Val) + '~' + //tForecast2Val~ - rgb_dec565(sctForecast3Val) + '~' + //tForecast3Val~ - rgb_dec565(sctForecast4Val) + '~' + //tForecast4Val~ - rgb_dec565(scbar) + '~' + //bar~ - rgb_dec565(sctMainTextAlt) + '~' + //tMainTextAlt - rgb_dec565(sctTimeAdd); //tTimeAdd + let payloadString = buildNSPanelString( + 'color' , + scrSvrBGCol , //background + rgb_dec565(sctime) , //time + rgb_dec565(sctimeAMPM) , //timeAMPM~ + rgb_dec565(scdate) , //date~ + rgb_dec565(sctMainText) , //tMainText~ + rgb_dec565(sctForecast1) , //tForecast1~ + rgb_dec565(sctForecast2) , //tForecast2~ + rgb_dec565(sctForecast3) , //tForecast3~ + rgb_dec565(sctForecast4) , //tForecast4~ + rgb_dec565(sctForecast1Val) , //tForecast1Val~ + rgb_dec565(sctForecast2Val) , //tForecast2Val~ + rgb_dec565(sctForecast3Val) , //tForecast3Val~ + rgb_dec565(sctForecast4Val) , //tForecast4Val~ + rgb_dec565(scbar) , //bar~ + rgb_dec565(sctMainTextAlt) , //tMainTextAlt + rgb_dec565(sctTimeAdd) //tTimeAdd + ); SendToPanel({ payload: payloadString }); } catch (err: any) { @@ -9664,6 +9666,14 @@ function spotifyGetDeviceID(vDeviceString: string): string { let strDevID = arrayDeviceListIds[indexPos]; return strDevID; } +/** + * Join arguments with ~ and return the string; + * @param tokens unlimited numbers of strings + * @returns + */ +function buildNSPanelString(...tokens: (string|number)[]): string { + return tokens.join('~'); +} type RGB = NSPanel.RGB; type PageItem = NSPanel.PageItem; From 8c84c1050f987700d72a314103041746a4aa728d Mon Sep 17 00:00:00 2001 From: ticaki Date: Fri, 19 Jan 2024 00:03:15 +0100 Subject: [PATCH 14/17] fix pm/am --- ioBroker/DEV/NSPanelTs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 846d5955..4594f3fe 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -3285,7 +3285,7 @@ function SendTime(): void { const min = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(); SendToPanel({ payload: 'time~' + hr + ':' + min });*/ - SendToPanel({ payload: `time~${new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`, }); + SendToPanel({ payload: `time~${new Date().toLocaleTimeString('de-DE', { hour: "2-digit", minute: "2-digit" })}`, }); } catch (err: any) { log('error at function SendTime: ' + err.message, 'warn'); } From b2f338cad8a9edc8651d255a3a3b7a0c9a6702f5 Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:33:35 +0100 Subject: [PATCH 15/17] Change cardLChart - no yAxisTicks required --- ioBroker/DEV/NSPanelTs.ts | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 4594f3fe..5ecd0251 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -6157,26 +6157,52 @@ function GeneratePowerPage(page: NSPanel.PagePower): NSPanel.Payload[] { } } +const timeValueRegEx = /\~\d+:(\d+)/g; function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] { try { activePage = page; let id = page.items[0].id; - let out_msgs: NSPanel.Payload[] = []; + let out_msgs: Array = []; out_msgs.push({ payload: 'pageType~' + page.type }); let heading = page.heading !== undefined ? page.heading : "Chart..."; - let txt = getState(id + '.ACTUAL').val; - if (!page.items[0].yAxisTicks) { - throw new Error (`Page item ${id} yAxisTicks is undefined!`) + const txt = getState(id + '.ACTUAL')?.val; + if (!txt) { + throw new Error(`Unable to get the state of ${id}.ACTUAL`) } + + let yAxisTicks : number[] = []; + + if (!page.items[0].yAxisTicks) { + const sorted = [...txt.matchAll(timeValueRegEx)].map(x => Number(x[1])).sort((x, y) => x < y ? -1 : 1); + if (sorted.length === 0) { + throw new Error (`Page item ${id} yAxisTicks is undefined and unable to be calculated!`) + } + const minValue = sorted[0]; + const maxValue = sorted[sorted.length - 1]; + const tick = Math.max(Number(((maxValue - minValue) / 5).toFixed()), 10); + + let currentTick = minValue - tick; + while(currentTick < (maxValue + tick)) { + yAxisTicks.push(currentTick); + currentTick += tick; + } + + if (Debug) { + log(`Calculated yAxisTicks for ${id} (Min: ${minValue}, Max: ${maxValue}, Tick: ${tick}): ${yAxisTicks}`); + } + } else { + yAxisTicks = typeof page.items[0].yAxisTicks === 'string' + ? JSON.parse(getState(page.items[0].yAxisTicks).val) + : page.items[0].yAxisTicks; + } + if (!page.items[0].onColor) { throw new Error (`Page item ${id} onColor is undefined!`) } - let yAxisTicks = (typeof page.items[0].yAxisTicks == 'object') ? page.items[0].yAxisTicks : JSON.parse(getState(page.items[0].yAxisTicks).val); - out_msgs.push({ payload: 'entityUpd~' + //entityUpd heading + '~' + //heading @@ -6189,7 +6215,6 @@ function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] { if (Debug) log('GenerateChartPage payload: ' + JSON.stringify(out_msgs), 'info'); return out_msgs; - } catch (err: any) { log('error at function GenerateChartPage: ' + err.message, 'warn'); return []; From 1d3914ce86655ee79e2ead28564e5e8afb9ee05d Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:37:30 +0100 Subject: [PATCH 16/17] let out_msgs: NSPanel.Payload[] = []; --- ioBroker/DEV/NSPanelTs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 5ecd0251..5c281749 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -6163,7 +6163,7 @@ function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] { activePage = page; let id = page.items[0].id; - let out_msgs: Array = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~' + page.type }); let heading = page.heading !== undefined ? page.heading : "Chart..."; From 576176e1cc92979756e49e8c93265c8100cc51ef Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:44:46 +0100 Subject: [PATCH 17/17] Change in cardLChart Change: yAxisTicks parameter is not required in cardLChart PageItem --- ioBroker/DEV/NSPanelTs.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 5c281749..9b62d627 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -103,6 +103,7 @@ ReleaseNotes: - 16.01.2024 - v4.3.3.38 Optimate: function SendTime() - 17.01.2024 - v4.3.3.38 Add: ScreensaverEntityIconSelect for MRIcons is like common.states for states. - 17.01.2024 - v4.3.3.38 Add: Changing the ScreensaverEntityValue value updates the screensaver. + - 19.01.2024 - v4.3.3.38 Change: yAxisTicks parameter is not required in cardLChart PageItem Todo: - XX.XX.XXXX - v5.0.0 Change the bottomScreensaverEntity (rolling) if more than 6 entries are defined