mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-19 20:54:43 +01:00
change schedule (testing needed)
add 1 extendObjectfor bgColorIndicator
This commit is contained in:
@@ -976,6 +976,8 @@ const moment = require('moment');
|
|||||||
const parseFormat = require('moment-parseformat');
|
const parseFormat = require('moment-parseformat');
|
||||||
moment.locale(getState(NSPanel_Path + 'Config.locale').val);
|
moment.locale(getState(NSPanel_Path + 'Config.locale').val);
|
||||||
|
|
||||||
|
const scheduleList:{[key:string]: any} = {};
|
||||||
|
|
||||||
const globalTextColor: any = White;
|
const globalTextColor: any = White;
|
||||||
const Sliders2: number = 0;
|
const Sliders2: number = 0;
|
||||||
let checkBlindActive: boolean = false;
|
let checkBlindActive: boolean = false;
|
||||||
@@ -1387,8 +1389,27 @@ Init_ActivePageData();
|
|||||||
//switch BackgroundColors for Screensaver Indicators
|
//switch BackgroundColors for Screensaver Indicators
|
||||||
async function Init_Screensaver_Backckground_Color_Switch() {
|
async function Init_Screensaver_Backckground_Color_Switch() {
|
||||||
try {
|
try {
|
||||||
if (existsState(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator') == false ) {
|
const objDef: iobJS.StateObject = {
|
||||||
await createStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', 0, true, { type: 'number' });
|
_id: '',
|
||||||
|
type: "state",
|
||||||
|
common: {
|
||||||
|
type: "number",
|
||||||
|
name: "Color Indicator",
|
||||||
|
role: "level",
|
||||||
|
states: {0:'black', 1:'red', 2:'green', 3:'attention', 4: 'pink'},
|
||||||
|
read: true,
|
||||||
|
write: true
|
||||||
|
},
|
||||||
|
"native": {},
|
||||||
|
};
|
||||||
|
await extendObjectAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', objDef)
|
||||||
|
if (await existsStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator')) {
|
||||||
|
const obj = await getStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator');
|
||||||
|
if (obj && obj.val !== null && obj.val !== undefined) {
|
||||||
|
bgColorScrSaver = obj.val;
|
||||||
|
} else {
|
||||||
|
setStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', bgColorScrSaver)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
log('error at function Init_Screensaver_Backckground_Color_Switch: ' + err.message, 'warn');
|
log('error at function Init_Screensaver_Backckground_Color_Switch: ' + err.message, 'warn');
|
||||||
@@ -1939,11 +1960,11 @@ async function InitDimmode() {
|
|||||||
timeNight: (vTimeNight < 10) ? `0${vTimeNight}:00` : `${vTimeNight}:00`
|
timeNight: (vTimeNight < 10) ? `0${vTimeNight}:00` : `${vTimeNight}:00`
|
||||||
};
|
};
|
||||||
// timeDimMode Day
|
// timeDimMode Day
|
||||||
scheduleInitDimModeDay = schedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourDay').val, minute: 0 }, () => {
|
scheduleInitDimModeDay = adapterSchedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourDay').val, minute: 0}, 24 * 60 * 60, () => {
|
||||||
ScreensaverDimmode(timeDimMode);
|
ScreensaverDimmode(timeDimMode);
|
||||||
});
|
});
|
||||||
// timeDimMode Night
|
// timeDimMode Night
|
||||||
scheduleInitDimModeNight = schedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourNight').val, minute: 0 }, () => {
|
scheduleInitDimModeNight = adapterSchedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourNight').val, minute: 0 }, 24 * 60 * 60, () => {
|
||||||
ScreensaverDimmode(timeDimMode);
|
ScreensaverDimmode(timeDimMode);
|
||||||
});
|
});
|
||||||
if (getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != null && getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != -1) {
|
if (getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != null && getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != -1) {
|
||||||
@@ -2142,7 +2163,7 @@ let pageId = 0;
|
|||||||
let activePage: PageType | undefined = undefined;
|
let activePage: PageType | undefined = undefined;
|
||||||
|
|
||||||
//Send time to NSPanel
|
//Send time to NSPanel
|
||||||
let scheduleSendTime = schedule('* * * * *', () => {
|
let scheduleSendTime = adapterSchedule(new Date().setMilliseconds(0), 1, () => {
|
||||||
try {
|
try {
|
||||||
SendTime();
|
SendTime();
|
||||||
HandleScreensaverUpdate();
|
HandleScreensaverUpdate();
|
||||||
@@ -2152,7 +2173,7 @@ let scheduleSendTime = schedule('* * * * *', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Switch between Screensaver Entities and WeatherForecast
|
//Switch between Screensaver Entities and WeatherForecast
|
||||||
let scheduleSwichScreensaver = schedule('*/' + getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val + ' * * * * *', () => {
|
let scheduleSwichScreensaver = adapterSchedule(undefined, parseInt(getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val), () => {
|
||||||
try {
|
try {
|
||||||
//WeatherForecast true/false Switchover delayed
|
//WeatherForecast true/false Switchover delayed
|
||||||
if (getState(NSPanel_Path + "ScreensaverInfo.popupNotifyHeading").val == '' && getState(NSPanel_Path + "ScreensaverInfo.popupNotifyText").val == '' && getState(NSPanel_Path + "ScreensaverInfo.weatherForecast").val == true && getState(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer").val == true) {
|
if (getState(NSPanel_Path + "ScreensaverInfo.popupNotifyHeading").val == '' && getState(NSPanel_Path + "ScreensaverInfo.popupNotifyText").val == '' && getState(NSPanel_Path + "ScreensaverInfo.weatherForecast").val == true && getState(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer").val == true) {
|
||||||
@@ -2211,17 +2232,17 @@ on({id: [config.weatherEntity + '.TEMP',
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let scheduleSendDate = schedule('0 * * * *', () => {
|
let scheduleSendDate = adapterSchedule((new Date().setMinutes(0,0)),60*60, () => {
|
||||||
SendDate();
|
SendDate();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3:30 a.m. Perform startup and receive current TFT version
|
// 3:30 a.m. Perform startup and receive current TFT version
|
||||||
let scheduleStartup = schedule({ hour: 3, minute: 30 }, async () => {
|
let scheduleStartup = adapterSchedule({ hour: 3, minute: 30 }, 24*60*60, async () => {
|
||||||
setIfExists(config.panelSendTopic, 'pageType~pageStartup');
|
setIfExists(config.panelSendTopic, 'pageType~pageStartup');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Updates currently compare every 12 hours
|
// Updates currently compare every 12 hours
|
||||||
let scheduleCheckUpdates = schedule('{"time":{"start":"00:00","end":"23:59","mode":"hours","interval":12},"period":{"days":1}}', () => {
|
let scheduleCheckUpdates = adapterSchedule(undefined,60*60*12, () => {
|
||||||
get_tasmota_status0();
|
get_tasmota_status0();
|
||||||
get_panel_update_data();
|
get_panel_update_data();
|
||||||
check_updates();
|
check_updates();
|
||||||
@@ -3330,19 +3351,19 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean =
|
|||||||
// ioBroker
|
// ioBroker
|
||||||
if (pageItem.id && existsObject(pageItem.id) || pageItem.navigate === true) {
|
if (pageItem.id && existsObject(pageItem.id) || pageItem.navigate === true) {
|
||||||
|
|
||||||
let iconColor = rgb_dec565(config.defaultColor);
|
let iconColor:number = rgb_dec565(config.defaultColor);
|
||||||
let optVal = '0';
|
let optVal:string = '0';
|
||||||
let val: any = null;
|
let val: any = null;
|
||||||
|
|
||||||
let o:any
|
let o:any = undefined;
|
||||||
if (pageItem.id != null && existsObject(pageItem.id)) {
|
if (pageItem.id != null && existsObject(pageItem.id)) {
|
||||||
o = getObject(pageItem.id);
|
o = getObject(pageItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback if no name is given
|
// Fallback if no name is given
|
||||||
name = pageItem.name !== undefined ? pageItem.name : o.common.name.de == undefined ? o.common.name : o.common.name.de;
|
name = pageItem.name !== undefined ? pageItem.name : o.common.name.de == undefined ? o.common.name : o.common.name.de;
|
||||||
let prefix = pageItem.prefixName !== undefined ? pageItem.prefixName : '';
|
const prefix = pageItem.prefixName !== undefined ? pageItem.prefixName : '';
|
||||||
let suffix = pageItem.suffixName !== undefined ? pageItem.suffixName : '';
|
const suffix = pageItem.suffixName !== undefined ? pageItem.suffixName : '';
|
||||||
|
|
||||||
// If name is used with changing values
|
// If name is used with changing values
|
||||||
if ((name || '').indexOf('getState(') != -1) {
|
if ((name || '').indexOf('getState(') != -1) {
|
||||||
@@ -3350,6 +3371,10 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean =
|
|||||||
name = getState(dpName).val;
|
name = getState(dpName).val;
|
||||||
RegisterEntityWatcher(dpName);
|
RegisterEntityWatcher(dpName);
|
||||||
}
|
}
|
||||||
|
else if ((name || '').split('.').length > 3 && existsState(name)) {
|
||||||
|
name = getState(name).val;
|
||||||
|
RegisterEntityWatcher(name);
|
||||||
|
}
|
||||||
name = prefix + name + suffix;
|
name = prefix + name + suffix;
|
||||||
|
|
||||||
if (existsState(pageItem.id + '.GET')) {
|
if (existsState(pageItem.id + '.GET')) {
|
||||||
@@ -8594,7 +8619,6 @@ function HandleScreensaverUpdate(): void {
|
|||||||
|
|
||||||
//Alternativ Layout bekommt zusätzlichen Status
|
//Alternativ Layout bekommt zusätzlichen Status
|
||||||
if (config.bottomScreensaverEntity[4] && getState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout').val) {
|
if (config.bottomScreensaverEntity[4] && getState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout').val) {
|
||||||
log('alternativ');
|
|
||||||
let val = getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val;
|
let val = getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val;
|
||||||
if (parseFloat(val+"") == val) {
|
if (parseFloat(val+"") == val) {
|
||||||
val = parseFloat(val);
|
val = parseFloat(val);
|
||||||
@@ -9024,6 +9048,8 @@ function HandleScreensaverColors(): void {
|
|||||||
scrSvrBGCol = rgb_dec565(scbackgroundInd2);
|
scrSvrBGCol = rgb_dec565(scbackgroundInd2);
|
||||||
} else if (bgColorScrSaver == 3) {
|
} else if (bgColorScrSaver == 3) {
|
||||||
scrSvrBGCol = rgb_dec565(scbackgroundInd3);
|
scrSvrBGCol = rgb_dec565(scbackgroundInd3);
|
||||||
|
} else if (bgColorScrSaver == 4) {
|
||||||
|
scrSvrBGCol = rgb_dec565({red:255, green:16, blue:240});
|
||||||
}
|
}
|
||||||
|
|
||||||
let payloadString = 'color' + '~' +
|
let payloadString = 'color' + '~' +
|
||||||
@@ -9632,6 +9658,39 @@ type PageUnlock = NSPanel.PageUnlock;
|
|||||||
type PageAlarm = NSPanel.PageAlarm;
|
type PageAlarm = NSPanel.PageAlarm;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// dont work with summer/winter time has to be fixed
|
||||||
|
function adapterSchedule(time: {hour?: number, minute?: number} | undefined | number, repeatTime: number, callback: () => void): number|null {
|
||||||
|
if (typeof callback !== 'function') return null
|
||||||
|
const ref = Math.random() + 1;
|
||||||
|
scheduleList[ref] = setTimeout(_schedule, 1, time, ref, repeatTime, callback);
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _schedule(time: {hour?: number, minute?: number} | undefined | number, ref: number, repeatTime, callback) {
|
||||||
|
if (!scheduleList[ref]) return;
|
||||||
|
callback();
|
||||||
|
let targetTime: number;
|
||||||
|
if ( time === undefined) {
|
||||||
|
targetTime = new Date().setMilliseconds(0) + repeatTime * 1000;
|
||||||
|
} else if (typeof time === 'number') {
|
||||||
|
targetTime = time + repeatTime * 1000;
|
||||||
|
} else {
|
||||||
|
time.hour = time.hour !== undefined ? time.hour : 0;
|
||||||
|
time.minute = time.minute !== undefined ? time.minute : 0;
|
||||||
|
targetTime = time.hour !== undefined ? new Date().setHours(time.hour, time.minute, 0) : new Date().setMinutes(time.minute, 0);
|
||||||
|
if (new Date().getTime() > targetTime) {
|
||||||
|
targetTime += repeatTime * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const timeout = targetTime - new Date().getTime();
|
||||||
|
scheduleList[ref] = setTimeout(_schedule, timeout, targetTime, ref, repeatTime, callback);
|
||||||
|
}
|
||||||
|
function _clearSchedule(ref: number): null {
|
||||||
|
if (scheduleList[ref]) clearTimeout(scheduleList[ref]);
|
||||||
|
delete scheduleList[ref];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const ArrayPlayerTypeWithMediaDevice = ['alexa2', 'sonos', 'squeezeboxrpc'] as const
|
const ArrayPlayerTypeWithMediaDevice = ['alexa2', 'sonos', 'squeezeboxrpc'] as const
|
||||||
const ArrayPlayerTypeWithOutMediaDevice = ['spotify-premium', 'volumio', 'bosesoundtouch'] as const
|
const ArrayPlayerTypeWithOutMediaDevice = ['spotify-premium', 'volumio', 'bosesoundtouch'] as const
|
||||||
|
|
||||||
@@ -9844,7 +9903,8 @@ namespace NSPanel {
|
|||||||
setThermoAlias?: string[],
|
setThermoAlias?: string[],
|
||||||
setThermoDestTemp2?: string,
|
setThermoDestTemp2?: string,
|
||||||
} & PageBaseItem
|
} & PageBaseItem
|
||||||
|
// mean string start with getState(' and end with ').val
|
||||||
|
type getStateID = string;
|
||||||
export type PageBaseItem = {
|
export type PageBaseItem = {
|
||||||
id?: string | null,
|
id?: string | null,
|
||||||
icon?: string,
|
icon?: string,
|
||||||
@@ -9866,7 +9926,7 @@ namespace NSPanel {
|
|||||||
stepValue?: number,
|
stepValue?: number,
|
||||||
prefixName?: string,
|
prefixName?: string,
|
||||||
suffixName?: string,
|
suffixName?: string,
|
||||||
name?: string,
|
name?: string | getStateID,
|
||||||
secondRow?: string,
|
secondRow?: string,
|
||||||
buttonText?: string,
|
buttonText?: string,
|
||||||
unit?: string,
|
unit?: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user