tapo

package
v0.0.0-...-175a4df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = time.Second * 15

Variables

This section is empty.

Functions

func DumpRSAPEM

func DumpRSAPEM(pubKey *rsa.PublicKey) ([]byte, error)

func GenerateRSAKeys

func GenerateRSAKeys() (*rsa.PrivateKey, *rsa.PublicKey, error)

Types

type Connection

type Connection struct {
	*request.Helper

	URI             string
	EncodedUser     string
	EncodedPassword string
	Cipher          *ConnectionCipher
	SessionID       string
	Token           string
	TerminalUUID    string
	// contains filtered or unexported fields
}

Connection is the Tapo connection

func NewConnection

func NewConnection(uri, user, password string) (*Connection, error)

NewConnection creates a new Tapo device connection. User is encoded by using MessageDigest of SHA1 which is afterwards B64 encoded. Password is directly B64 encoded.

func (*Connection) ChargedEnergy

func (d *Connection) ChargedEnergy() (float64, error)

ChargedEnergy collects the daily charged energy

func (*Connection) CheckErrorCode

func (d *Connection) CheckErrorCode(errorCode int) error

func (*Connection) CurrentPower

func (d *Connection) CurrentPower() (float64, error)

CurrentPower provides current power consuption

func (*Connection) DoSecureRequest

func (d *Connection) DoSecureRequest(uri string, taporequest map[string]interface{}) (*DeviceResponse, error)

DoSecureRequest executes a Tapo device request by encding the request and decoding its response.

func (*Connection) ExecCmd

func (d *Connection) ExecCmd(method string, enable bool) (*DeviceResponse, error)

ExecCmd executes a Tapo api command and provides the response

func (*Connection) ExecMethod

func (d *Connection) ExecMethod(method string, deviceOn bool) (*DeviceResponse, error)

ExecMethod executes a Tapo device command method and provides the corresponding response.

func (*Connection) Handshake

func (d *Connection) Handshake() error

Handshake provides the Tapo device session cookie and encryption cipher.

func (*Connection) Login

func (d *Connection) Login() error

Login provides the Tapo device session token and MAC address (TerminalUUID).

type ConnectionCipher

type ConnectionCipher struct {
	Key []byte
	Iv  []byte
}

Tapo connection cipher

func (*ConnectionCipher) Decrypt

func (c *ConnectionCipher) Decrypt(payload []byte) ([]byte, error)

func (*ConnectionCipher) Encrypt

func (c *ConnectionCipher) Encrypt(payload []byte) ([]byte, error)

type DeviceResponse

type DeviceResponse struct {
	Result 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"`
		Specs              string `json:"specs"`
		DeviceON           bool   `json:"device_on"`
		OnTime             int64  `json:"on_time"`
		OverHeated         bool   `json:"overheated"`
		Nickname           string `json:"nickname"`
		Location           string `json:"location"`
		Avatar             string `json:"avatar"`
		Longitude          int64  `json:"longitude"`
		Latitude           int64  `json:"latitude"`
		HasSetLocationInfo bool   `json:"has_set_location_info"`
		IP                 string `json:"ip"`
		SSID               string `json:"ssid"`
		SignalLevel        int64  `json:"signal_level"`
		RSSI               int64  `json:"rssi"`
		Region             string `json:"Europe/Kiev"`
		TimeDiff           int64  `json:"time_diff"`
		Lang               string `json:"lang"`
		Key                string `json:"key"`
		Response           string `json:"response"`
		Token              string `json:"token"`
		Current_Power      int64  `json:"current_power"`
		Today_Energy       int64  `json:"today_energy"`
	} `json:"result"`
	ErrorCode int `json:"error_code"`
}

Tapo device response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL