tuyaslim

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: MIT Imports: 13 Imported by: 0

README

tuyaslim

For usage, see tuya_test.go or docs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	AccessToken  string `json:"access_token"`
	ExpireTime   int    `json:"expire_time"`
	RefreshToken string `json:"refresh_token"`
	Uid          string `json:"uid"`
	// contains filtered or unexported fields
}

type Client

type Client struct {
	ClientId     string
	ClientSecret string
	AccessToken  *AccessToken
	Host         string // defaults to "https://openapi.tuyacn.com"
}

func NewClient

func NewClient(id, secret string) *Client

Create new client.

func (*Client) Execute

func (client *Client) Execute(ctx context.Context, deviceId string, commands ...interface{}) error

Execute executes a command for a device given device ID.

func (*Client) GetDevices

func (client *Client) GetDevices(ctx context.Context) (devices Devices, err error)

GetDevices returns all devices.

func (*Client) GetStatuses added in v1.0.1

func (client *Client) GetStatuses(ctx context.Context, ids ...string) (devices []DeviceIdAndStatus, err error)

GetStatuses returns statuses of given devices. You should provide at least one device and at most 20 devices.

func (*Client) GetToken

func (client *Client) GetToken(ctx context.Context) error

GetToken updates client.AccessToken.

func (*Client) Request

func (client *Client) Request(ctx context.Context, method, path string, body interface{}, targets ...interface{}) (err error)

Request makes a new request given a method, URL, and optional body, parses the JSON response and stores the result in the value pointed to by the optional targets. Error is returned if network has connectivity problem or server responded an error.

type Device

type Device struct {
	Id        string   `json:"id"`
	Category  string   `json:"category"`
	IpAddress string   `json:"ip"`
	Name      string   `json:"name"`
	Online    bool     `json:"online"`
	Statuses  Statuses `json:"status"`
	CreatedAt Time     `json:"create_time"`
	UpdatedAt Time     `json:"update_time"`
}

type DeviceIdAndStatus added in v1.0.1

type DeviceIdAndStatus struct {
	Id       string   `json:"id"`
	Statuses Statuses `json:"status"`
}

type Devices added in v1.0.1

type Devices []Device

func (Devices) Ids added in v1.0.1

func (devices Devices) Ids() (ids []string)

type Statuses

type Statuses map[string]interface{}

func (*Statuses) UnmarshalJSON

func (s *Statuses) UnmarshalJSON(data []byte) error

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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