optimize timemaster first start of day

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-04-21 08:15:39 +02:00
parent 3c85fa61b6
commit b5561729f7
5 changed files with 55 additions and 41 deletions
+4 -1
View File
@@ -28,6 +28,7 @@
"API Error": "API-Fehler", "API Error": "API-Fehler",
"Offline": "Offline", "Offline": "Offline",
"Connecting…": "Verbinde…", "Connecting…": "Verbinde…",
"Waiting…": "Warten…",
"No Host": "Kein Host", "No Host": "Kein Host",
"Off": "Aus", "Off": "Aus",
"Day": "Tag", "Day": "Tag",
@@ -38,6 +39,8 @@
"Password": "Passwort", "Password": "Passwort",
"Device ID": "Geräte-ID", "Device ID": "Geräte-ID",
"Topic": "Topic", "Topic": "Topic",
"Not configured": "Nicht konfiguriert" "Not configured": "Nicht konfiguriert",
"VPN?": "VPN?",
"See log": "Siehe Log"
} }
} }
+4 -1
View File
@@ -28,6 +28,7 @@
"API Error": "API Error", "API Error": "API Error",
"Offline": "Offline", "Offline": "Offline",
"Connecting…": "Connecting…", "Connecting…": "Connecting…",
"Waiting…": "Waiting…",
"No Host": "No Host", "No Host": "No Host",
"Off": "Off", "Off": "Off",
"Day": "Day", "Day": "Day",
@@ -38,6 +39,8 @@
"Password": "Password", "Password": "Password",
"Device ID": "Device ID", "Device ID": "Device ID",
"Topic": "Topic", "Topic": "Topic",
"Not configured": "Not configured" "Not configured": "Not configured",
"VPN?": "VPN?",
"See log": "See log"
} }
} }
+36 -34
View File
@@ -8,16 +8,16 @@ class PetrolAction extends ActionBase {
refreshRate: '1', refreshRate: '1',
}; };
this.previousPrice = null; this.previousPrice = null;
this.lastDelta = null;
this.lastRised = null; this.lastRised = null;
this.prevLastRised = null;
this.$UD.onDidReceiveSettings(jsn => { this.$UD.onDidReceiveSettings(jsn => {
if (jsn.context !== this.context) return; if (jsn.context !== this.context) return;
const s = jsn.settings || {}; const s = jsn.settings || {};
this.config = Object.assign(this.config, s); this.config = Object.assign(this.config, s);
if (s.previousPrice != null) this.previousPrice = s.previousPrice; if (s.previousPrice != null) this.previousPrice = s.previousPrice;
if (s.lastDelta != null) this.lastDelta = s.lastDelta; if (s.lastRised > 0) this.lastRised = s.lastRised;
if (s.lastRised != null) this.lastRised = s.lastRised; if (s.prevLastRised > 0) this.prevLastRised = s.prevLastRised;
}); });
} }
@@ -36,7 +36,7 @@ class PetrolAction extends ActionBase {
fetchPrice() { fetchPrice() {
this.debounce(async () => { this.debounce(async () => {
if (!this.config.url || !this.config.stationUuid || !this.config.fuelType) { if (!this.config.url || !this.config.stationUuid || !this.config.fuelType) {
this.renderButton('?', null); this.renderButton('?');
return; return;
} }
try { try {
@@ -47,17 +47,25 @@ class PetrolAction extends ActionBase {
const current = parseFloat(raw); const current = parseFloat(raw);
if (this.previousPrice !== null) { if (this.previousPrice !== null) {
const delta = current - this.previousPrice; const delta = current - this.previousPrice;
if (delta !== 0) this.lastDelta = delta; if (delta > 0) {
if (delta > 0) this.lastRised = current; this.prevLastRised = this.lastRised;
this.lastRised = current;
}
} }
this.previousPrice = 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 { } else {
this.renderButton('N/A', null); this.renderButton('N/A');
} }
} catch (e) { } catch (e) {
this.renderButton('ERR', null); this.renderButton('ERR');
} }
}); });
} }
@@ -74,45 +82,39 @@ class PetrolAction extends ActionBase {
return null; return null;
} }
renderButton(priceText, delta) { renderButton(priceText) {
const { canvas, ctx } = this.createCanvas(); const { canvas, ctx } = this.createCanvas();
if (this.lastRised !== null) { let risedColor = '#888888';
const lastRised = this.lastRised; if (this.lastRised > 0 && this.prevLastRised > 0) {
// Compact layout with lastRised risedColor = this.lastRised < this.prevLastRised ? '#6bff6b' : '#ff6b6b';
ctx.fillStyle = '#7ec8e3'; }
ctx.font = 'bold 24px "Source Han Sans SC"';
ctx.fillText(this.config.fuelType, 98, 28);
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.fillStyle = '#f0c040';
ctx.font = `bold ${fSize}px "Source Han Sans SC"`; ctx.font = `bold ${fSize}px "Source Han Sans SC"`;
ctx.fillText(priceText, 98, 95); ctx.fillText(priceText, 98, 82);
ctx.fillStyle = '#888888'; ctx.fillStyle = '#888888';
ctx.font = '22px "Source Han Sans SC"'; ctx.font = '20px "Source Han Sans SC"';
ctx.fillText(this.$UD.t('Last Rised'), 98, 143); ctx.fillText(this.$UD.t('Last Rised'), 98, 130);
ctx.fillStyle = '#ff6b6b'; ctx.fillStyle = risedColor;
ctx.font = 'bold 30px "Source Han Sans SC"'; ctx.font = 'bold 28px "Source Han Sans SC"';
ctx.fillText(`${lastRised.toFixed(3)}`, 98, 168); ctx.fillText(`${this.lastRised.toFixed(3)}`, 98, 162);
} else { } else {
// Original layout
ctx.fillStyle = '#7ec8e3'; ctx.fillStyle = '#7ec8e3';
ctx.font = 'bold 28px "Source Han Sans SC"'; 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; const fSize = priceText.length > 6 ? 38 : 46;
ctx.fillStyle = '#f0c040'; ctx.fillStyle = '#f0c040';
ctx.font = `bold ${fSize}px "Source Han Sans SC"`; ctx.font = `bold ${fSize}px "Source Han Sans SC"`;
ctx.fillText(priceText, 98, 105); 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); this.setIcon(canvas);
+1 -1
View File
@@ -201,7 +201,7 @@ class RailwayAction extends ActionBase {
ctx.fillText(short, 98, 155); ctx.fillText(short, 98, 155);
ctx.font = '14px "Source Han Sans SC"'; ctx.font = '14px "Source Han Sans SC"';
ctx.fillStyle = '#888888'; ctx.fillStyle = '#888888';
ctx.fillText('(see log)', 98, 175); ctx.fillText(this.$UD.t('See log'), 98, 175);
} else { } else {
ctx.font = '22px "Source Han Sans SC"'; ctx.font = '22px "Source Han Sans SC"';
ctx.fillText(missing ? this.$UD.t('Not configured') : this.$UD.t('Connecting…'), 98, 162); ctx.fillText(missing ? this.$UD.t('Not configured') : this.$UD.t('Connecting…'), 98, 162);
+10 -4
View File
@@ -8,6 +8,7 @@ class TimemasterAction extends ActionBase {
this.reconnectTimer = null; this.reconnectTimer = null;
this.connected = false; this.connected = false;
this.handshakeDone = false; this.handshakeDone = false;
this.dataReceived = false;
this.isError = false; this.isError = false;
this.errorText = null; this.errorText = null;
this.noServer = false; this.noServer = false;
@@ -111,6 +112,7 @@ class TimemasterAction extends ActionBase {
} }
this.connected = false; this.connected = false;
this.handshakeDone = false; this.handshakeDone = false;
this.dataReceived = false;
} }
host() { host() {
@@ -286,7 +288,7 @@ class TimemasterAction extends ActionBase {
if (msg.type === 1 && Array.isArray(msg.arguments)) { if (msg.type === 1 && Array.isArray(msg.arguments)) {
if (msg.target === 'Info.UpdateLastWorkingHours') { 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) { for (const arg of msg.arguments) {
this.parseWorkingHours(arg); this.parseWorkingHours(arg);
} }
@@ -462,7 +464,7 @@ class TimemasterAction extends ActionBase {
if (this.noServer) { if (this.noServer) {
ctx.fillStyle = '#ff6b6b'; ctx.fillStyle = '#ff6b6b';
ctx.font = 'bold 22px "Source Han Sans SC"'; 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.fillStyle = '#888888';
ctx.font = '16px "Source Han Sans SC"'; ctx.font = '16px "Source Han Sans SC"';
ctx.fillText(this.$UD.t('No Host'), cx, cy + 16); ctx.fillText(this.$UD.t('No Host'), cx, cy + 16);
@@ -476,10 +478,14 @@ class TimemasterAction extends ActionBase {
cx, cy cx, cy
); );
} }
} else { } else if (this.dataReceived) {
ctx.fillStyle = '#666666'; 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.font = 'bold 22px "Source Han Sans SC"';
ctx.fillText('Warten…', cx, cy); ctx.fillText(this.$UD.t('Waiting…'), cx, cy);
} }
// Bottom label // Bottom label