cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.629: full source
This commit is contained in:
1 parent
d5fbcacaa4
commit
85edd56ec8
46 files changed
+3518
-267
No files matched your search
+33
-2
@@ -30,6 +30,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"math"
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
@@ -755,11 +756,41 @@ func (l *link) heartbeat() map[string]any {
|
||||
if p := l.pathInfo(); p != nil {
|
||||
hb["path"] = p
|
||||
}
|
||||
hb["consents"] = consents(env("CANTABILE_CONSENT_FILE",
|
||||
c := consents(env("CANTABILE_CONSENT_FILE",
|
||||
map[bool]string{true: "/data/cantabile/edge/consent.json", false: "/data/state/consent.json"}[isHub()]))
|
||||
hb["consents"] = c
|
||||
// the site's weather cell (0.1°), for the cloud's weather: only with
|
||||
// the owner's share consent
|
||||
if c["share"] == true {
|
||||
if cell := siteCell(filepath.Join(l.cfg.AgentState, "site_cell.json")); cell != nil {
|
||||
hb["cell"] = cell
|
||||
}
|
||||
// the Hub's country and postcode (the panel's Location; tariffs,
|
||||
// Mieterstrom and energy sharing go by them): with the same consent
|
||||
if isHub() {
|
||||
if loc := boxLocation(boxConfig); loc != nil {
|
||||
hb["location"] = loc
|
||||
}
|
||||
}
|
||||
}
|
||||
return hb
|
||||
}
|
||||
|
||||
// siteCell: [lat, lon] rounded to 0.1° from the agent's site_cell.json
|
||||
// (written from HA's configuration), or nil (none, malformed, out of range).
|
||||
func siteCell(path string) []float64 {
|
||||
var c struct{ Lat, Lon *float64 }
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil || json.Unmarshal(b, &c) != nil || c.Lat == nil || c.Lon == nil {
|
||||
return nil
|
||||
}
|
||||
lat, lon := math.Round(*c.Lat*10)/10, math.Round(*c.Lon*10)/10
|
||||
if math.Abs(lat) > 90 || math.Abs(lon) > 180 {
|
||||
return nil
|
||||
}
|
||||
return []float64{lat, lon}
|
||||
}
|
||||
|
||||
// consents: the owner's consents as fleet keeps them (per
|
||||
// recipient; nothing goes to a recipient without its yes): share (with
|
||||
// Cantabile), control, and the recipients granted (building, grid,
|
||||
@@ -900,7 +931,7 @@ func (l *link) do(c command) (bool, string, func()) {
|
||||
case "refresh":
|
||||
l.publish("hb", l.heartbeat())
|
||||
return true, "heartbeat sent", nil
|
||||
case "tariff", "model", "flats", "acl": // data bundles: checked here, read by the agent (bundles.go; flats: a building's box; acl: the devices' protection)
|
||||
case "tariff", "model", "flats", "acl", "market": // data bundles: checked here, read by the agent (bundles.go; flats: a building's box; acl: the devices' protection; market: the shadow market's values)
|
||||
ok, msg := l.bundleCmd(c, time.Now())
|
||||
if ok && c.Cmd == "acl" && isHub() {
|
||||
devicesPolicy() // the policy in force for add-ons and the Modbus bridge (/usr/lib/cantabile/devices)
|
||||
|
||||
Reference in new issue
Block a user