Documentation ¶
Overview ¶
Package relay implements LIFX LAN Protocol for LIFX relay devices (switches):
https://lan.developer.lifx.com/docs/the-lifx-switch
Please refer to its parent package for more background/context.
Example ¶
package main import ( "context" "log" "time" "go.yhsif.com/lifxlan" "go.yhsif.com/lifxlan/relay" ) func main() { // Need proper initialization in real code. var ( device relay.Device // Important to set timeout to context when requiring ack. timeout time.Duration ) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() if err := device.SetRPower( ctx, nil, // conn, use nil so that SetRPower will maintain it for us 0, // index of the relay to controal lifxlan.PowerOn, true, // ack ); err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
const ( GetRPower lifxlan.MessageType = 816 SetRPower lifxlan.MessageType = 817 StateRPower lifxlan.MessageType = 818 )
Tile related MessageType values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device interface { lifxlan.Device // GetRPower returns the current power level on the relay at index. // // If conn is nil, // a new connection will be made and guaranteed to be closed before returning. // You should pre-dial and pass in the conn if you plan to call APIs on this // device repeatedly. GetRPower(ctx context.Context, conn net.Conn, index uint8) (lifxlan.Power, error) // SetRPower sets the power level at the relay index. (Turn it on or off.) // // If conn is nil, // a new connection will be made and guaranteed to be closed before returning. // You should pre-dial and pass in the conn if you plan to call APIs on this // device repeatedly. // // If ack is false, // this function returns nil error after the API is sent successfully. // If ack is true, // this function will only return nil error after it received ack from the // device. SetRPower(ctx context.Context, conn net.Conn, index uint8, power lifxlan.Power, ack bool) error }
Device is a wrapped lifxlan.Device that provides relay related APIs.
func Wrap ¶
Wrap tries to wrap a lifxlan.Device into a relay device.
When force is false and d is already a relay device, d will be casted and returned directly. Otherwise, this function calls a relay device API, and only returns a non-nil Device if it supports the API.
If the device is not a relay device, the function might block until ctx is cancelled.
type RawGetRPowerPayload ¶
type RawGetRPowerPayload struct {
Index uint8
}
RawGetRPowerPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/querying-the-device-for-data#getrpower---packet-816
type RawSetRPowerPayload ¶
RawSetRPowerPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/changing-a-device#setrpower---packet-817
type RawStateRPowerPayload ¶
RawStateRPowerPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/information-messages#staterpower---packet-818