diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 0c1e53ef..8c664745 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -541,6 +541,7 @@ let NSPanel_Service_SubPage: PageType = /*PageItem*/{ id: AliasPath + 'IoBroker.ScriptVersion', name: findLocaleServMenu('script_version_nspanelts'), offColor: Menu, onColor: Menu }, /*PageItem*/{ id: AliasPath + 'IoBroker.NodeJSVersion', name: findLocaleServMenu('nodejs_version'), offColor: Menu, onColor: Menu }, /*PageItem*/{ id: AliasPath + 'IoBroker.JavaScriptVersion', name: findLocaleServMenu('instance_javascript'), offColor: Menu, onColor: Menu }, + /*PageItem*/{ id: AliasPath + 'IoBroker.ScriptName', name: findLocaleServMenu('scriptname'), offColor: Menu, onColor: Menu }, ] }; @@ -1038,7 +1039,18 @@ async function CheckConfigParameters() { log('Config-Parameter: << config.panelRecvTopic - ' + config.panelRecvTopic + ' >> is not reachable. Please Check Parameters!','error'); } if (existsObject(config.panelSendTopic) == false) { - log('Config-Parameter: << config.panelSendTopic - ' + config.panelSendTopic + ' >> is not reachable. Please Check Parameters!','error'); + const n = config.panelSendTopic.split('.'); + const a = n.shift(); + const i = n.shift(); + + if (a === 'mqtt' && !isNaN(Number(i))) { + sendTo(`${a}.${i}`, 'sendMessage2Client', {topic: n.join('/'), message: 'time~12:00'}); + await sleep(500); + } + if (await existsObjectAsync(config.panelSendTopic) == false) { + log('Config-Parameter: << config.panelSendTopic - ' + config.panelSendTopic + ' >> is not reachable. Please Check Parameters!','error'); + stopScript(scriptName); + } } if (weatherAdapterInstance.substring(0, weatherAdapterInstance.length - 3) == 'daswetter') { if (existsObject(weatherAdapterInstance + 'NextHours.Location_1.Day_1.current.symbol_value') == false) { @@ -1063,6 +1075,7 @@ async function CheckConfigParameters() { if (common.name == 'javascript') { javaScriptVersion = common.version; setIfExists(NSPanel_Path + 'IoBroker.JavaScriptVersion', 'v' + javaScriptVersion); + setIfExists(NSPanel_Path + 'IoBroker.ScriptName', (name as unknown as string).split('.').slice(2).join('.')); let jsVersion = common.version.split('.'); let jsV = 10*parseInt(jsVersion[0]) + parseInt(jsVersion[1]); if (jsV<61) log('JS-Adapter: ' + common.name + ' must be at least v6.1.3. Currently: v' + common.version, 'error'); @@ -1115,6 +1128,10 @@ async function InitIoBrokerInfo() { await createStateAsync(NSPanel_Path + 'IoBroker.JavaScriptVersion', 'v' + javaScriptVersion, { type: 'string' }); setObject(AliasPath + 'IoBroker.JavaScriptVersion', {type: 'channel', common: {role: 'info', name:'Version JavaScript Instanz'}, native: {}}); await createAliasAsync(AliasPath + 'IoBroker.JavaScriptVersion.ACTUAL', NSPanel_Path + 'IoBroker.JavaScriptVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + // ScriptName + await createStateAsync(NSPanel_Path + 'IoBroker.ScriptName', 'v' + javaScriptVersion, { type: 'string' }); + setObject(AliasPath + 'IoBroker.ScriptName', {type: 'channel', common: {role: 'info', name:'Scriptname'}, native: {}}); + await createAliasAsync(AliasPath + 'IoBroker.ScriptName.ACTUAL', NSPanel_Path + 'IoBroker.ScriptName', true, { type: 'string', role: 'state', name: 'ACTUAL' }); } setIfExists(NSPanel_Path + 'IoBroker.ScriptVersion', scriptVersion); } catch (err: any) { @@ -2203,7 +2220,7 @@ let scheduleSendDate = schedule('0 * * * *', () => { // 3:30 a.m. Perform startup and receive current TFT version let scheduleStartup = schedule({ hour: 3, minute: 30 }, async () => { - await setStateAsync(config.panelSendTopic, 'pageType~pageStartup'); + setIfExists(config.panelSendTopic, 'pageType~pageStartup'); }); // Updates currently compare every 12 hours @@ -2216,7 +2233,7 @@ let scheduleCheckUpdates = schedule('{"time":{"start":"00:00","end":"23:59","mod // Check for updates with Start get_locales(); get_locales_servicemenu(); -setState(config.panelSendTopic, 'pageType~pageStartup'); +setIfExists(config.panelSendTopic, 'pageType~pageStartup'); get_tasmota_status0(); get_panel_update_data(); check_updates(); @@ -2325,7 +2342,7 @@ async function check_updates() { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - if (Debug) log('Auto-Updates eingeschaltet - Update Tasmota wird durchgeführt', 'info'); + log('Auto-Updates eingeschaltet - Update Tasmota wird durchgeführt', 'info'); // Perform Tasmota upgrade update_tasmota_firmware(); @@ -2353,7 +2370,7 @@ async function check_updates() { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - if (Debug) log('Auto-updates switched on - Berry driver update is carried out', 'info'); + log('Auto-updates switched on - Berry driver update is carried out', 'info'); // Tasmota Berry-Driver Update durchführen update_berry_driver_version(); @@ -2383,7 +2400,7 @@ async function check_updates() { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - if (Debug) log('Auto-updates switched on - update TFT firmware is carried out', 'info'); + log('Auto-updates switched on - update TFT firmware is carried out', 'info'); // TFT-Firmware Update durchführen update_tft_firmware(); @@ -2950,13 +2967,13 @@ async function SendToPanel(val: Payload | Payload[]) { try { if (Array.isArray(val)) { val.forEach(function (id) { - setStateAsync(config.panelSendTopic, id.payload); + setIfExists(config.panelSendTopic, id.payload); if (Debug) { log('function SendToPanel payload: ' + id.payload, 'info'); } }); } else { - setState(config.panelSendTopic, val.payload); + setIfExists(config.panelSendTopic, val.payload); } } catch (err: any) { @@ -3020,7 +3037,7 @@ function HandleMessage(typ: string, method: EventMethod, page: number | undefine tempId = tempPageItem[0]; } let pageItem: PageItem = findPageItem(tempId); - if (pageItem !== undefined) { + if (pageItem !== undefined && isPopupType(words[2])) { let temp: string | mediaOptional | undefined = tempPageItem[1] if (isMediaOptional(temp)) SendToPanel(GenerateDetailPage(words[2], temp, pageItem, placeId)); else SendToPanel(GenerateDetailPage(words[2], undefined, pageItem, placeId)); @@ -4190,7 +4207,7 @@ function RegisterEntityWatcher(id: string): void { } } -function RegisterDetailEntityWatcher(id: string, pageItem: PageItem, type: string, placeId: number | undefined): void { +function RegisterDetailEntityWatcher(id: string, pageItem: PageItem, type: PopupType, placeId: number | undefined): void { try { if (subscriptions.hasOwnProperty(id)) { return; @@ -4712,7 +4729,7 @@ function subscribeMediaSubscriptionsBoseAdd(id: string): void { async function createAutoMediaAlias (id: string, mediaDevice: string, adapterPlayerInstance: adapterPlayerInstanceType) { if (autoCreateAlias) { - if (isSetOptionActive) { + if (isSetOptionActive) { switch (adapterPlayerInstance) { case "alexa2.0.": case "alexa2.1.": @@ -7299,7 +7316,7 @@ function GetNavigationString(pageId: number): string { } return ''; } -function GenerateDetailPage(type: string, optional: mediaOptional | undefined, pageItem: PageItem, placeId: number | undefined): Payload[] { +function GenerateDetailPage(type: PopupType, optional: mediaOptional | undefined, pageItem: PageItem, placeId: number | undefined): Payload[] { if (Debug) log('GenerateDetailPage Übergabe Type: ' + type + ' - optional: ' + optional + ' - pageItem.id: ' + pageItem.id, 'info'); try { let out_msgs: Array = []; @@ -7967,7 +7984,7 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p let actualMode = pageItem.modeList![getState(id + '.MODE').val]; let tempId = placeId != undefined ? placeId : id; - + // {tempid | icon | iconColor | switchVal | actualSpeed | maxSpeed: | findLocale | actualMode | modeList} out_msgs.push({ payload: 'entityUpdateDetail' + '~' // entityUpdateDetail + tempId + '~' @@ -7987,13 +8004,14 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p if (role == 'media') { let actualState: any = ''; let optionalString: string = 'Kein Eintrag'; - let mode: string = ''; + let mode: mediaOptional | '' = ''; if (isPageMediaItem(pageItem)) { const vTempAdapter = (pageItem.adapterPlayerInstance!).split('.'); const vAdapter: PlayerType = vTempAdapter[0] as PlayerType; if (optional == 'seek') { - let actualStateTemp: number = getState(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.seek').val; - if (actualStateTemp >= 95) { + const actualStateTemp: number = getState(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.seek').val; + actualState = Math.round(actualStateTemp / 10) * 10 + '%'; + /*if (actualStateTemp >= 95) { actualState = '100%'; } else if (actualStateTemp >= 85) { actualState = '90%'; @@ -8015,7 +8033,7 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p actualState = '10%'; } else if (actualStateTemp >= 0) { actualState = '0%'; - } + }*/ if (vAdapter == 'sonos') { optionalString = '0%?10%?20%?30%?40%?50%?60%?70%?80%?90%?100%'; } @@ -8214,7 +8232,7 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p } let tempId = placeId != undefined ? placeId : id; - + // {tempid | color | mediaOptional | actualState | optionalString} out_msgs.push({ payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail + tempId + '?' + optional + '~~' //{entity_id} @@ -8243,7 +8261,7 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p let valueList = pageItem.modeList != undefined ? tempModeList.join('?') : ''; let tempId = placeId != undefined ? placeId : id; - + // {tempid | color | mediaOptional | actualValue | valueList} out_msgs.push({ payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail2 + tempId + '~~' //{entity_id} @@ -8279,7 +8297,7 @@ function GenerateDetailPage(type: string, optional: mediaOptional | undefined, p //log(valueList); let tempId = placeId != undefined ? placeId : id; - + // {tempid | color | 'insel' | actualValue | valueList} out_msgs.push({ payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail2 + tempId + '~~' //{entity_id} @@ -8672,10 +8690,8 @@ function HandleScreensaverUpdate(): void { if (screensaverAdvanced) { // 5 indicatorScreensaverEntities for (let i = 0; i < 5 && i < config.indicatorScreensaverEntity.length; i++) { - let checkpoint = true; const indicatorScreensaverEntity:ScreenSaverElementWithUndefined = config.indicatorScreensaverEntity[i]; if (indicatorScreensaverEntity === null || indicatorScreensaverEntity === undefined) { - checkpoint = false; break; } RegisterScreensaverEntityWatcher(indicatorScreensaverEntity.ScreensaverEntity) @@ -9562,8 +9578,9 @@ function rgb_to_cie(red: number, green: number, blue: number): string return cie; } + /** - * + * * @param vDeviceString * @returns */ @@ -9576,6 +9593,9 @@ function spotifyGetDeviceID(vDeviceString: string): string { let strDevID = arrayDeviceListIds[indexPos]; return strDevID; } +type PopupType = 'popupFan' | 'popupInSel' | 'popupLight' | 'popupLightNew' | 'popupNotify' | 'popupShutter' | 'popupThermo' | 'popupTimer' + + type EventMethod = 'startup' | 'sleepReached' | 'pageOpenDetail' | 'buttonPress2' | 'renderCurrentPage' | 'button1' | 'button2' @@ -9624,7 +9644,7 @@ type PageBaseType = { homeIconColor?: RGB }; -type PagetypeType = 'cardChart' | 'cardLChart' | 'cardEntities' |'cardGrid'|'cardGrid2'|'cardThermo'|'cardMedia'|'cardUnlock'|'cardQR'|'cardAlarm'|'cardPower' +type PagetypeType = 'cardChart' | 'cardLChart' | 'cardEntities' |'cardGrid'|'cardGrid2'|'cardThermo'|'cardMedia'|'cardUnlock'|'cardQR'|'cardAlarm'|'cardPower' //| 'cardBurnRec' type PageType = PageChart | PageEntities | PageGrid | PageGrid2 | PageThermo | PageMedia | PageUnlock | PageQR | PageAlarm | PagePower @@ -9714,6 +9734,14 @@ type PageThermoItem = { popUpThermoName?: string[], setThermoAlias?: string[], setThermoDestTemp2?: string, +} & PageBaseItem | +{ + popupThermoMode1?: string[], + popupThermoMode2?: string[], + popupThermoMode3?: string[], + popUpThermoName?: string[], + setThermoAlias?: string[], + setThermoDestTemp2?: string, } & PageBaseItem type PageBaseItem = { @@ -9795,7 +9823,7 @@ type Config = { button2: ConfigButtonFunction } type leftScreensaverEntityType = [ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined] | []; -type indicatorScreensaverEntityType = [ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined] | []; +type indicatorScreensaverEntityType = [ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?] | []; type ScreenSaverElementWithUndefined = null | undefined | ScreenSaverElement type ScreenSaverElement = { ScreensaverEntity: string, @@ -9891,3 +9919,20 @@ function isEventMethod(F: string | EventMethod): F is EventMethod { return false; } } + +function isPopupType(F: PopupType | string): F is PopupType { + switch(F as PopupType) { + case "popupFan": + case "popupInSel": + case "popupLight": + case "popupLightNew": + case "popupNotify": + case "popupShutter": + case "popupThermo": + case "popupTimer": + return true; + default: + log(`Please report to developer: Unknown PopupType: ${F} `, 'warn'); + return false; + } +}