cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.400: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-10-30 08:26:45 +02:00
1 parent 343331d234
commit d5fbcacaa4
176 files changed
+32511 -19

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
// Copyright © 2026 Setti Solutions S.R.L, www.setti.md. All rights reserved.
package main
import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
func TestPage(t *testing.T) {
h := newHarness(t, Options{})
cb, hp, _ := h.home()
h.core.Seen("ff00aa", "Bosch", "Compress 6800i AW", "HeatGenerationSystem", "")
h.core.PairingRequest("ff00aa")
p := &Page{core: h.core, peers: []string{"172.30.32.2"}, ha: true}
get := func(peer, lang string) *httptest.ResponseRecorder {
r := httptest.NewRequest("GET", "/", nil)
r.RemoteAddr = peer + ":5555"
r.Header.Set("Accept-Language", lang)
w := httptest.NewRecorder()
p.ServeHTTP(w, r)
return w
}
if w := get("192.0.2.9", "en"); w.Code != http.StatusForbidden {
t.Fatalf("anyone but the ingress proxy: %d", w.Code)
}
en := get("172.30.32.2", "en-GB,en;q=0.9").Body.String()
for _, want := range []string{`id="` + hp.ID + `"`, `id="` + cb.ID + `"`, "Found on the network", "asks to be paired", "ff00aa",
"sealed", "Grid operator's limit", "protected", `src="page.js"`} {
if !strings.Contains(en, want) {
t.Fatalf("page lacks %q", want)
}
}
// a sealed control box has no unpair button and no controls to set
sec := en[strings.Index(en, `id="`+cb.ID+`"`):]
sec = sec[:strings.Index(sec, "</section>")]
if strings.Contains(sec, `value="unpair"`) {
t.Fatal("unpair offered for a sealed control box")
}
de := get("172.30.32.2", "de-DE,de").Body.String()
if !strings.Contains(de, "Gekoppelte Geräte") || !strings.Contains(de, "Im Netz gefunden") {
t.Fatal("German")
}
// pairing from the page, by the HA user named in ingress's headers
form := url.Values{"action": {"pair"}, "ski": {"ff00aa"}}
r := httptest.NewRequest("POST", "/", strings.NewReader(form.Encode()))
r.RemoteAddr = "172.30.32.2:1"
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
r.Header.Set("X-Remote-User-Display-Name", "Dana")
r.Header.Set("X-Ingress-Path", "/api/hassio_ingress/abc")
w := httptest.NewRecorder()
p.ServeHTTP(w, r)
if w.Code != http.StatusSeeOther || w.Header().Get("Location") != "/api/hassio_ingress/abc/" {
t.Fatalf("redirect %d %q", w.Code, w.Header().Get("Location"))
}
if d := h.core.devices["ff00aa"]; !d.Paired || d.Profile != "eebus-bosch-compress" || !strings.Contains(d.PairedBy, "Dana") {
t.Fatalf("paired from the page: %+v", d)
}
// page.js for the panel's frame (its own scripts only)
r = httptest.NewRequest("GET", "/page.js", nil)
r.RemoteAddr = "172.30.32.2:1"
w = httptest.NewRecorder()
p.ServeHTTP(w, r)
if !strings.Contains(w.Body.String(), "location.hash") {
t.Fatal("page.js")
}
}
// The page's catalogues: every text in English and German, none empty, the
// same placeholders; the catalogue's value names in German too.
func TestPageTextsBothLanguages(t *testing.T) {
for k, en := range texts["en"] {
de, ok := texts["de"][k]
if !ok || de == "" || en == "" {
t.Errorf("text %q: en %q, de %q", k, en, de)
}
if strings.Count(en, "{}") != strings.Count(de, "{}") {
t.Errorf("text %q: placeholders differ", k)
}
}
for k := range texts["de"] {
if _, ok := texts["en"][k]; !ok {
t.Errorf("text %q only in German", k)
}
}
for _, s := range Catalogue {
if s.Name == "" || s.NameDE == "" {
t.Errorf("value %s: name %q, German %q", s.Key, s.Name, s.NameDE)
}
}
}