add ui, new config opts

This commit is contained in:
2026-07-16 16:32:44 -04:00
parent 8effff311b
commit df01e060e4
33 changed files with 1104 additions and 37 deletions
+13
View File
@@ -27,5 +27,18 @@ func deviceToProto(d *econetclient.Device) *pb.Device {
AlertCount: int32(d.AlertCount),
Away: d.Away,
LastUpdated: timestamppb.New(d.LastUpdated),
SupportedModes: supportedModes(d.SupportedModes()),
}
}
// supportedModes maps the device's mode slugs to proto enums, dropping any that
// aren't settable (e.g. "unknown").
func supportedModes(slugs []string) []pb.Mode {
out := make([]pb.Mode, 0, len(slugs))
for _, slug := range slugs {
if m, ok := modeFromSlug(slug); ok {
out = append(out, m)
}
}
return out
}
+26
View File
@@ -71,6 +71,17 @@ func (s *EconetGRPCServer) GetDevice(ctx context.Context, req *pb.GetDeviceReque
return &pb.GetDeviceResponse{Device: deviceToProto(d)}, nil
}
// DeviceRawJSON returns the undecoded EcoNet equipment payload for a device,
// used by the web UI's debug view. ok is false if the serial is unknown or no
// raw payload was captured. It is a debug accessor, not part of the RPC surface.
func (s *EconetGRPCServer) DeviceRawJSON(serial string) ([]byte, bool) {
d := s.client.Device(serial)
if d == nil || len(d.Raw) == 0 {
return nil, false
}
return d.Raw, true
}
// modeSlugs maps the settable proto Mode enum to the normalized slugs the
// client (and Device.mode) use. MODE_UNSPECIFIED is intentionally absent;
// protovalidate rejects it before we get here.
@@ -83,6 +94,21 @@ var modeSlugs = map[pb.Mode]string{
pb.Mode_MODE_GAS: "gas",
pb.Mode_MODE_PERFORMANCE: "performance",
pb.Mode_MODE_VACATION: "vacation",
pb.Mode_MODE_ELECTRIC_GAS: "electric-gas",
}
// ModeSlug returns the normalized slug for a settable Mode, or "" if unknown.
func ModeSlug(m pb.Mode) string { return modeSlugs[m] }
// modeFromSlug is the reverse of modeSlugs; ok is false for slugs with no
// settable enum (e.g. "unknown").
func modeFromSlug(slug string) (pb.Mode, bool) {
for m, s := range modeSlugs {
if s == slug {
return m, true
}
}
return pb.Mode_MODE_UNSPECIFIED, false
}
func (s *EconetGRPCServer) SetMode(ctx context.Context, req *pb.SetModeRequest) (