Compare commits

...

10 Commits

Author SHA1 Message Date
slajob
2103411de1 Merge 127671047f into bd24d4bcd1 2024-01-24 16:17:43 +01:00
Armilar
bd24d4bcd1 Merge pull request #1151 from ticaki/main
2 Points
2024-01-23 22:04:52 +01:00
ticaki
4aab72fb10 build nice objects 2024-01-23 18:36:03 +01:00
ticaki
aa266da5ac fix txt.matchall 2024-01-23 18:17:37 +01:00
ticaki
49987d55ce Merge branch 'joBr99:main' into main 2024-01-23 18:16:59 +01:00
Armilar
c6939efd70 Merge pull request #1149 from theknut/patch-1
feat: write button event to states
2024-01-23 18:16:19 +01:00
ticaki
f7f853f05e Add setOn / setOff 2024-01-23 16:55:07 +01:00
ticaki
1faa540a70 Add some optional types 2024-01-23 07:58:21 +01:00
theknut
1746c876bd feat: write button event to states
Whenever a button is pressed there is no event triggered which lets the user easily implement triggers on this event.
This PR adds the functionality that the current button event is written to NSPanel objects structures as states under `0_userdata.0.NSPanel.1.Event.Button`:
- Action - whatever button was pressed (button, media-OnOff, volumeSlider, ...)
- Value -  auxillary value for this action (e.g. action `volumeSlider` - `Value` holds the value the slider was moved to)
- Id
  - Action == `button` - Id of the alias the button is connected to
  - else - Id of the current page item or the page to navigate to
2024-01-22 00:19:23 +01:00
slajob
127671047f missing friday entity from example photo 2024-01-10 18:22:05 +01:00
2 changed files with 37 additions and 7 deletions

View File

@@ -44,6 +44,8 @@ Using a 6th entity will automatically activate the alternative layout.
type: 0 type: 0
- entity: weather.demo_weather_north - entity: weather.demo_weather_north
type: 1 type: 1
- entity: weather.demo_weather_north
type: 2
- entity: sensor.energy_usage - entity: sensor.energy_usage
- entity: delete - entity: delete
- entity: sensor.indoor_temp - entity: sensor.indoor_temp

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
TypeScript v4.3.3.38 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @ticaki / @Britzelpuf / @Sternmiere / @ravenS0ne TypeScript v4.3.3.39 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 - 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 @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 NsPanelTs.ts (dieses TypeScript in ioBroker) Stable: https://github.com/joBr99/nspanel-lovelace-ui/blob/main/ioBroker/NsPanelTs.ts
@@ -103,8 +103,9 @@ ReleaseNotes:
- 16.01.2024 - v4.3.3.38 Optimate: function SendTime() - 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: ScreensaverEntityIconSelect for MRIcons is like common.states for states.
- 17.01.2024 - v4.3.3.38 Add: Changing the ScreensaverEntityValue value updates the screensaver. - 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 - 19.01.2024 - v4.3.3.38 Change: yAxisTicks parameter is not required in cardLChart PageItem
- 20.01.2024 - v4.3.3.38 Add: click on indicatorIcon navigate to Page - 20.01.2024 - v4.3.3.38 Add: click on indicatorIcon navigate to Page
- 23.01.2024 - v4.3.3.39 Add: Optional setOn & setOff for HW button with mode 'set'
Todo: Todo:
@@ -972,7 +973,7 @@ export const config: Config = {
// _________________________________ DE: Ab hier keine Konfiguration mehr _____________________________________ // _________________________________ DE: Ab hier keine Konfiguration mehr _____________________________________
// _________________________________ EN: No more configuration from here _____________________________________ // _________________________________ EN: No more configuration from here _____________________________________
const scriptVersion: string = 'v4.3.3.38'; const scriptVersion: string = 'v4.3.3.39';
const tft_version: string = 'v4.3.3'; const tft_version: string = 'v4.3.3';
const desired_display_firmware_version = 53; const desired_display_firmware_version = 53;
const berry_driver_version = 9; const berry_driver_version = 9;
@@ -986,6 +987,8 @@ let weatherForecast: boolean;
let pageCounter: number = 0; let pageCounter: number = 0;
let alwaysOn: boolean = false; let alwaysOn: boolean = false;
let buttonToggleState: {[key: string]: boolean} = {};
const axios = require('axios'); const axios = require('axios');
const dayjs = require('dayjs'); const dayjs = require('dayjs');
const moment = require('moment'); const moment = require('moment');
@@ -3242,7 +3245,13 @@ function HandleHardwareButton(method: NSPanel.EventMethod): void {
break; break;
case 'set': case 'set':
if (Debug) log('HandleHardwareButton -> Mode Set', 'info'); if (Debug) log('HandleHardwareButton -> Mode Set', 'info');
if (buttonConfig.entity) { if (buttonConfig.setOn && existsState(buttonConfig.setOn.dp) && !buttonToggleState[method]) {
setState(buttonConfig.setOn.dp, buttonConfig.setOn.val);
buttonToggleState[method] = true;
} else if (buttonConfig.setOff && existsState(buttonConfig.setOff.dp) && buttonToggleState[method]) {
setState(buttonConfig.setOff.dp, buttonConfig.setOff.val);
buttonToggleState[method] = false;
} else if (buttonConfig.entity && existsState(buttonConfig.entity)) {
setState(buttonConfig.entity, buttonConfig.setValue); setState(buttonConfig.entity, buttonConfig.setValue);
} }
screensaverEnabled = true; screensaverEnabled = true;
@@ -6179,7 +6188,7 @@ function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] {
let yAxisTicks : number[] = []; let yAxisTicks : number[] = [];
if (!page.items[0].yAxisTicks) { if (!page.items[0].yAxisTicks) {
const sorted = [...txt.matchAll(timeValueRegEx)].map(x => Number(x[1])).sort((x, y) => x < y ? -1 : 1); const sorted = [...String(txt).matchAll(timeValueRegEx)].map(x => Number(x[1])).sort((x, y) => x < y ? -1 : 1);
if (sorted.length === 0) { if (sorted.length === 0) {
throw new Error (`Page item ${id} yAxisTicks is undefined and unable to be calculated!`) throw new Error (`Page item ${id} yAxisTicks is undefined and unable to be calculated!`)
} }
@@ -6313,6 +6322,10 @@ function HandleButtonEvent(words: any): void {
SendToPanel({ payload: 'timeout~' + getState(NSPanel_Path + 'Config.Screensaver.timeoutScreensaver').val }); SendToPanel({ payload: 'timeout~' + getState(NSPanel_Path + 'Config.Screensaver.timeoutScreensaver').val });
} }
setOrCreate(NSPanel_Path + "Event.Button.Action", buttonAction ?? words[2], false, {name: 'Incoming button acion', type: 'string', role: 'text', write: false, read: true});
setOrCreate(NSPanel_Path + "Event.Button.Value", words[4] != undefined ? words[4] : '', false, {name: 'Incoming button value', type: 'string', role: 'text', write: false, read: true});
setOrCreate(NSPanel_Path + "Event.Button.Id", id, false, {name: 'Incoming button id', type: 'string', role: 'text', write: false, read: true});
if (Debug) { if (Debug) {
log('HandleButtonEvent buttonAction: ' + buttonAction, 'info'); log('HandleButtonEvent buttonAction: ' + buttonAction, 'info');
} }
@@ -7359,6 +7372,16 @@ function HandleButtonEvent(words: any): void {
} }
} }
function setOrCreate(id : string, value : any, forceCreation: boolean = true, common: Partial<iobJS.StateCommon> = { }, callback?: iobJS.SetStateCallback) {
if (!existsState(id)) {
extendObject(id.split('.').slice(0, -2).join('.'), {type: 'channel', common:{name: 'channel'}, native:{}});
extendObject(id.split('.').slice(0, -1).join('.'), {type: 'channel', common:{name: 'channel'}, native:{}});
createState(id, value, forceCreation, common, callback);
} else {
setState(id, value, true);
}
}
//Determination of page navigation (CustomSend-Payload) //Determination of page navigation (CustomSend-Payload)
function GetNavigationString(pageId: number): string { function GetNavigationString(pageId: number): string {
try { try {
@@ -9037,7 +9060,7 @@ function HandleScreensaverStatusIcons() : void {
} else { } else {
payloadString += '~'; payloadString += '~';
} }
// statusUpdate~icon1~icon1Color~icon1font~icon2~icon2color~icon2font~icon2font
SendToPanel({ payload: 'statusUpdate~' + payloadString }); SendToPanel({ payload: 'statusUpdate~' + payloadString });
} catch (err: any) { } catch (err: any) {
@@ -9891,6 +9914,7 @@ namespace NSPanel {
export type PageBaseType = { export type PageBaseType = {
type: PagetypeType, type: PagetypeType,
uniqueName?: string,
heading: string, heading: string,
items: PageItem[], items: PageItem[],
useColor: boolean, useColor: boolean,
@@ -10001,6 +10025,8 @@ namespace NSPanel {
// mean string start with getState(' and end with ').val // mean string start with getState(' and end with ').val
type getStateID = string; type getStateID = string;
export type PageBaseItem = { export type PageBaseItem = {
uniqueName?: string,
role?: string,
id?: string | null, id?: string | null,
icon?: string, icon?: string,
icon2?: string, icon2?: string,
@@ -10058,6 +10084,8 @@ namespace NSPanel {
page: (PageThermo | PageMedia | PageAlarm | PageQR | PageEntities | PageGrid | PageGrid2 | PagePower | PageChart | PageUnlock | null), page: (PageThermo | PageMedia | PageAlarm | PageQR | PageEntities | PageGrid | PageGrid2 | PagePower | PageChart | PageUnlock | null),
entity: string | null, entity: string | null,
setValue: string | number | boolean | null setValue: string | number | boolean | null
setOn?: {dp:string, val:iobJS.StateValue}
setOff?: {dp:string, val:iobJS.StateValue};
} }
export type Config = { export type Config = {