Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGetSysinfoFailed = errors.New("get_sysinfo failed")
ErrGetSysinfoFailed is returned by a Kasa device when get_sysinfo fails.
Functions ¶
func DecodeAPIMessage ¶
func DecodeAPIMessage(raw []byte, message *APIMessage) error
DecodeAPIMessage from the "encrypted" Kasa wire format.
Types ¶
type APIMessage ¶
type APIMessage struct { RemoteAddress *net.UDPAddr `json:"-"` System map[string]interface{} `json:"system"` }
APIMessage wraps requests to and responses from Kasa devices. Does not currently support emeter details.
func Send ¶
func Send(ctx context.Context, message *APIMessage, raddr, laddr *net.UDPAddr, expectResponse bool) ([]*APIMessage, error)
Send an APIMessage to a UDP address. The address can be either an individual Kasa device's address, or a broadcast address. If expectResponse is true, then receive is called and any responses are returned. If expectResponse is false, the returned APIMessage slice will always be nil.
func (*APIMessage) Encode ¶
func (p *APIMessage) Encode() ([]byte, error)
Encode an API message into the wire format expected by Kasa devices. This is a JSON payload with no trailing whitespace, "encrypted" using the encrypt function.
func (*APIMessage) GetModule ¶
func (p *APIMessage) GetModule(module string) (map[string]interface{}, bool)
GetModule from the APIMessage. A "module" is the command or response to a command inside the system object of the Kasa API message. Examples include get_sysinfo and set_relate_state.
This is a utility intended for use with mapstructure or similar.
type SystemInformation ¶
type SystemInformation struct { RemoteAddress *net.UDPAddr `json:"-"` ErrorCode int `json:"err_code,omitempty" mapstructure:"err_code"` Error string `json:"error_msg,omitempty" mapstructure:"error_msg"` ActiveMode string `json:"active_mode,omitempty" mapstructure:"active_mode"` Alias string `json:"alias,omitempty" mapstructure:"alias"` DeviceID string `json:"deviceId,omitempty" mapstructure:"deviceId"` DevName string `json:"dev_name,omitempty" mapstructure:"dev_name"` Feature string `json:"feature,omitempty" mapstructure:"feature"` HardwareID string `json:"hwId,omitempty" mapstructure:"hwId"` HardwareVersion string `json:"hw_ver,omitempty" mapstructure:"hw_ver"` IconHash string `json:"icon_hash,omitempty" mapstructure:"icon_hash"` LEDOff int `json:"led_off,omitempty" mapstructure:"led_off"` MAC string `json:"mac,omitempty" mapstructure:"mac"` MicType string `json:"mic_type,omitempty" mapstructure:"mic_type"` Model string `json:"model,omitempty" mapstructure:"model"` NTCCode int `json:"ntc_code,omitempty" mapstructure:"ntc_code"` OEMID string `json:"oemId,omitempty" mapstructure:"oemId"` OnTime int `json:"on_time,omitempty" mapstructure:"on_time"` RelayState int `json:"relay_state,omitempty" mapstructure:"relay_state"` RSSI int `json:"rssi,omitempty" mapstructure:"rssi"` SoftwareVersion string `json:"sw_ver,omitempty" mapstructure:"sw_ver"` Status string `json:"status,omitempty" mapstructure:"status"` Updating int `json:"updating,omitempty" mapstructure:"updating"` NextAction *struct { Type int `json:"type,omitempty"` } `json:"next_action,omitempty"` }
SystemInformation gives structure to the response to get_sysinfo requests.
func GetSystemInformation ¶
func GetSystemInformation(ctx context.Context, raddr, laddr *net.UDPAddr, allOrNothing bool) ([]*SystemInformation, error)
GetSystemInformation sends a get_sysinfo request to the UDP address, and returns any responses received before the deadline.
func (SystemInformation) Err ¶
func (p SystemInformation) Err() error
Err converts any error details in a get_sysinfo response to a Go error.
func (*SystemInformation) FromAPIMessage ¶
func (i *SystemInformation) FromAPIMessage(msg *APIMessage) error
FromAPIMessage populates a SystemInformation from an APIMessage.