From b5561729f70410e2aca7177e415c0147d5cb20bc Mon Sep 17 00:00:00 2001 From: Peter Siegmund Date: Tue, 21 Apr 2026 08:15:39 +0200 Subject: [PATCH] optimize timemaster first start of day Signed-off-by: Peter Siegmund --- de_DE.json | 5 ++- en.json | 5 ++- plugin/actions/PetrolAction.js | 70 +++++++++++++++--------------- plugin/actions/RailwayAction.js | 2 +- plugin/actions/TimemasterAction.js | 14 ++++-- 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/de_DE.json b/de_DE.json index 0d183cf..9fd3da9 100644 --- a/de_DE.json +++ b/de_DE.json @@ -28,6 +28,7 @@ "API Error": "API-Fehler", "Offline": "Offline", "Connecting…": "Verbinde…", + "Waiting…": "Warten…", "No Host": "Kein Host", "Off": "Aus", "Day": "Tag", @@ -38,6 +39,8 @@ "Password": "Passwort", "Device ID": "Geräte-ID", "Topic": "Topic", - "Not configured": "Nicht konfiguriert" + "Not configured": "Nicht konfiguriert", + "VPN?": "VPN?", + "See log": "Siehe Log" } } diff --git a/en.json b/en.json index 35e96ef..515aae7 100644 --- a/en.json +++ b/en.json @@ -28,6 +28,7 @@ "API Error": "API Error", "Offline": "Offline", "Connecting…": "Connecting…", + "Waiting…": "Waiting…", "No Host": "No Host", "Off": "Off", "Day": "Day", @@ -38,6 +39,8 @@ "Password": "Password", "Device ID": "Device ID", "Topic": "Topic", - "Not configured": "Not configured" + "Not configured": "Not configured", + "VPN?": "VPN?", + "See log": "See log" } } diff --git a/plugin/actions/PetrolAction.js b/plugin/actions/PetrolAction.js index 22552bb..2e17d91 100644 --- a/plugin/actions/PetrolAction.js +++ b/plugin/actions/PetrolAction.js @@ -8,16 +8,16 @@ class PetrolAction extends ActionBase { refreshRate: '1', }; this.previousPrice = null; - this.lastDelta = null; this.lastRised = null; + this.prevLastRised = null; this.$UD.onDidReceiveSettings(jsn => { if (jsn.context !== this.context) return; const s = jsn.settings || {}; this.config = Object.assign(this.config, s); if (s.previousPrice != null) this.previousPrice = s.previousPrice; - if (s.lastDelta != null) this.lastDelta = s.lastDelta; - if (s.lastRised != null) this.lastRised = s.lastRised; + if (s.lastRised > 0) this.lastRised = s.lastRised; + if (s.prevLastRised > 0) this.prevLastRised = s.prevLastRised; }); } @@ -36,7 +36,7 @@ class PetrolAction extends ActionBase { fetchPrice() { this.debounce(async () => { if (!this.config.url || !this.config.stationUuid || !this.config.fuelType) { - this.renderButton('?', null); + this.renderButton('?'); return; } try { @@ -47,17 +47,25 @@ class PetrolAction extends ActionBase { const current = parseFloat(raw); if (this.previousPrice !== null) { const delta = current - this.previousPrice; - if (delta !== 0) this.lastDelta = delta; - if (delta > 0) this.lastRised = current; + if (delta > 0) { + this.prevLastRised = this.lastRised; + this.lastRised = current; + } } this.previousPrice = current; - this.renderButton(`${parseFloat(raw).toFixed(3)}€`, this.lastDelta); - this.$UD.setSettings({ ...this.config, previousPrice: this.previousPrice, lastDelta: this.lastDelta, lastRised: this.lastRised }, this.context); + + this.renderButton(`${parseFloat(raw).toFixed(3)}€`); + this.$UD.setSettings({ + ...this.config, + previousPrice: this.previousPrice, + lastRised: this.lastRised, + prevLastRised: this.prevLastRised, + }, this.context); } else { - this.renderButton('N/A', null); + this.renderButton('N/A'); } } catch (e) { - this.renderButton('ERR', null); + this.renderButton('ERR'); } }); } @@ -74,45 +82,39 @@ class PetrolAction extends ActionBase { return null; } - renderButton(priceText, delta) { + renderButton(priceText) { const { canvas, ctx } = this.createCanvas(); - if (this.lastRised !== null) { - const lastRised = this.lastRised; - // Compact layout with lastRised - ctx.fillStyle = '#7ec8e3'; - ctx.font = 'bold 24px "Source Han Sans SC"'; - ctx.fillText(this.config.fuelType, 98, 28); + let risedColor = '#888888'; + if (this.lastRised > 0 && this.prevLastRised > 0) { + risedColor = this.lastRised < this.prevLastRised ? '#6bff6b' : '#ff6b6b'; + } - const fSize = priceText.length > 6 ? 38 : 46; + if (this.lastRised !== null) { + ctx.fillStyle = '#7ec8e3'; + ctx.font = 'bold 22px "Source Han Sans SC"'; + ctx.fillText(this.config.fuelType, 98, 25); + + const fSize = priceText.length > 6 ? 36 : 42; ctx.fillStyle = '#f0c040'; ctx.font = `bold ${fSize}px "Source Han Sans SC"`; - ctx.fillText(priceText, 98, 95); + ctx.fillText(priceText, 98, 82); ctx.fillStyle = '#888888'; - ctx.font = '22px "Source Han Sans SC"'; - ctx.fillText(this.$UD.t('Last Rised'), 98, 143); - ctx.fillStyle = '#ff6b6b'; - ctx.font = 'bold 30px "Source Han Sans SC"'; - ctx.fillText(`${lastRised.toFixed(3)}€`, 98, 168); + ctx.font = '20px "Source Han Sans SC"'; + ctx.fillText(this.$UD.t('Last Rised'), 98, 130); + ctx.fillStyle = risedColor; + ctx.font = 'bold 28px "Source Han Sans SC"'; + ctx.fillText(`${this.lastRised.toFixed(3)}€`, 98, 162); } else { - // Original layout ctx.fillStyle = '#7ec8e3'; ctx.font = 'bold 28px "Source Han Sans SC"'; - ctx.fillText(this.config.fuelType, 98, 45); + ctx.fillText(this.config.fuelType, 98, 42); const fSize = priceText.length > 6 ? 38 : 46; ctx.fillStyle = '#f0c040'; ctx.font = `bold ${fSize}px "Source Han Sans SC"`; ctx.fillText(priceText, 98, 105); - - if (delta !== null) { - const arrow = delta > 0 ? '▲' : '▼'; - const color = delta > 0 ? '#ff6b6b' : '#6bff6b'; - ctx.fillStyle = color; - ctx.font = '24px "Source Han Sans SC"'; - ctx.fillText(`${arrow} ${Math.abs(delta).toFixed(3)}`, 98, 142); - } } this.setIcon(canvas); diff --git a/plugin/actions/RailwayAction.js b/plugin/actions/RailwayAction.js index a2ff39b..277fa38 100644 --- a/plugin/actions/RailwayAction.js +++ b/plugin/actions/RailwayAction.js @@ -201,7 +201,7 @@ class RailwayAction extends ActionBase { ctx.fillText(short, 98, 155); ctx.font = '14px "Source Han Sans SC"'; ctx.fillStyle = '#888888'; - ctx.fillText('(see log)', 98, 175); + ctx.fillText(this.$UD.t('See log'), 98, 175); } else { ctx.font = '22px "Source Han Sans SC"'; ctx.fillText(missing ? this.$UD.t('Not configured') : this.$UD.t('Connecting…'), 98, 162); diff --git a/plugin/actions/TimemasterAction.js b/plugin/actions/TimemasterAction.js index 88f4be4..c992939 100644 --- a/plugin/actions/TimemasterAction.js +++ b/plugin/actions/TimemasterAction.js @@ -8,6 +8,7 @@ class TimemasterAction extends ActionBase { this.reconnectTimer = null; this.connected = false; this.handshakeDone = false; + this.dataReceived = false; this.isError = false; this.errorText = null; this.noServer = false; @@ -111,6 +112,7 @@ class TimemasterAction extends ActionBase { } this.connected = false; this.handshakeDone = false; + this.dataReceived = false; } host() { @@ -286,7 +288,7 @@ class TimemasterAction extends ActionBase { if (msg.type === 1 && Array.isArray(msg.arguments)) { if (msg.target === 'Info.UpdateLastWorkingHours') { - console.log(`[Timemaster] ${msg.target}:`, JSON.stringify(msg.arguments).slice(0, 200)); + this.dataReceived = true; for (const arg of msg.arguments) { this.parseWorkingHours(arg); } @@ -462,7 +464,7 @@ class TimemasterAction extends ActionBase { if (this.noServer) { ctx.fillStyle = '#ff6b6b'; ctx.font = 'bold 22px "Source Han Sans SC"'; - ctx.fillText('VPN?', cx, cy - 10); + ctx.fillText(this.$UD.t('VPN?'), cx, cy - 10); ctx.fillStyle = '#888888'; ctx.font = '16px "Source Han Sans SC"'; ctx.fillText(this.$UD.t('No Host'), cx, cy + 16); @@ -476,10 +478,14 @@ class TimemasterAction extends ActionBase { cx, cy ); } - } else { + } else if (this.dataReceived) { ctx.fillStyle = '#666666'; + ctx.font = 'bold 44px "Source Han Sans SC"'; + ctx.fillText('00:00', cx, cy); + } else { + ctx.fillStyle = '#444444'; ctx.font = 'bold 22px "Source Han Sans SC"'; - ctx.fillText('Warten…', cx, cy); + ctx.fillText(this.$UD.t('Waiting…'), cx, cy); } // Bottom label