From dd8e8bc7f29c4bb0b134b9af9e47d15a5f235572 Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:17:53 +0100 Subject: [PATCH 1/9] fix(installer): accept a typed IP address in media step 5 Without an own known_hosts entry the reachability check now expects the host key of the last written medium, so the right device no longer shows as a foreign one. A matching key is pinned under the address too, so setup connects without the fingerprint question. Co-Authored-By: Claude Opus 5.5 --- installer/internal/host/media.go | 41 +++++++++++- installer/internal/host/media_test.go | 89 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/installer/internal/host/media.go b/installer/internal/host/media.go index 7d68d53a..b797d6b2 100644 --- a/installer/internal/host/media.go +++ b/installer/internal/host/media.go @@ -14,6 +14,7 @@ import ( "unicode" "github.com/Developer-Simon/energy-node-installer/internal/media" + "github.com/Developer-Simon/energy-node-installer/internal/transport" "github.com/Developer-Simon/energy-node-webui/hostapi" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" @@ -38,6 +39,9 @@ var imagerEnv = media.Env{ }, } +// mediaProbe prueft einen Rechner per SSH. Tests ersetzen ihn. +var mediaProbe = media.Probe + // mediaSupported liefert MEDIA_UNSUPPORTED, wenn der Rechner keine Medien // vorbereiten kann oder kein Medienverzeichnis gesetzt ist. func (h *Host) mediaSupported() error { @@ -343,6 +347,8 @@ func (h *Host) MediaCancel(ctx context.Context) error { // MediaReachable prueft, ob der Node unter host antwortet. Der erwartete // Schluessel ist der, den der Installer fuer diesen Host in known_hosts gepinnt hat. +// Ohne eigenen Eintrag, etwa bei einer eingetippten IP-Adresse, gilt der +// Schluessel des zuletzt geschriebenen Mediums. func (h *Host) MediaReachable(ctx context.Context, host string) (hostapi.MediaReachability, error) { if err := h.mediaSupported(); err != nil { return hostapi.MediaReachability{}, err @@ -350,8 +356,39 @@ func (h *Host) MediaReachable(ctx context.Context, host string) (hostapi.MediaRe if host == "" || strings.ContainsRune(host, '/') || strings.ContainsFunc(host, unicode.IsSpace) { return hostapi.MediaReachability{}, apiError("BAD_REQUEST", http.StatusBadRequest, host) } - r := media.Probe(ctx, host, pinnedKey(h.cfg.KnownHostsPath, host)) - return hostapi.MediaReachability{Reachable: r.Reachable, KeyMatches: r.KeyMatches}, nil + target := "" + if w, err := h.writer(); err == nil { + if t := w.View().Target; t != nil { + target = t.Host + } + } + return h.mediaReachable(ctx, host, target), nil +} + +// mediaReachable prueft host gegen den erwarteten Schluessel. Passt ein vom +// Medium geliehener Schluessel, pinnt es ihn auch fuer host, damit Einrichten +// unter dieser Adresse ohne Fingerabdruck-Abfrage verbindet. +func (h *Host) mediaReachable(ctx context.Context, host, target string) hostapi.MediaReachability { + want, borrowed := expectedMediaKey(h.cfg.KnownHostsPath, host, target) + r := mediaProbe(ctx, host, want) + if r.KeyMatches && borrowed { + // Scheitert das Pinnen, fragt Einrichten wie sonst nach dem Fingerabdruck. + _ = transport.PinHostKey(h.cfg.KnownHostsPath, host, want) + } + return hostapi.MediaReachability{Reachable: r.Reachable, KeyMatches: r.KeyMatches} +} + +// expectedMediaKey liefert den Schluessel, den host zeigen muss. Hat host +// keinen eigenen Eintrag, gilt der des Mediums unter target, borrowed ist dann true. +func expectedMediaKey(path, host, target string) (ssh.PublicKey, bool) { + if key := pinnedKey(path, host); key != nil { + return key, false + } + if target == "" || knownhosts.Normalize(target) == knownhosts.Normalize(host) { + return nil, false + } + key := pinnedKey(path, target) + return key, key != nil } // pinnedKey liest den Schluessel, den known_hosts fuer host fuehrt. nil heisst: keiner. diff --git a/installer/internal/host/media_test.go b/installer/internal/host/media_test.go index 49911953..b0844336 100644 --- a/installer/internal/host/media_test.go +++ b/installer/internal/host/media_test.go @@ -23,6 +23,7 @@ import ( "github.com/Developer-Simon/energy-node-webui/hostapi" "github.com/ProtonMail/go-crypto/openpgp" "github.com/ProtonMail/go-crypto/openpgp/armor" + "golang.org/x/crypto/ssh" ) // newMediaHost baut einen Wirt mit Medienverzeichnis und Schluesselordner in tmp. @@ -474,3 +475,91 @@ func TestExecRunnerMergesOutputAndReportsTheExitCode(t *testing.T) { t.Errorf("output = %q, want stdout and stderr merged", got) } } + +func TestExpectedMediaKeyBorrowsTheKeyOfTheMedium(t *testing.T) { + path := filepath.Join(t.TempDir(), "known_hosts") + hk, err := media.NewHostKey() + if err != nil { + t.Fatal(err) + } + if err := transport.PinHostKey(path, "energy-node.local", hk.Public); err != nil { + t.Fatal(err) + } + + key, borrowed := expectedMediaKey(path, "energy-node.local", "energy-node.local") + if key == nil || borrowed { + t.Errorf("own entry: key %v, borrowed %v, want the key and false", key, borrowed) + } + + key, borrowed = expectedMediaKey(path, "192.0.2.10", "energy-node.local") + if key == nil || !bytes.Equal(key.Marshal(), hk.Public.Marshal()) || !borrowed { + t.Errorf("IP address: key %v, borrowed %v, want the medium key and true", key, borrowed) + } + + if key, borrowed = expectedMediaKey(path, "192.0.2.10", ""); key != nil || borrowed { + t.Errorf("no medium: key %v, borrowed %v, want nil and false", key, borrowed) + } +} + +// stubMediaProbe ersetzt die SSH-Pruefung. Der Rechner antwortet immer und zeigt key. +func stubMediaProbe(t *testing.T, key ssh.PublicKey) *ssh.PublicKey { + t.Helper() + var probed ssh.PublicKey + orig := mediaProbe + mediaProbe = func(_ context.Context, _ string, want ssh.PublicKey) media.Reachability { + probed = want + return media.Reachability{Reachable: true, KeyMatches: want != nil && bytes.Equal(want.Marshal(), key.Marshal())} + } + t.Cleanup(func() { mediaProbe = orig }) + return &probed +} + +func TestMediaReachablePinsTheMediumKeyForAnIPAddress(t *testing.T) { + h := newMediaHost(t, t.TempDir()) + hk, err := media.NewHostKey() + if err != nil { + t.Fatal(err) + } + if err := transport.PinHostKey(h.cfg.KnownHostsPath, "energy-node.local", hk.Public); err != nil { + t.Fatal(err) + } + probed := stubMediaProbe(t, hk.Public) + + got := h.mediaReachable(context.Background(), "192.0.2.10", "energy-node.local") + if !got.Reachable || !got.KeyMatches { + t.Fatalf("mediaReachable = %+v, want reachable with matching key", got) + } + if *probed == nil || !bytes.Equal((*probed).Marshal(), hk.Public.Marshal()) { + t.Errorf("probe got %v, want the medium key", *probed) + } + if key := pinnedKey(h.cfg.KnownHostsPath, "192.0.2.10"); key == nil || !bytes.Equal(key.Marshal(), hk.Public.Marshal()) { + t.Errorf("pinnedKey(192.0.2.10) = %v, want the medium key", key) + } + if key := pinnedKey(h.cfg.KnownHostsPath, "energy-node.local"); key == nil { + t.Error("the pin for energy-node.local is gone") + } +} + +func TestMediaReachableDoesNotPinAForeignDevice(t *testing.T) { + h := newMediaHost(t, t.TempDir()) + hk, err := media.NewHostKey() + if err != nil { + t.Fatal(err) + } + other, err := media.NewHostKey() + if err != nil { + t.Fatal(err) + } + if err := transport.PinHostKey(h.cfg.KnownHostsPath, "energy-node.local", hk.Public); err != nil { + t.Fatal(err) + } + stubMediaProbe(t, other.Public) + + got := h.mediaReachable(context.Background(), "192.0.2.10", "energy-node.local") + if !got.Reachable || got.KeyMatches { + t.Fatalf("mediaReachable = %+v, want reachable with a foreign key", got) + } + if key := pinnedKey(h.cfg.KnownHostsPath, "192.0.2.10"); key != nil { + t.Errorf("pinnedKey(192.0.2.10) = %v, want no pin for a foreign device", key) + } +} From fc6cfdad5c5d8f24c0b74b0e73339f5ec4815c86 Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:18:23 +0100 Subject: [PATCH 2/9] docs(installer): the Debian stick builds on all three systems The Debian section still said the stick needs Linux, although the media mode now builds it on Windows and macOS too. Step 5 also says that a typed IP address is checked against the same host key. Co-Authored-By: Claude Opus 5.5 --- docs/installer.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/installer.md b/docs/installer.md index 1946295b..f597b3a0 100644 --- a/docs/installer.md +++ b/docs/installer.md @@ -163,8 +163,8 @@ and for 64-bit ARM computers with UEFI, the installer builds a USB stick that installs Debian 13 on the device by itself. Pick the **Generic** entries in the device list. The installer downloads the Debian 13 netinst image for the architecture, checks the signature of its checksum file and then builds the -stick from the image on this computer. Like the Pi card, the stick needs Linux -for now. 32-bit x86 (i386) is not supported. +stick from the image on this computer. Like the Pi card, the stick can be built +on Linux, Windows and macOS. 32-bit x86 (i386) is not supported. 1. **Settings.** Choose a device name and a user, as for the Pi. The emergency password for a screen and keyboard is on by default here, and you can @@ -196,7 +196,8 @@ for now. 32-bit x86 (i386) is not supported. key the installer created, **Continue to setup** becomes active. If the device does not answer after 30 minutes, the page lists the usual causes: no network connection, mDNS blocked on the network, the wrong boot drive, or - no DHCP on the cable. You can also enter the device's IP address there. + no DHCP on the cable. You can also enter the device's IP address there. The + installer checks the device at that address against the same host key. The installer chooses the target disk by its size: From 50b5e84c52195039392d6838dd35ea0325d4d7ea Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:26:42 +0100 Subject: [PATCH 3/9] fix(monitoring): add the text for the learning settings button Co-Authored-By: Claude Opus 5.5 --- dashboard/internal/webui/catalogs/de.json | 3 ++- dashboard/internal/webui/catalogs/en.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dashboard/internal/webui/catalogs/de.json b/dashboard/internal/webui/catalogs/de.json index fc8e3481..a48f1f63 100644 --- a/dashboard/internal/webui/catalogs/de.json +++ b/dashboard/internal/webui/catalogs/de.json @@ -3856,7 +3856,8 @@ "monitoring.forecast.verdict.median": "Prognose {forecast} daneben, Median {median}. Der Median war näher.", "monitoring.group.known": "Zur Kenntnis genommen", "monitoring.group.new": "Neu", - "monitoring.learned.off": "Muster lernen ist aus. Einschalten unter Einstellungen, Lernfunktionen.", + "monitoring.learned.off": "Muster lernen ist aus. Es kommen keine neuen Lernwerte dazu.", + "monitoring.learned.off_open": "Lernfunktionen öffnen", "monitoring.learned.short.pv_reserve_w": "PV-Reserve", "monitoring.learned.short.surplus_left_wh": "Rest-Überschuss heute", "monitoring.learned.site": "Anlage", diff --git a/dashboard/internal/webui/catalogs/en.json b/dashboard/internal/webui/catalogs/en.json index a1561a1e..021b298f 100644 --- a/dashboard/internal/webui/catalogs/en.json +++ b/dashboard/internal/webui/catalogs/en.json @@ -3856,7 +3856,8 @@ "monitoring.forecast.verdict.median": "Forecast off by {forecast}, median by {median}. The median was closer.", "monitoring.group.known": "Acknowledged", "monitoring.group.new": "New", - "monitoring.learned.off": "Pattern learning is off. Turn it on under settings, learning.", + "monitoring.learned.off": "Pattern learning is off. No new learned values are added.", + "monitoring.learned.off_open": "Open learning features", "monitoring.learned.short.pv_reserve_w": "PV reserve", "monitoring.learned.short.surplus_left_wh": "Remaining surplus today", "monitoring.learned.site": "System", From 9462d1f9785ac3dc3ff8c3f362ec9b42f6e6d45a Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:27:07 +0100 Subject: [PATCH 4/9] fix(monitoring): name the values of the role notice Co-Authored-By: Claude Opus 5.5 --- dashboard/internal/monitoring/notice.go | 28 +++++++++++++++++++- dashboard/internal/monitoring/notice_test.go | 24 +++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/dashboard/internal/monitoring/notice.go b/dashboard/internal/monitoring/notice.go index 832e8d55..79f420f6 100644 --- a/dashboard/internal/monitoring/notice.go +++ b/dashboard/internal/monitoring/notice.go @@ -140,12 +140,13 @@ func energyNotices(in Input) []Notice { if len(in.Config.RoleNeeded) > 0 { ids := append([]string{}, in.Config.RoleNeeded...) sort.Strings(ids) + labels := roleNeededLabels(snap, ids) out = append(out, Notice{ ID: "energy:role_needed", Source: "energy", Severity: "info", Code: "role_needed", - Params: map[string]any{"ids": ids}, + Params: map[string]any{"ids": ids, "labels": labels}, Steps: []Step{ {Code: "set_role", Target: "energy.focus", IDs: ids}, {Code: "role_keep", Target: "action.role_keep", IDs: ids}, @@ -156,6 +157,31 @@ func energyNotices(in Input) []Notice { return out } +// roleNeededLabels names the values in ids in the same order: the label of the +// resolved entity, else the name of the unassigned value, else the entity ID. +func roleNeededLabels(snap energy.Snapshot, ids []string) []string { + names := map[string]string{} + for _, e := range snap.Unassigned { + if e.Name != "" { + names[e.EntityID] = e.Name + } + } + for _, e := range snap.Entities { + if e.Label != "" { + names[e.EntityID] = e.Label + } + } + labels := make([]string, 0, len(ids)) + for _, id := range ids { + if name := names[id]; name != "" { + labels = append(labels, name) + } else { + labels = append(labels, id) + } + } + return labels +} + func chainNotices(snap energy.Snapshot) []Notice { var out []Notice for _, chain := range snap.Chains { diff --git a/dashboard/internal/monitoring/notice_test.go b/dashboard/internal/monitoring/notice_test.go index 90ef58f4..a7b28c4d 100644 --- a/dashboard/internal/monitoring/notice_test.go +++ b/dashboard/internal/monitoring/notice_test.go @@ -49,6 +49,30 @@ func TestCollectEnergyNotices(t *testing.T) { } } +func TestRoleNeededLabels(t *testing.T) { + in := Input{ + Snapshot: energy.Snapshot{ + Entities: []energy.ResolvedEntity{{EntityID: "x", Label: "Speicher Leistung"}}, + Unassigned: []energy.UnassignedEntity{{EntityID: "y", Name: "Zähler"}}, + }, + Config: settings.EnergyConfig{RoleNeeded: []string{"z", "y", "x"}}, + } + var rn *Notice + got := Collect(in) + for i := range got { + if got[i].ID == "energy:role_needed" { + rn = &got[i] + } + } + if rn == nil { + t.Fatal("no role_needed notice") + } + want := []string{"Speicher Leistung", "Zähler", "z"} + if !reflect.DeepEqual(rn.Params["labels"], want) { + t.Errorf("labels = %v, want %v", rn.Params["labels"], want) + } +} + func TestCollectMeasuredWithLoadRoleIsQuiet(t *testing.T) { in := Input{Config: settings.EnergyConfig{ Interpretation: energy.Interpretation{LoadMode: energy.LoadModeMeasured}, From a07ed438fad6a55002fafd2176f4e3f6def5ef2c Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:27:55 +0100 Subject: [PATCH 5/9] fix(monitoring): open the learning settings from the learned values Co-Authored-By: Claude Opus 5.5 --- dashboard/internal/webui/static/js/monitoring-model.js | 3 +++ dashboard/internal/webui/static/js/monitoring.page.js | 8 ++++++++ dashboard/internal/webui/static/js/settings.page.js | 9 +++++++++ dashboard/internal/webui/templates/monitoring.html | 2 +- dashboard/test/monitoring-model.test.mjs | 5 +++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dashboard/internal/webui/static/js/monitoring-model.js b/dashboard/internal/webui/static/js/monitoring-model.js index 46f1b61a..40be7ced 100644 --- a/dashboard/internal/webui/static/js/monitoring-model.js +++ b/dashboard/internal/webui/static/js/monitoring-model.js @@ -159,6 +159,9 @@ if ((p.more || 0) > 0) rows.push(['', t('monitoring.fact.more', { n: p.more })]); return rows; } + if (notice.code === 'role_needed') { + return (p.labels || []).map((label) => [t('monitoring.fact.value'), label]); + } if (sourceOf(notice) === 'learn' && p.kind === 'shade') return shadeFacts(notice, p, t); if (sourceOf(notice) === 'effect') { const confidence = p.confidence === 'high' ? t('automations.learn.confidence.sure') : t('automations.learn.confidence.estimate'); diff --git a/dashboard/internal/webui/static/js/monitoring.page.js b/dashboard/internal/webui/static/js/monitoring.page.js index 924273f5..05feb954 100644 --- a/dashboard/internal/webui/static/js/monitoring.page.js +++ b/dashboard/internal/webui/static/js/monitoring.page.js @@ -287,6 +287,14 @@ openTab('automations-panel'); }, + // Öffnet in den Einstellungen die Seite Lernfunktionen (general). Ist die + // Einstellungsseite noch nicht geladen, nimmt sie die Anfrage in init(). + goLearningSettings() { + window.__settingsPageRequest__ = 'general'; + window.dispatchEvent(new CustomEvent('settings-page-open', { detail: { page: 'general' } })); + openTab('settings-panel'); + }, + titleOf(notice) { return window.MonitoringModel.title(notice, t); }, rowMeta(notice) { return [this.sourceLabel(notice.source), window.MonitoringModel.sinceText(notice.first_seen, nowSeconds(), t)].join(' · '); diff --git a/dashboard/internal/webui/static/js/settings.page.js b/dashboard/internal/webui/static/js/settings.page.js index 657e2d6c..481d9de9 100644 --- a/dashboard/internal/webui/static/js/settings.page.js +++ b/dashboard/internal/webui/static/js/settings.page.js @@ -832,6 +832,15 @@ init() { const requested = new URLSearchParams(window.location.search).get('page'); if (SETTINGS_PAGES.includes(requested)) this.activeSettingsPage = requested; + // Ein Sprung von einer anderen Seite, etwa vom Monitoring zu den Lernfunktionen. + const pending = window.__settingsPageRequest__; + delete window.__settingsPageRequest__; + if (SETTINGS_PAGES.includes(pending)) this.activeSettingsPage = pending; + window.addEventListener('settings-page-open', (event) => { + delete window.__settingsPageRequest__; + const page = event.detail && event.detail.page; + if (SETTINGS_PAGES.includes(page)) this.choosePage(page); + }); this.$watch('activeSettingsPage', (page) => this.ensureSubpage(page).catch(() => {})); this.ensureSubpage(this.activeSettingsPage).catch(() => {}); this.$nextTick(() => { diff --git a/dashboard/internal/webui/templates/monitoring.html b/dashboard/internal/webui/templates/monitoring.html index 37d771a7..02a8c349 100644 --- a/dashboard/internal/webui/templates/monitoring.html +++ b/dashboard/internal/webui/templates/monitoring.html @@ -75,7 +75,7 @@