Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- type Device
- type DeviceInfo
- type DeviceUsage
- type DiscoverResponse
- type DiscoverV1Request
- type EnergyUsage
- type GetDeviceInfoRequest
- type GetDeviceInfoResponse
- type GetDeviceUsageRequest
- type GetDeviceUsageResponse
- type GetEnergyUsageRequest
- type GetEnergyUsageResponse
- type GetInfo
- type GetSysinfo
- type HandshakeRequest
- type HandshakeResponse
- type KlapSession
- type LoginDeviceRequest
- type LoginDeviceResponse
- type PassthroughSession
- type Plug
- func (p *Plug) GetDeviceInfo() (*DeviceInfo, error)
- func (p *Plug) GetDeviceUsage() (*DeviceUsage, error)
- func (p *Plug) GetEnergyUsage() (*EnergyUsage, error)
- func (p *Plug) Handshake(username, password string) error
- func (p *Plug) IsOn() (bool, error)
- func (p *Plug) Off() error
- func (p *Plug) On() error
- func (p *Plug) SetDeviceInfo(deviceOn bool) error
- type PlugOption
- type ResponseEnvelope
- type SecurePassthroughRequest
- type SecurePassthroughResponse
- type Session
- type SetDeviceInfoRequest
- type SetDeviceInfoResponse
- type TapoStatus
- type UntypedResponse
Constants ¶
View Source
const DiscoverV1InitializationVector = 0xab
Variables ¶
View Source
var ErrForbidden = errors.New("Forbidden")
This is returned when a Tapo device returns an HTTP 403.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a tp-link cloud client for cloud-based operations.
func (*Client) CloudLogin ¶
func (*Client) Discover ¶
func (c *Client) Discover() (map[string]DiscoverResponse, []DiscoverResponse, error)
type Device ¶
type Device struct {
DeviceType string `json:"deviceType"`
Role int `json:"role"`
FwVer string `json:"fwVer"`
AppServerURL string `json:"appServerUrl"`
DeviceRegion string `json:"deviceRegion"`
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
DeviceHwVer string `json:"deviceHwVer"`
Alias string `json:"alias"`
DeviceMAC tapoMAC `json:"deviceMac"`
OemID string `json:"oemId"`
DeviceModel string `json:"deviceModel"`
HwID string `json:"hwId"`
FwID string `json:"fwId"`
IsSameRegion bool `json:"isSameRegion"`
Status int `json:"status"`
// Computed values
DecodedAlias string
}
type DeviceInfo ¶
type DeviceInfo struct {
DeviceID string `json:"device_id"`
FWVersion string `json:"fw_ver"`
HWVersion string `json:"hw_ver"`
Type string `json:"type"`
Model string `json:"model"`
MAC string `json:"mac"`
HWID string `json:"hw_id"`
FWID string `json:"fw_id"`
OEMID string `json:"oem_id"`
IP string `json:"ip"`
TimeDiff int `json:"time_diff"`
SSID string `json:"ssid"`
RSSI int `json:"rssi"`
SignalLevel int `json:"signal_level"`
Latitude int `json:"latitude"`
Longitude int `json:"longitude"`
Lang string `json:"lang"`
Avatar string `json:"avatar"`
Region string `json:"region"`
Specs string `json:"specs"`
Nickname string `json:"nickname"`
HasSetLocationInfo bool `json:"has_set_location_info"`
DeviceON bool `json:"device_on"`
OnTime int `json:"on_time"`
DefaultStates struct {
Type string `json:"type"`
// TODO add the structure for State
State *json.RawMessage `json:"state"`
} `json:"default_states"`
OverHeated bool `json:"overheated"`
PowerProtectionStatus string `json:"power_protection_status,omitempty"`
Location string `json:"location,omitempty"`
// Computed values below.
// DecodedSSID is the decoded version of the base64-encoded SSID field.
DecodedSSID string
// DecodedNickname is the decoded version of the base64-encoded Nickname field.
DecodedNickname string
}
TODO differentiate fields between P100 and P110
type DeviceUsage ¶
type DeviceUsage struct {
TimeUsage struct {
Today int `json:"today"`
Past7 int `json:"past7"`
Past30 int `json:"past30"`
} `json:"time_usage"`
PowerUsage struct {
Today int `json:"today"`
Past7 int `json:"past7"`
Past30 int `json:"past30"`
} `json:"power_usage"`
SavedPower struct {
Today int `json:"today"`
Past7 int `json:"past7"`
Past30 int `json:"past30"`
} `json:"saved_power"`
}
type DiscoverResponse ¶
type DiscoverResponse struct {
Result struct {
DeviceID string `json:"device_id"`
Owner string `json:"owner"`
DeviceType string `json:"device_type"`
DeviceModel string `json:"device_model"`
IP xjson.IP `json:"ip"`
MAC xjson.HardwareAddr `json:"mac"`
IsSupportIOTCloud bool `json:"is_support_iot_clout"`
ObdSrc string `json:"obd_src"`
FactoryDefault bool `json:"factory_default"`
MgtEncryptSchm struct {
IsSupportHTTPS bool `json:"is_support_https"`
EncryptType string `json:"encrypt_type"`
HTTPPort int `json:"http_port"`
Lv int `json:"lv"`
} `json:"mgt_encrypt_schm"`
ErrorCode TapoStatus `json:"error_code"`
} `json:"result"`
}
type DiscoverV1Request ¶
type DiscoverV1Request struct {
System GetSysinfo `json:"system"`
CnCloud GetInfo `json:"cnCloud"`
IOTCommonCloud GetInfo `json:"smartlife.iot.common.cloud"`
CamIpcameraCloud GetInfo `json:"smartlife.cam.ipcamera.cloud"`
}
func NewDiscoverV1Request ¶
func NewDiscoverV1Request() *DiscoverV1Request
type EnergyUsage ¶
type EnergyUsage struct {
TodayRuntime int `json:"today_runtime"`
MonthRuntime int `json:"month_runtime"`
TodayEnergy int `json:"today_energy"`
MonthEnergy int `json:"month_energy"`
LocalTime string `json:"local_time"`
ElectricityCharge [3]int `json:"electricity_charge"`
CurrentPower int `json:"current_power"`
}
type GetDeviceInfoRequest ¶
type GetDeviceInfoRequest struct {
Method string `json:"method"`
RequestTimeMils int `json:"requestTimeMils"`
}
func NewGetDeviceInfoRequest ¶
func NewGetDeviceInfoRequest() *GetDeviceInfoRequest
type GetDeviceInfoResponse ¶
type GetDeviceInfoResponse struct {
ResponseEnvelope
Result DeviceInfo `json:"result"`
}
type GetDeviceUsageRequest ¶
type GetDeviceUsageRequest struct {
Method string `json:"method"`
RequestTimeMils int `json:"requestTimeMils"`
}
func NewGetDeviceUsageRequest ¶
func NewGetDeviceUsageRequest() *GetDeviceUsageRequest
type GetDeviceUsageResponse ¶
type GetDeviceUsageResponse struct {
ResponseEnvelope
Result DeviceUsage `json:"result"`
}
type GetEnergyUsageRequest ¶
type GetEnergyUsageRequest struct {
Method string `json:"method"`
RequestTimeMils int `json:"requestTimeMils"`
}
func NewGetEnergyUsageRequest ¶
func NewGetEnergyUsageRequest() *GetEnergyUsageRequest
type GetEnergyUsageResponse ¶
type GetEnergyUsageResponse struct {
ResponseEnvelope
Result EnergyUsage `json:"result"`
}
type GetSysinfo ¶
type HandshakeRequest ¶
type HandshakeRequest struct {
Method string `json:"method"`
RequestTimeMils int `json:"requestTimeMils"`
Params struct {
Key string `json:"key"`
} `json:"params"`
}
func NewHandshakeRequest ¶
func NewHandshakeRequest(key string) *HandshakeRequest
type HandshakeResponse ¶
type HandshakeResponse struct {
ResponseEnvelope
Result struct {
Key string `json:"key"`
}
}
type KlapSession ¶
type KlapSession struct {
SessionID string
Expiry time.Time
LocalSeed []byte
RemoteSeed []byte
UserHash []byte
// contains filtered or unexported fields
}
func NewKlapSession ¶
func NewKlapSession(l *log.Logger) *KlapSession
func (*KlapSession) Addr ¶
func (s *KlapSession) Addr() netip.Addr
func (*KlapSession) Handshake ¶
func (s *KlapSession) Handshake(addr netip.Addr, username, password string) error
func (*KlapSession) Request ¶
func (s *KlapSession) Request(payload []byte) (*UntypedResponse, error)
type LoginDeviceRequest ¶
type LoginDeviceRequest struct {
Method string `json:"method"`
RequestTimeMils int `json:"requestTimeMils"`
Params struct {
Username string `json:"username"`
Password string `json:"password"`
} `json:"params"`
}
func NewLoginDeviceRequest ¶
func NewLoginDeviceRequest(username, password string) *LoginDeviceRequest
type LoginDeviceResponse ¶
type LoginDeviceResponse struct {
ResponseEnvelope
Result struct {
Token string `json:"token"`
} `json:"result"`
}
type PassthroughSession ¶
type PassthroughSession struct {
Key []byte
IV []byte
ID string
// contains filtered or unexported fields
}
func NewPassthroughSession ¶
func NewPassthroughSession(l *log.Logger) *PassthroughSession
func (*PassthroughSession) Addr ¶
func (p *PassthroughSession) Addr() netip.Addr
func (*PassthroughSession) Handshake ¶
func (p *PassthroughSession) Handshake(addr netip.Addr, username, password string) error
func (*PassthroughSession) Request ¶
func (s *PassthroughSession) Request(requestBytes []byte) (*UntypedResponse, error)
type Plug ¶
func (*Plug) GetDeviceInfo ¶
func (p *Plug) GetDeviceInfo() (*DeviceInfo, error)
func (*Plug) GetDeviceUsage ¶
func (p *Plug) GetDeviceUsage() (*DeviceUsage, error)
func (*Plug) GetEnergyUsage ¶
func (p *Plug) GetEnergyUsage() (*EnergyUsage, error)
func (*Plug) SetDeviceInfo ¶
type PlugOption ¶ added in v1.0.2
type PlugOption func(p *Plug)
func OptionRetryOnCommunicationError ¶ added in v1.0.2
func OptionRetryOnCommunicationError(times uint) PlugOption
func OptionRetryOnForbidden ¶ added in v1.0.2
func OptionRetryOnForbidden(times uint) PlugOption
type ResponseEnvelope ¶ added in v1.0.2
type ResponseEnvelope struct {
ErrorCode TapoStatus `json:"error_code"`
}
type SecurePassthroughRequest ¶
type SecurePassthroughRequest struct {
Method string `json:"method"`
Params struct {
Request string `json:"request"`
} `json:"params"`
}
func NewSecurePassthroughRequest ¶
func NewSecurePassthroughRequest(innerRequest string) *SecurePassthroughRequest
type SecurePassthroughResponse ¶
type SecurePassthroughResponse struct {
ResponseEnvelope
Result struct {
Response string `json:"response"`
}
}
type SetDeviceInfoRequest ¶
type SetDeviceInfoRequest struct {
Method string `json:"method"`
Params struct {
DeviceOn bool `json:"device_on"`
} `json:"params"`
}
func NewSetDeviceInfoRequest ¶
func NewSetDeviceInfoRequest(deviceOn bool) *SetDeviceInfoRequest
type SetDeviceInfoResponse ¶
type SetDeviceInfoResponse struct {
ResponseEnvelope
Result struct {
Response string `json:"response"`
}
}
type TapoStatus ¶ added in v1.0.2
type TapoStatus int
var ( StatusSuccess TapoStatus = 0 StatusInvalidPublicKeyLength TapoStatus = -1010 StatusInvalidTerminalUUID TapoStatus = -1012 StatusInvalidRequestOrCredentials TapoStatus = -1501 StatusIncorrectRequest TapoStatus = 1002 StatusJSONFormattingError TapoStatus = -1003 StatusCommunicationError TapoStatus = 1003 StatusSessionTimeout TapoStatus = 9999 )
func (TapoStatus) Error ¶ added in v1.0.2
func (te TapoStatus) Error() string
type UntypedResponse ¶ added in v1.0.2
type UntypedResponse struct {
ResponseEnvelope
Result *json.RawMessage `json:"result,omitempty"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.