Documentation ¶
Index ¶
- Constants
- func BroadcastAddresses() ([]net.IP, error)
- func BroadcastDimmerParameters(timeout, probes int) (map[string]*DimmerParameters, error)
- func BroadcastDiscovery(timeout, probes int) (map[string]*Sysinfo, error)
- func BroadcastEmeter(timeout, probes int) (map[string]KasaDevice, error)
- func BroadcastWifiParameters(timeout, probes int) (map[string]*StaInfo, error)
- func Scramble(plaintext string) []byte
- func ScrambleTCP(plaintext string) []byte
- func SetLogger(l kasalogger)
- func Unscramble(ciphertext []byte) []byte
- type AddRule
- type Child
- type Countdown
- type DelRules
- type Device
- func (d *Device) AddCountdownRule(dur int, target bool, name string) error
- func (d *Device) ClearCountdownRules() error
- func (d *Device) DisableCloud() error
- func (d *Device) EnableCloud(username, password string) error
- func (d *Device) GetCountdownRules() (*[]Rule, error)
- func (d *Device) GetDimmerParameters() (*DimmerParameters, error)
- func (d *Device) GetEmeter() (*EmeterRealtime, error)
- func (d *Device) GetEmeterChild(child string) (*EmeterRealtime, error)
- func (d *Device) GetEmeterMonth(month, year int) (*EmeterDaystat, error)
- func (d *Device) GetRules() (string, error)
- func (d *Device) GetSettings() (*Sysinfo, error)
- func (d *Device) GetWIFIStatus() (*StaInfo, error)
- func (d *Device) Reboot() error
- func (d *Device) SendRawCommand(cmd string) error
- func (d *Device) SetAlias(s string) error
- func (d *Device) SetBrightness(newval int) error
- func (d *Device) SetChildAlias(childID, s string) error
- func (d *Device) SetFadeOffTime(newval int) error
- func (d *Device) SetFadeOnTime(newval int) error
- func (d *Device) SetGentleOffTime(newval int) error
- func (d *Device) SetGentleOnTime(newval int) error
- func (d *Device) SetLEDOff(t bool) error
- func (d *Device) SetMode(m string) error
- func (d *Device) SetRelayState(newstate bool) error
- func (d *Device) SetRelayStateChild(childID string, newstate bool) error
- func (d *Device) SetRelayStateChildMulti(newstate bool, children ...string) error
- type Dimmer
- type DimmerParameters
- type EmeterDay
- type EmeterDaystat
- type EmeterRealtime
- type EmeterSub
- type GetRules
- type GetSysinfo
- type KasaDevice
- type NetIf
- type Preset
- type Rule
- type StaInfo
- type Sysinfo
Constants ¶
const ( CmdSetRelayState = `{"system":{"set_relay_state":{"state":%d}}}` // 0 or 1 CmdGetSysinfo = `{"system":{"get_sysinfo":{}}}` CmdReboot = `{"system":{"reboot":{"delay":2}}}` CmdLEDOff = `{"system":{"set_led_off":{"off":%d}}}` // off = 1, on = 0 CmdDeviceAlias = `{"system":{"set_dev_alias":{"alias":"%s"}}}` CmdSetMode = `{"system":{"set_mode":{"mode":"%s"}}}` // "none", "count_down", ??? CmdGetEmeter = `{"emeter":{"get_realtime":{}}}` CmdGetEmeterGetDaystat = `{"emeter":{"get_daystat":{"month":%d,"year":%d}}}` CmdGetEmeterVgain = `{"emeter":{"get_vgain_igain":{}}}` CmdSetEmeterVgain = `{"emeter":{"set_vgain_igain":{"vgain":%d,"igain":%d}}}` // int, int CmdEmeterCalibration = `{"emeter":{"start_calibration":{"vtarget":%d,"itarget":%d}}}` // int, int CmdEmeterGetMonth = `{"emeter":{"get_daystat":{"month":%d,"year":%d}}}` // 1-12, 4-digit-year CmdEmeterGetYear = `{"emeter":{"get_monthstat":{"year":%d}}}` // 4-digit-year CmdEmeterErase = `{"emeter":{"erase_emeter_stat":null}}` CmdGetEmeterChild = `{"context":{"child_ids":["%s"]},"emeter":{"get_realtime":{}}}` CmdWifiStainfo = `{"netif":{"get_stainfo":{}}}` CmdSetRelayStateChild = `{"context":{"child_ids":["%s"]},"system":{"set_relay_state":{"state":%d}}}` // index (e.g. ".....00"), 0/1 CmdSetRelayStateChildMulti = `{"context":{"child_ids":[%s]},"system":{"set_relay_state":{"state":%d}}}` // indexes (e.g. `"....00","....03"`), 0/1 CmdChildAlias = `{"context":{"child_ids":["%s"]},"system":{"set_dev_alias":{"alias":"%s"}}}` // index (e.g. "....01"), name CmdGetDimmer = `{"smartlife.iot.dimmer":{"get_dimmer_parameters":{}}}` CmdSetBrightness = `{"smartlife.iot.dimmer":{"set_brightness":{"brightness":%d}}}` // 0-100 CmdSetFadeOffTime = `{"smartlife.iot.dimmer":{"set_fade_off_time":{"fadeTime":%d}}}` // ms CmdSetFadeOnTime = `{"smartlife.iot.dimmer":{"set_fade_on_time":{"fadeTime":%d}}}` // ms CmdSetGentleOffTime = `{"smartlife.iot.dimmer":{"set_gentle_off_time":{"fadeTime":%d}}}` // ms CmdSetGentleOnTime = `{"smartlife.iot.dimmer":{"set_gentle_on_time":{"fadeTime":%d}}}` // ms CmdGetRules = `{"smartlife.iot.common.schedule":{"get_rules":{}}}` CmdGetCountdownRules = `{"count_down":{"get_rules":{}}}` CmdDeleteAllRules = `{"count_down":{"delete_all_rules":{}}}` CmdAddCountdownRule = `{"count_down":{"add_rule":{"enable":1,"delay":%d,"act":%d,"name":"%s"}}}` // 0-3600, 0/1, string CmdCloudUnbind = `{"cnCloud":{"unbind":null}}` CmdSetServerURL = `{"cnCloud":{"set_server_url":{"server":"%s"}}}` // bare hostname, no protocol spec CmdSetServerCreds = `{"cnCloud":{"bind":{"username":"%s", "password":"%s"}}}` // alice@home.com / mikeisagoat )
Request strings
Variables ¶
This section is empty.
Functions ¶
func BroadcastAddresses ¶
BroadcastAddresses - probably belongs in its own library, get all broadcast addresses
func BroadcastDimmerParameters ¶
func BroadcastDimmerParameters(timeout, probes int) (map[string]*DimmerParameters, error)
BroadcastDimmerParameters queries all devices on all attached subnets for dimmer state
func BroadcastDiscovery ¶
BroadcastDiscovery pulls every attached subnet for kasa devices and returns whatever is discovered
func BroadcastEmeter ¶
func BroadcastEmeter(timeout, probes int) (map[string]KasaDevice, error)
BroadcastEmeter pulls all devices on all attached subnets for emeter data
func BroadcastWifiParameters ¶
BroadcastWifiParameters polls all devices on all attached subnets for wifi status. This is handy when you have one device that never wants to respond, seeing how its wifi status changes over time
func Scramble ¶
Scramble is simpler. UDP doesn't require the length header, just allocates and write to a slice.
func ScrambleTCP ¶
ScrambleTCP is for TCP, It writes the length in the first byte. It uses a binary buffer and writer.
func SetLogger ¶
func SetLogger(l kasalogger)
SetLogger allows applications to register their own logging interface
func Unscramble ¶
Unscramble turns the response from the Kasa into parsable JSON it works in place -- be careful with your buffers
Types ¶
type AddRule ¶
type AddRule struct { ID string `json:"id"` ErrorCode int8 `json:"err_code"` ErrorMessage string `json:"err_msg"` }
AddRule is defined by kasa devices
type Child ¶
type Child struct { ID string `json:"id"` RelayState uint8 `json:"state"` Alias string `json:"alias"` OnTime int `json:"on_time"` }
Child is defined by kasa devices
type Countdown ¶
type Countdown struct { GetRules GetRules `json:"get_rules"` DelRules DelRules `json:"delete_all_rules"` AddRule AddRule `json:"add_rule"` }
Countdown is defined by kasa devices
type Device ¶
Device is the primary type, commands are called from the device
func (*Device) AddCountdownRule ¶
AddCountdownRule adds a new countdown
func (*Device) ClearCountdownRules ¶
ClearCountdownRules resets all countdown rules on the device
func (*Device) DisableCloud ¶
DisableCloud sets the device to "local only" mode. TODO: forget any cloud settings
func (*Device) EnableCloud ¶
Enable/Configure Cloud
func (*Device) GetCountdownRules ¶
GetCountdownRules returns a list of the countdown timers on a device
func (*Device) GetDimmerParameters ¶
func (d *Device) GetDimmerParameters() (*DimmerParameters, error)
GetDimmerParameters returns the dimmer parameters from dimmer-capable devices
func (*Device) GetEmeter ¶
func (d *Device) GetEmeter() (*EmeterRealtime, error)
GetEmeter returns emeter data from the device
func (*Device) GetEmeterChild ¶
func (d *Device) GetEmeterChild(child string) (*EmeterRealtime, error)
GetEmeter returns emeter data from the device
func (*Device) GetEmeterMonth ¶
func (d *Device) GetEmeterMonth(month, year int) (*EmeterDaystat, error)
GetEmeterMonth returns a single month's emeter data from the device
func (*Device) GetSettings ¶
GetSettings gets the device sys info
func (*Device) GetWIFIStatus ¶
GetWIFIStatus returns the WiFi station info
func (*Device) SendRawCommand ¶
func (*Device) SetBrightness ¶
SetBrightness adjust the brightness setting on a dimmer-capable device (1-100)
func (*Device) SetChildAlias ¶
SetChildAlias sets the name of an individual relay on a multi-relay device, I don't think this works
func (*Device) SetFadeOffTime ¶
func (*Device) SetFadeOnTime ¶
func (*Device) SetGentleOffTime ¶
func (*Device) SetGentleOnTime ¶
func (*Device) SetLEDOff ¶
SetLEDOff is insanely named... it should be SetLED, but I'm just going with what TP-Link called these things internally...
func (*Device) SetRelayState ¶
SetRelayState changes the relay state of the device -- for multi-relay devices use SetRelayStateChild
func (*Device) SetRelayStateChild ¶
SetRelayStateChild adjusts a single relay on a multi-relay device
type Dimmer ¶
type Dimmer struct { Parameters DimmerParameters `json:"get_dimmer_parameters"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
Dimmer is defined by kasa devices
type DimmerParameters ¶
type DimmerParameters struct { MinThreshold uint16 `json:"minThreshold"` FadeOnTime uint16 `json:"fadeOnTime"` FadeOffTime uint16 `json:"fadeOffTime"` GentleOnTime uint16 `json:"gentleOnTime"` GentleOffTime uint16 `json:"gentleOffTime"` RampRate uint16 `json:"rampRate"` BulbType uint8 `json:"bulb_type"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
DimmerParameters is defined by kasa devices
type EmeterDay ¶
type EmeterDay struct { Year uint16 `json:"year"` Month uint8 `json:"month"` Day uint8 `json:"day"` WH uint16 `json:"energy_wh"` }
EmeterDay is defined by kasa devices
type EmeterDaystat ¶
type EmeterDaystat struct { List []EmeterDay `json:"day_list"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
EmeterDaystat is defined by kasa devices
type EmeterRealtime ¶
type EmeterRealtime struct { Slot uint8 `json:"slot_id"` CurrentMA uint `json:"current_ma"` VoltageMV uint `json:"voltage_mv"` PowerMW uint `json:"power_mw"` TotalWH uint `json:"total_wh"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
EmeterRealtime is defined by kasa devices
type EmeterSub ¶
type EmeterSub struct { Realtime EmeterRealtime `json:"get_realtime"` DayStat EmeterDaystat `json:"get_daystat"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
EmeterSub is defined by kasa devices
type GetRules ¶
type GetRules struct { RuleList []Rule `json:"rule_list"` ErrorCode int8 `json:"err_code"` ErrorMessage string `json:"err_msg"` }
GetRules is defined by kasa devices
type GetSysinfo ¶
type GetSysinfo struct {
Sysinfo Sysinfo `json:"get_sysinfo"`
}
GetSysinfo is defined by kasa devices
type KasaDevice ¶
type KasaDevice struct { GetSysinfo GetSysinfo `json:"system"` Dimmer Dimmer `json:"smartlife.iot.dimmer"` NetIf NetIf `json:"netif"` Countdown Countdown `json:"count_down"` Emeter EmeterSub `json:"emeter"` }
KasaDevice is the primary type, defined by kasa devices
type NetIf ¶
type NetIf struct { StaInfo StaInfo `json:"get_stainfo"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
NetIf is defined by kasa devices {"netif":{"get_stainfo":{"ssid":"IoT8417","key_type":3,"rssi":-61,"err_code":0}}}
type Rule ¶
type Rule struct { ID string `json:"id"` Name string `json:"name"` Enable uint8 `json:"enable"` Delay uint16 `json:"delay"` Active uint8 `json:"act"` Remaining uint16 `json:"remain"` }
Rule is defined by kasa devices
type StaInfo ¶
type StaInfo struct { SSID string `json:"ssid"` KeyType int8 `json:"key_type"` RSSI int8 `json:"rssi"` ErrCode int8 `json:"err_code"` ErrMsg string `json:"err_msg"` }
StaInfo is defined by kasa devices
type Sysinfo ¶
type Sysinfo struct { SWVersion string `json:"sw_ver"` HWVersion string `json:"hw_ver"` Model string `json:"model"` DeviceID string `json:"deviceId"` OEMID string `json:"oemId"` HWID string `json:"hwId"` RSSI int8 `json:"rssi"` Longitude int `json:"longitude_i"` Latitude int `json:"latitude_i"` Alias string `json:"alias"` Status string `json:"status"` MIC string `json:"mic_type"` Feature string `json:"feature"` MAC string `json:"mac"` Updating uint8 `json:"updating"` LEDOff uint8 `json:"led_off"` RelayState uint8 `json:"relay_state"` Brightness uint8 `json:"brightness"` OnTime int `json:"on_time"` ActiveMode string `json:"active_mode"` DevName string `json:"dev_name"` Children []Child `json:"children"` NumChildren uint8 `json:"child_num"` NTCState int `json:"ntc_state"` PreferredState []Preset `json:"preferred_state"` ErrCode int8 `json:"error_code"` }
Sysinfo is defined by kasa devices