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 ¶
- Variables
- type Bridge
- func (b *Bridge) Declare(ctx context.Context, doc any) (DeclareResult, error)
- func (b *Bridge) Devices() []BridgedDevice
- func (b *Bridge) Forget(ctx context.Context, device string) error
- func (b *Bridge) Host(ctx context.Context, st HostStatement) error
- func (b *Bridge) Info() BridgeInfo
- func (b *Bridge) NodeInfo(ctx context.Context) (map[string]any, error)
- func (b *Bridge) PairingCodes(ctx context.Context) (qr, manual string, err error)
- func (b *Bridge) Remove(ctx context.Context, device string) error
- func (b *Bridge) Result(ctx context.Context, correlation uint64, response any, err *ResultError) error
- func (b *Bridge) Set(ctx context.Context, device, cluster string, patch any) error
- type BridgeEvent
- type BridgeInfo
- type BridgedDevice
- type Client
- func (c *Client) Call(ctx context.Context, command string, args, result any) error
- func (c *Client) CallRaw(ctx context.Context, command string, args any) (json.RawMessage, error)
- func (c *Client) Close() error
- func (c *Client) CommissionOnNetwork(ctx context.Context, pin uint32, filterType int, filter uint64, ip string) (Node, error)
- func (c *Client) CommissionWithCode(ctx context.Context, code string, networkOnly bool) (Node, error)
- func (c *Client) DeviceCommand(ctx context.Context, nodeID uint64, endpoint uint16, cluster uint32, ...) (json.RawMessage, error)
- func (c *Client) Diagnostics(ctx context.Context) (map[string]json.RawMessage, error)
- func (c *Client) Discover(ctx context.Context) ([]map[string]any, error)
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Dropped() uint64
- func (c *Client) Events() <-chan Event
- func (c *Client) GetAllCredentials(ctx context.Context) (map[string]any, error)
- func (c *Client) GetFabricLabel(ctx context.Context) (string, error)
- func (c *Client) GetLogLevel(ctx context.Context) (LogLevels, error)
- func (c *Client) GetMatterFabrics(ctx context.Context, nodeID uint64) ([]map[string]any, error)
- func (c *Client) GetNode(ctx context.Context, nodeID uint64) (Node, error)
- func (c *Client) GetNodeIPAddresses(ctx context.Context, nodeID uint64) ([]string, error)
- func (c *Client) GetNodes(ctx context.Context, onlyAvailable bool) ([]Node, error)
- func (c *Client) InterviewNode(ctx context.Context, nodeID uint64) error
- func (c *Client) Nodes() []Node
- func (c *Client) OpenCommissioningWindow(ctx context.Context, nodeID uint64, timeout int) (map[string]any, error)
- func (c *Client) PingNode(ctx context.Context, nodeID uint64) (map[string]bool, error)
- func (c *Client) PingNodeAddresses(ctx context.Context, nodeID uint64, attempts int) ([]PingResult, error)
- func (c *Client) Read(ctx context.Context, nodeID uint64, attributePaths, eventPaths []string) (Report, error)
- func (c *Client) ReadAttribute(ctx context.Context, nodeID uint64, paths ...string) (map[string]any, error)
- func (c *Client) RemoveMatterFabric(ctx context.Context, nodeID uint64, fabricIndex uint8) error
- func (c *Client) RemoveNode(ctx context.Context, nodeID uint64) error
- func (c *Client) SendRaw(ctx context.Context, id string, b []byte) (json.RawMessage, error)
- func (c *Client) ServerInfo() ServerInfo
- func (c *Client) SetDefaultFabricLabel(ctx context.Context, label string) error
- func (c *Client) SetLogLevel(ctx context.Context, console string) (LogLevels, error)
- func (c *Client) SetThreadDataset(ctx context.Context, dataset string) error
- func (c *Client) SetWifiCredentials(ctx context.Context, ssid, credentials string) error
- func (c *Client) Subscribe(ctx context.Context, nodeID uint64, attributePaths []string, ...) (Report, error)
- func (c *Client) Unsubscribe(ctx context.Context, nodeID uint64, subscriptionID uint32) error
- func (c *Client) WriteAttribute(ctx context.Context, nodeID uint64, path string, value any) ([]WriteResult, error)
- type DeclareResult
- type Declared
- type Event
- type HostStatement
- type LogLevels
- type Node
- type Options
- type PingResult
- type Report
- type ResultError
- type ServerInfo
- type WithheldDevice
- type WriteResult
Constants ¶
This section is empty.
Variables ¶
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
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
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
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) PairingCodes ¶ added in v0.2.0
PairingCodes are the node's QR payload and manual code.
func (*Bridge) Remove ¶ added in v0.2.0
Remove removes a device; its endpoint number stays stored under its key, so a later Declare of the key gets it back.
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 ¶
Dial connects to url ("ws://host:port/ws", or "unix:/path" for the server's Unix socket).
func (*Client) Call ¶
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 ¶
CallRaw is Client.Call returning the raw result.
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 ¶
Diagnostics is diagnostics.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed when the connection ended.
func (*Client) GetAllCredentials ¶
GetAllCredentials is get_all_credentials.
func (*Client) GetFabricLabel ¶
GetFabricLabel is get_fabric_label.
func (*Client) GetLogLevel ¶
GetLogLevel is get_loglevel.
func (*Client) GetMatterFabrics ¶
GetMatterFabrics is get_matter_fabrics.
func (*Client) GetNodeIPAddresses ¶
GetNodeIPAddresses is get_node_ip_addresses.
func (*Client) InterviewNode ¶
InterviewNode is interview_node.
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) 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 ¶
RemoveMatterFabric is remove_matter_fabric.
func (*Client) RemoveNode ¶
RemoveNode is remove_node.
func (*Client) SendRaw ¶
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 ¶
SetDefaultFabricLabel is set_default_fabric_label.
func (*Client) SetLogLevel ¶
SetLogLevel is set_loglevel for the console.
func (*Client) SetThreadDataset ¶
SetThreadDataset is set_thread_dataset for the default entry.
func (*Client) SetWifiCredentials ¶
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 ¶
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 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.