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
+36 -34
View File
@@ -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);
+1 -1
View File
@@ -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);
+10 -4
View File
@@ -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