Documentation
¶
Overview ¶
Package controllerapi is the controller half of go-fabric-server: the WebSocket API at /ws, wire-compatible with matterjs-server's (schema 14, the python-matter-server contract Home Assistant's Matter integration speaks), over go-fabric's controller facade.
The shapes are the read map's (notes/reads/read-v8-matterjs-server.md, matterjs-server a7922e85): the dispatch table (§1.7), the arguments (§1.8), the results (§1.9), the node data (§2), the events (§1.5-1.6) and the connection model (§3.3-3.7) — server_info on connect, events only after start_listening has answered, the backpressure send path of protocol.Conn.
Lifecycle: New → wire Server.Hooks into the controller's node configuration → build the controller → Server.Start → serve Server.ServeHTTP at /ws → Server.Shutdown. The hooks come before the controller because the controller starts its nodes while it is built.
Index ¶
- type Backend
- type Discoverer
- type Options
- type Server
- func (s *Server) Capabilities() []string
- func (s *Server) FabricLabel() string
- func (s *Server) Health() (healthy bool, nodes int)
- func (s *Server) Hooks(id string) client.Hooks
- func (s *Server) NodeCount() int
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Shutdown(ctx context.Context)
- func (s *Server) Start(_ context.Context, b Backend) error
- type VendorSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Registry is the registry of the paired nodes.
Registry() *client.Registry
// Fabric is our fabric.
Fabric() *commissioner.Fabric
// Pair commissions the device a QR or manual pairing code names.
Pair(ctx context.Context, code string, opts controller.PairOptions) (*client.Node, error)
}
Backend is the controller the API drives — go-fabric's *controller.Controller satisfies it. Everything the API does goes through these three routes and the client nodes they hand out.
type Discoverer ¶
type Discoverer interface {
Discover(ctx context.Context, id discovery.Identifier, timeout time.Duration) ([]client.Device, error)
}
Discoverer is the optional route of discover_commissionable_nodes and commission_on_network: find the commissionable devices id selects within timeout. go-fabric's controller facade has no such method yet (report S1, Questions Q3); fabrictest.Controller has it, so the in-process tests exercise the commands. A backend without it answers both commands with InvalidCommand.
type Options ¶
type Options struct {
// Version is go-fabric-server's version, for server_info's sdk_version.
Version string
// GoFabricVersion is the go-fabric module version, for sdk_version.
GoFabricVersion string
// StoragePath is the directory of the server's own settings
// (server.json: credentials, the fabric label); "" keeps them in
// memory.
StoragePath string
// DisableAutoSubscription is matterjs-server's
// --disable-auto-subscription: new nodes are paired without the
// server's own subscription, and subscribe/unsubscribe are available.
DisableAutoSubscription bool
// DefaultFabricLabel pins the fabric label; set_default_fabric_label
// then succeeds without effect (--default-fabric-label).
DefaultFabricLabel string
// PairTimeout bounds a commissioning; 0 is 5 minutes.
PairTimeout time.Duration
// Logger receives the server's logs; nil discards them.
Logger *slog.Logger
// LogLevel is the level get_loglevel reports and set_loglevel changes;
// nil is a fixed info.
LogLevel *slog.LevelVar
// Metrics receives the send path's metrics.
Metrics protocol.Metrics
// Conn overrides the backpressure defaults of each connection (tests).
Conn protocol.ConnOptions
// MaxInFlight bounds the requests a connection runs at once; 0 is 64.
MaxInFlight int
// Vendors lists the vendor names of get_vendor_names; nil is the
// production DCL's vendor records.
Vendors VendorSource
}
Options configures a Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the controller half. Its methods are safe for concurrent use.
func (*Server) Capabilities ¶
Capabilities are the commands this server answers, sorted — the capabilities list of server_info (concept v8 C.1, our extension).
func (*Server) FabricLabel ¶
FabricLabel is the effective fabric label: the pinned one, else the stored one.
func (*Server) Health ¶
Health is the controller half's state for GET /health: healthy once started and until shut down.
func (*Server) Hooks ¶
Hooks are the client node hooks the server needs for the node with the registry's local id: wire them as client.RegistryConfig.HooksFor. An empty id is hooks that cannot tell the nodes apart — what controller.Config.Node.Hooks takes today (report S1, Questions Q2): a change then refreshes every node, and node events, which only the hook's node could name, are not forwarded.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves one WebSocket connection of the controller half.
type VendorSource ¶ added in v0.2.0
VendorSource lists the vendor names by vendor id — the DCL's vendor records (dcl.Client.Vendors) unless Options.Vendors sets another.