allow parsing config with missing keys, added nightlamp config stuff, added nightlamp testing,

This commit is contained in:
2025-03-08 18:47:30 +01:00
parent a4fd4acaa3
commit d11dc523f0
9 changed files with 140 additions and 41 deletions

View File

@@ -4,12 +4,26 @@ export class NightLampView {
private readonly night_lamp_only_when_dark: HTMLInputElement;
private readonly night_lamp_time_start: HTMLSelectElement;
private readonly night_lamp_time_end: HTMLSelectElement;
private readonly night_lamp_test: HTMLInputElement;
private readonly night_lamp_enabled: HTMLInputElement;
private readonly night_lamp_soc_low: HTMLInputElement;
private readonly night_lamp_soc_restore: HTMLInputElement;
constructor(controller:Controller){
(document.getElementById("lightview") as HTMLElement).innerHTML = require('./nightlightview.html') as string;
this.night_lamp_only_when_dark = document.getElementById("night_lamp_only_when_dark") as HTMLInputElement;
this.night_lamp_only_when_dark.onchange = controller.configChanged
this.night_lamp_enabled = document.getElementById("night_lamp_enabled") as HTMLInputElement;
this.night_lamp_enabled.onchange = controller.configChanged
this.night_lamp_soc_low = document.getElementById("night_lamp_soc_low") as HTMLInputElement;
this.night_lamp_soc_low.onchange = controller.configChanged
this.night_lamp_soc_restore = document.getElementById("night_lamp_soc_restore") as HTMLInputElement;
this.night_lamp_soc_restore.onchange = controller.configChanged
this.night_lamp_time_start = document.getElementById("night_lamp_time_start") as HTMLSelectElement;
this.night_lamp_time_start.onchange = controller.configChanged
for (let i = 0; i < 24; i++) {
@@ -31,12 +45,21 @@ export class NightLampView {
option.innerText = i.toString();
this.night_lamp_time_end.appendChild(option);
}
let night_lamp_test = document.getElementById("night_lamp_test") as HTMLInputElement;
this.night_lamp_test = night_lamp_test
this.night_lamp_test.onchange = () => {
controller.testNightLamp(night_lamp_test.checked)
}
}
setConfig(nightLamp: NightLampConfig) {
this.night_lamp_only_when_dark.checked = nightLamp.night_lamp_only_when_dark
this.night_lamp_time_start.value = nightLamp.night_lamp_hour_start.toString();
this.night_lamp_time_end.value = nightLamp.night_lamp_hour_end.toString();
this.night_lamp_enabled.checked = nightLamp.enabled;
this.night_lamp_soc_low.value = nightLamp.low_soc_cutoff.toString();
this.night_lamp_soc_restore.value = nightLamp.low_soc_restore.toString();
}
getConfig(): NightLampConfig {
@@ -44,6 +67,9 @@ export class NightLampView {
night_lamp_hour_start: +this.night_lamp_time_start.value,
night_lamp_hour_end: +this.night_lamp_time_end.value,
night_lamp_only_when_dark: this.night_lamp_only_when_dark.checked,
enabled: this.night_lamp_enabled.checked,
low_soc_cutoff: +this.night_lamp_soc_low.value,
low_soc_restore: +this.night_lamp_soc_restore.value
}
}
}