cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.629: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-03 23:26:41 +02:00
1 parent d5fbcacaa4
commit 85edd56ec8
46 files changed
+3518 -267

No files matched your search

+34
View File
@@ -253,3 +253,37 @@ func TestConsentsCarrySourceAndVersion(t *testing.T) {
t.Fatalf("no file: %v", c)
}
}
// The site's weather cell (the agent's site_cell.json) goes into the
// heartbeat only with the share consent, rounded to 0.1°, on a Hub too;
// a missing or bad file: no cell.
func TestHeartbeatCell(t *testing.T) {
for _, hub := range []string{"0", "1"} {
t.Setenv("CANTABILE_HUB", hub)
dir := t.TempDir()
cons := filepath.Join(dir, "consent.json")
t.Setenv("CANTABILE_CONSENT_FILE", cons)
l := &link{cfg: config{AgentState: dir}, loc: &local{}}
cell := filepath.Join(dir, "site_cell.json")
os.WriteFile(cell, []byte(`{"lat": 47.0234, "lon": 28.86}`), 0o644)
os.WriteFile(cons, []byte(`{"share": true}`), 0o600)
if c, ok := l.heartbeat()["cell"].([]float64); !ok || len(c) != 2 || c[0] != 47.0 || c[1] != 28.9 {
t.Fatalf("hub %s, shared: %v", hub, l.heartbeat()["cell"])
}
os.WriteFile(cons, []byte(`{"share": false, "control": true}`), 0o600)
if c, ok := l.heartbeat()["cell"]; ok {
t.Fatalf("hub %s, not shared: %v", hub, c)
}
os.WriteFile(cons, []byte(`{"share": true}`), 0o600)
for _, bad := range []string{`not json`, `{"lat": 47.0}`, `{"lat": 95, "lon": 28}`, `{"lat": 47, "lon": -181}`, `{"lat": "47", "lon": 28}`} {
os.WriteFile(cell, []byte(bad), 0o644)
if c, ok := l.heartbeat()["cell"]; ok {
t.Fatalf("hub %s, %s: %v", hub, bad, c)
}
}
os.Remove(cell)
if c, ok := l.heartbeat()["cell"]; ok {
t.Fatalf("hub %s, no file: %v", hub, c)
}
}
}