Documentation ¶
Index ¶
- Variables
- type Node
- func (n *Node) AddOrUpdate(d *devices.Device)
- func (n *Node) Connect() error
- func (n *Node) GetDevice(id string) *devices.Device
- func (n *Node) On(what string, cb OnFunc)
- func (n *Node) OnConfig(cb OnFunc)
- func (n *Node) OnRequestStateChange(cb func(state devices.State, device *devices.Device) error)
- func (n *Node) OnShutdown(cb func())
- func (n *Node) Stop()
- func (n *Node) Stopped() <-chan struct{}
- func (n *Node) Subscribe(what ...string) error
- func (n *Node) SyncDevice(id string)
- func (n *Node) SyncDevices() error
- func (n *Node) UpdateState(id string, newState devices.State)
- func (n *Node) Wait()
- func (n *Node) WaitForFirstConfig() func() error
- func (n *Node) WaitForMessage(msgType string, dst interface{}) error
- func (n *Node) WriteMessage(msgType string, data interface{}) error
- type OnFunc
Constants ¶
This section is empty.
Variables ¶
var ErrSkipSync = fmt.Errorf("skipping device sync after RequestStateChange")
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { UUID string Type string Version string Protocol string Client websocket.Websocket Config *models.Config X509 *x509.Certificate TLS *tls.Certificate CA *x509.CertPool Devices *devices.List // contains filtered or unexported fields }
Node is the main struct.
func NewWithClient ¶
NewWithClient returns a new Node with a custom websocket client.
func (*Node) AddOrUpdate ¶
AddOrUpdate adds or updates a device in our local device store and notifies the server about the new state of the device.
func (*Node) Connect ¶
Connect starts the node and makes connection to the server. Normally discovered using mdns but can be configured aswell.
func (*Node) OnRequestStateChange ¶
OnRequestStateChange is run if we get a state-change request from the server to update our devices (for example we are requested to turn on a light).
func (*Node) OnShutdown ¶
func (n *Node) OnShutdown(cb func())
OnShutdown registers a callback that is run before the server shuts down.
func (*Node) Stopped ¶
func (n *Node) Stopped() <-chan struct{}
Stopped is closed when the node is stopped by n.Stop or os signal.
func (*Node) SyncDevices ¶
SyncDevices notifies the server about the state of all our known devices.
func (*Node) UpdateState ¶
UpdateState updates the new state on the node if if differs and sends update to server if there was a diff.
func (*Node) WaitForFirstConfig ¶
WaitForFirstConfig blocks until we receive the first config from server.
func (*Node) WaitForMessage ¶
WaitForMessage is a helper method to wait for a specific message type.
func (*Node) WriteMessage ¶
WriteMessage writes a message to the server over websocket client.