client

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 14 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 client is a Go client of both halves of go-fabric-server. Dial connects to the controller half (/ws), reads server_info and, unless told otherwise, sends start_listening; the typed methods send its commands. DialBridge connects to the bridge half (/bridge) the same way; Bridge has the host's commands. Events arrive on Client.Events. The tests of this repository use it; a Go program that wants Matter embeds go-fabric instead.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("client: connection closed")

ErrClosed is a call on a connection that ended.

Functions

This section is empty.

Types

type Bridge added in v0.2.0

type Bridge struct {
	*Client
	// contains filtered or unexported fields
}

Bridge is a connection to the bridge half (/bridge).

func DialBridge added in v0.2.0

func DialBridge(ctx context.Context, url string, opts Options) (*Bridge, error)

DialBridge connects to the bridge half: url is "ws://host:port/bridge" or "unix:/path". Unless opts.NoListen, it sends start_listening, whose answer is Bridge.Devices. A second client while one is connected gets the server's refusal as a *protocol.Error.

func (*Bridge) Declare added in v0.2.0

func (b *Bridge) Declare(ctx context.Context, doc any) (DeclareResult, error)

Declare sends the declaration document (an object with "devices").

func (*Bridge) Devices added in v0.2.0

func (b *Bridge) Devices() []BridgedDevice

Devices is the start_listening dump.

func (*Bridge) Forget added in v0.3.2

func (b *Bridge) Forget(ctx context.Context, device string) error

Forget removes a device if it is still declared and frees its endpoint number: a later Declare of the key gets a fresh one.

func (*Bridge) Host added in v0.2.0

func (b *Bridge) Host(ctx context.Context, st HostStatement) error

Host sends the host command.

func (*Bridge) Info added in v0.2.0

func (b *Bridge) Info() BridgeInfo

Info is the server_info the bridge half sent on connect.

func (*Bridge) NodeInfo added in v0.2.0

func (b *Bridge) NodeInfo(ctx context.Context) (map[string]any, error)

NodeInfo is node_info's answer.

func (*Bridge) PairingCodes added in v0.2.0

func (b *Bridge) PairingCodes(ctx context.Context) (qr, manual string, err error)

PairingCodes are the node's QR payload and manual code.

func (*Bridge) Remove added in v0.2.0

func (b *Bridge) Remove(ctx context.Context, device string) error

Remove removes a device; its endpoint number stays stored under its key, so a later Declare of the key gets it back.

func (*Bridge) Result added in v0.2.0

func (b *Bridge) Result(ctx context.Context, correlation uint64, response any, err *ResultError) error

Result answers a write or command event: nil err accepts (with the command's response, when it has one).

func (*Bridge) Set added in v0.2.0

func (b *Bridge) Set(ctx context.Context, device, cluster string, patch any) error

Set sends a patch of one cluster of a device.

type BridgeEvent added in v0.2.0

type BridgeEvent struct {
	Correlation uint64          `json:"correlation"`
	Device      string          `json:"device"`
	Endpoint    *uint16         `json:"endpoint"`
	Cluster     string          `json:"cluster"`
	Command     string          `json:"command"`
	Attribute   string          `json:"attribute"`
	Fields      json.RawMessage `json:"fields"`
	Value       json.RawMessage `json:"value"`
	Deadline    string          `json:"deadline"`
	TimeoutMS   int64           `json:"timeout_ms"`
	State       map[string]any  `json:"state"`
	Attributes  []string        `json:"attributes"`
	Origin      string          `json:"origin"`
}

BridgeEvent is a write or command event (Command or Attribute set), a changed event (Cluster, State, Attributes, Origin) or a result_timeout.

type BridgeInfo added in v0.2.0

type BridgeInfo struct {
	BridgeSchemaVersion int      `json:"bridge_schema_version"`
	SDKVersion          string   `json:"sdk_version"`
	Capabilities        []string `json:"capabilities"`
	// Node is the key of the device node this connection feeds
	// ("default" for the daemon's --bridge-* node).
	Node string `json:"node"`
}

BridgeInfo is the bridge half's server_info.

type BridgedDevice added in v0.2.0

type BridgedDevice struct {
	Key       string                    `json:"key"`
	Type      string                    `json:"type"`
	Endpoint  *uint16                   `json:"endpoint"`
	Reachable bool                      `json:"reachable"`
	Clusters  map[string]map[string]any `json:"clusters"`
}

BridgedDevice is a device of start_listening's dump.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is one connection. Its methods are safe for concurrent use.

func Dial

func Dial(ctx context.Context, url string, opts Options) (*Client, error)

Dial connects to url ("ws://host:port/ws", or "unix:/path" for the server's Unix socket).

func (*Client) Call

func (c *Client) Call(ctx context.Context, command string, args, result any) error

Call sends command with args (nil for none) and decodes the result into result (nil to discard). A failure the server answered is a *protocol.Error.

func (*Client) CallRaw

func (c *Client) CallRaw(ctx context.Context, command string, args any) (json.RawMessage, error)

CallRaw is Client.Call returning the raw result.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) CommissionOnNetwork

func (c *Client) CommissionOnNetwork(ctx context.Context, pin uint32, filterType int, filter uint64, ip string) (Node, error)

CommissionOnNetwork is commission_on_network; filterType 0 is no filter.

func (*Client) CommissionWithCode

func (c *Client) CommissionWithCode(ctx context.Context, code string, networkOnly bool) (Node, error)

CommissionWithCode is commission_with_code.

func (*Client) DeviceCommand

func (c *Client) DeviceCommand(ctx context.Context, nodeID uint64, endpoint uint16, cluster uint32, command string, payload any) (json.RawMessage, error)

DeviceCommand is device_command; the result is the response payload, null for a command answered with a status.

func (*Client) Diagnostics

func (c *Client) Diagnostics(ctx context.Context) (map[string]json.RawMessage, error)

Diagnostics is diagnostics.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context) ([]map[string]any, error)

Discover is discover_commissionable_nodes.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done is closed when the connection ended.

func (*Client) Dropped

func (c *Client) Dropped() uint64

Dropped is the number of events dropped because Events was full.

func (*Client) Events

func (c *Client) Events() <-chan Event

Events are the server's pushes, in arrival order.

func (*Client) GetAllCredentials

func (c *Client) GetAllCredentials(ctx context.Context) (map[string]any, error)

GetAllCredentials is get_all_credentials.

func (*Client) GetFabricLabel

func (c *Client) GetFabricLabel(ctx context.Context) (string, error)

GetFabricLabel is get_fabric_label.

func (*Client) GetLogLevel

func (c *Client) GetLogLevel(ctx context.Context) (LogLevels, error)

GetLogLevel is get_loglevel.

func (*Client) GetMatterFabrics

func (c *Client) GetMatterFabrics(ctx context.Context, nodeID uint64) ([]map[string]any, error)

GetMatterFabrics is get_matter_fabrics.

func (*Client) GetNode

func (c *Client) GetNode(ctx context.Context, nodeID uint64) (Node, error)

GetNode is get_node.

func (*Client) GetNodeIPAddresses

func (c *Client) GetNodeIPAddresses(ctx context.Context, nodeID uint64) ([]string, error)

GetNodeIPAddresses is get_node_ip_addresses.

func (*Client) GetNodes

func (c *Client) GetNodes(ctx context.Context, onlyAvailable bool) ([]Node, error)

GetNodes is get_nodes.

func (*Client) InterviewNode

func (c *Client) InterviewNode(ctx context.Context, nodeID uint64) error

InterviewNode is interview_node.

func (*Client) Nodes

func (c *Client) Nodes() []Node

Nodes is the start_listening dump.

func (*Client) OpenCommissioningWindow

func (c *Client) OpenCommissioningWindow(ctx context.Context, nodeID uint64, timeout int) (map[string]any, error)

OpenCommissioningWindow is open_commissioning_window.

func (*Client) PingNode

func (c *Client) PingNode(ctx context.Context, nodeID uint64) (map[string]bool, error)

PingNode is ping_node.

func (*Client) PingNodeAddresses added in v0.5.0

func (c *Client) PingNodeAddresses(ctx context.Context, nodeID uint64, attempts int) ([]PingResult, error)

PingNodeAddresses is ping_node with details: one result per address of the node, each probed up to attempts times (1 when attempts is 0).

func (*Client) Read

func (c *Client) Read(ctx context.Context, nodeID uint64, attributePaths, eventPaths []string) (Report, error)

Read is read.

func (*Client) ReadAttribute

func (c *Client) ReadAttribute(ctx context.Context, nodeID uint64, paths ...string) (map[string]any, error)

ReadAttribute is read_attribute with one or more paths.

func (*Client) RemoveMatterFabric

func (c *Client) RemoveMatterFabric(ctx context.Context, nodeID uint64, fabricIndex uint8) error

RemoveMatterFabric is remove_matter_fabric.

func (*Client) RemoveNode

func (c *Client) RemoveNode(ctx context.Context, nodeID uint64) error

RemoveNode is remove_node.

func (*Client) SendRaw

func (c *Client) SendRaw(ctx context.Context, id string, b []byte) (json.RawMessage, error)

SendRaw sends a frame as is and waits for the answer to id — for tests of malformed requests.

func (*Client) ServerInfo

func (c *Client) ServerInfo() ServerInfo

ServerInfo is the server_info the server sent on connect.

func (*Client) SetDefaultFabricLabel

func (c *Client) SetDefaultFabricLabel(ctx context.Context, label string) error

SetDefaultFabricLabel is set_default_fabric_label.

func (*Client) SetLogLevel

func (c *Client) SetLogLevel(ctx context.Context, console string) (LogLevels, error)

SetLogLevel is set_loglevel for the console.

func (*Client) SetThreadDataset

func (c *Client) SetThreadDataset(ctx context.Context, dataset string) error

SetThreadDataset is set_thread_dataset for the default entry.

func (*Client) SetWifiCredentials

func (c *Client) SetWifiCredentials(ctx context.Context, ssid, credentials string) error

SetWifiCredentials is set_wifi_credentials for the default entry.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, nodeID uint64, attributePaths []string, minInterval, maxInterval uint16) (Report, error)

Subscribe is subscribe on attribute paths.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, nodeID uint64, subscriptionID uint32) error

Unsubscribe is unsubscribe.

func (*Client) WriteAttribute

func (c *Client) WriteAttribute(ctx context.Context, nodeID uint64, path string, value any) ([]WriteResult, error)

WriteAttribute is write_attribute.

type DeclareResult added in v0.2.0

type DeclareResult struct {
	Devices  []Declared       `json:"devices"`
	Removed  []string         `json:"removed"`
	Withheld []WithheldDevice `json:"withheld"`
}

DeclareResult is declare's answer. Withheld is empty when the specification level withholds no declared device.

type Declared added in v0.2.0

type Declared struct {
	Key      string  `json:"key"`
	Action   string  `json:"action"`
	Endpoint *uint16 `json:"endpoint"`
	Error    string  `json:"error"`
}

Declared is one device of declare's answer.

type Event

type Event struct {
	Event string
	Data  json.RawMessage
}

Event is a server push.

type HostStatement added in v0.2.0

type HostStatement struct {
	Device         string  `json:"device"`
	Name           *string `json:"name,omitempty"`
	DeviceAddress  *string `json:"device_address,omitempty"`
	ChannelAddress *string `json:"channel_address,omitempty"`
	Reachable      *bool   `json:"reachable,omitempty"`
	Label          *string `json:"label,omitempty"`
}

HostStatement are the host's statements of the host command; nil fields are left as they are.

type LogLevels

type LogLevels struct {
	Console string  `json:"console_loglevel"`
	File    *string `json:"file_loglevel"`
}

LogLevels is the result of get_loglevel and set_loglevel.

type Node

type Node struct {
	NodeID                 uint64            `json:"node_id"`
	DateCommissioned       string            `json:"date_commissioned"`
	LastInterview          string            `json:"last_interview"`
	InterviewVersion       int               `json:"interview_version"`
	Available              bool              `json:"available"`
	IsBridge               bool              `json:"is_bridge"`
	Attributes             map[string]any    `json:"attributes"`
	AttributeSubscriptions []any             `json:"attribute_subscriptions"`
	MatterVersion          *string           `json:"matter_version,omitempty"`
	EndpointParents        map[string]uint16 `json:"endpoint_parents"`
}

Node is a node's data (MatterNodeData). Attribute values keep their numbers exact (json.Number).

type Options

type Options struct {
	// Token is sent as "Authorization: Bearer <token>".
	Token string
	// NoListen skips start_listening: no events but subscription reports.
	NoListen bool
	// EventBuffer is the capacity of the event channel; 0 is 1024. An event
	// that finds it full is dropped and counted ([Client.Dropped]).
	EventBuffer int
	// HTTPClient dials the connection; nil is http.DefaultClient (or a Unix
	// socket client for a "unix:" URL).
	HTTPClient *http.Client
	// Node is the key of the device node DialBridge connects to: the
	// daemon serves each node at /bridge/<key> and its default node at
	// /bridge as well. Set, "/<key>" is appended to the URL's path (to
	// /bridge for a "unix:" URL); empty connects to the URL as given.
	// Dial ignores it.
	Node string
}

Options configure Dial.

type PingResult added in v0.5.0

type PingResult struct {
	IP        string `json:"ip"`
	Port      uint16 `json:"port"`
	Reachable bool   `json:"reachable"`
	// RoundTripMS is the answered attempt's round trip in milliseconds,
	// nil when no attempt was answered.
	RoundTripMS *float64 `json:"round_trip_ms"`
	// Error is the last attempt's error, empty when reachable.
	Error string `json:"error"`
}

PingResult is one address's outcome of ping_node with details.

type Report

type Report struct {
	SubscriptionID  uint32                    `json:"subscription_id,omitempty"`
	NodeID          uint64                    `json:"node_id,omitempty"`
	Attributes      map[string]any            `json:"attributes"`
	Events          []map[string]any          `json:"events"`
	AttributeStatus map[string]map[string]int `json:"attribute_status,omitempty"`
	EventStatus     map[string]map[string]int `json:"event_status,omitempty"`
	DataVersions    map[string]uint32         `json:"data_versions,omitempty"`
}

Report is the result of read and subscribe, and a subscription_report.

type ResultError added in v0.2.0

type ResultError struct {
	Status        *int `json:"status,omitempty"`
	ClusterStatus *int `json:"cluster_status,omitempty"`
}

ResultError is the error of a result: the status to answer with.

type ServerInfo

type ServerInfo struct {
	FabricID                  uint64   `json:"fabric_id"`
	CompressedFabricID        uint64   `json:"compressed_fabric_id"`
	FabricIndex               *uint8   `json:"fabric_index,omitempty"`
	SchemaVersion             int      `json:"schema_version"`
	MinSupportedSchemaVersion int      `json:"min_supported_schema_version"`
	SDKVersion                string   `json:"sdk_version"`
	WifiCredentialsSet        bool     `json:"wifi_credentials_set"`
	WifiSSID                  *string  `json:"wifi_ssid,omitempty"`
	ThreadCredentialsSet      bool     `json:"thread_credentials_set"`
	BluetoothEnabled          bool     `json:"bluetooth_enabled"`
	BLEProxyEnabled           bool     `json:"ble_proxy_enabled"`
	ControllerNodeID          *uint64  `json:"controller_node_id,omitempty"`
	Capabilities              []string `json:"capabilities"`
}

ServerInfo is the server_info object.

type WithheldDevice added in v0.4.6

type WithheldDevice struct {
	Key        string `json:"key"`
	DeviceType string `json:"device_type"`
	SpecLevel  string `json:"spec_level"`
}

WithheldDevice is a declared device the bridge node's specification level withholds: it is declared, serves no endpoint, and the node's surface report lists it as withheld.

type WriteResult

type WriteResult struct {
	Path struct {
		EndpointID  uint16 `json:"EndpointId"`
		ClusterID   uint32 `json:"ClusterId"`
		AttributeID uint32 `json:"AttributeId"`
	} `json:"Path"`
	Status        int  `json:"Status"`
	ClusterStatus *int `json:"ClusterStatus,omitempty"`
}

WriteResult is one entry of a write_attribute result.

Jump to

Keyboard shortcuts

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