du

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 9 Imported by: 0

README

小度控制

使用小度控制其他设备,只实现简单的获取设备信息和控制设备。

EXAMPLES

import "github.com/ivershuo/jaatsh/du"

// 以下信息自行通过抓包获取
const (
 cid   = "your cid"
 cuid  = "your cuid"
 bdid  = "your bdid"
 bduss = "your bduss"
)
xiaodu :=  du.NewDu(cid, cuid, bdid, bduss)

// 加载一个设备。appliance id 可提前抓包配置好或通过 GetDevs() 获取
device := xiaodu.NewDevice("a_appliance_id")

// 发送打开设备指令
err := device.Act("turnOn")

/* 将设备(空调)调至制热模式 */
type payloadMode struct {
 du.CtPayload //嵌套 CtPayload 后可自动添加 appliance 信息
 Mode struct {
   Value string `json:"value"`
 } `json:"mode"`
}

mode := &payloadMode{}
mode.Mode.Value = "HEAT"
err := device.Control("setMode", mode)

Documentation

Index

Constants

View Source
const APIHost = "https://xiaodu.baidu.com/saiya/smarthome"

APIHost 小度接口地址

Variables

This section is empty.

Functions

This section is empty.

Types

type CtPayload

type CtPayload struct {
	App payloadApp `json:"appliance"`
}

CtPayload 控制类 payload

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device 设备

func (*Device) Act

func (dev *Device) Act(action string) error

Act 发送指令。适合除开 applianceId 不需要其他 payload 信息的情况

func (*Device) Control

func (dev *Device) Control(action string, payload interface{}) error

Control 控制

func (*Device) GetInfo

func (dev *Device) GetInfo() (info gjson.Result, err error)

GetInfo 获取设备信息

type Directive

type Directive struct {
	Header  Header      `json:"header"`
	Payload interface{} `json:"payload"`
}

Directive 指令

type Du

type Du struct {
	Debug bool
	// contains filtered or unexported fields
}

Du 小度

func NewDu

func NewDu(cid, cuid, bdid, bduss string) *Du

NewDu 创建小度

func (*Du) Do

func (du *Du) Do(d Directive) error

Do 发送指令

func (*Du) GetDevs

func (du *Du) GetDevs() (map[string]gjson.Result, error)

GetDevs 获取小度已添加的设备信息

func (*Du) NewDevice

func (du *Du) NewDevice(id string) *Device

NewDevice 加载一个小度控制的设备

type Header struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
	Version   int    `json:"payloadVersion"`
}

Header 指令header

Jump to

Keyboard shortcuts

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