controllerapi

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 30 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 New

func New(opts Options) (*Server, error)

New returns a server; it loads the settings under opts.StoragePath.

func (*Server) Capabilities

func (s *Server) Capabilities() []string

Capabilities are the commands this server answers, sorted — the capabilities list of server_info (concept v8 C.1, our extension).

func (*Server) FabricLabel

func (s *Server) FabricLabel() string

FabricLabel is the effective fabric label: the pinned one, else the stored one.

func (*Server) Health

func (s *Server) Health() (healthy bool, nodes int)

Health is the controller half's state for GET /health: healthy once started and until shut down.

func (*Server) Hooks

func (s *Server) Hooks(id string) client.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) NodeCount

func (s *Server) NodeCount() int

NodeCount is the number of commissioned nodes the server knows.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves one WebSocket connection of the controller half.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown sends server_shutdown to every connection, waits until it is written (or ctx ends) and closes them; then the server stops following the controller. The controller itself is the caller's to close.

func (*Server) Start

func (s *Server) Start(_ context.Context, b Backend) error

Start binds the server to its controller: the node cache is built from the registry's nodes (no events for them), and changes are followed from then on.

type VendorSource added in v0.2.0

type VendorSource func(ctx context.Context) (map[uint16]string, error)

VendorSource lists the vendor names by vendor id — the DCL's vendor records (dcl.Client.Vendors) unless Options.Vendors sets another.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL