Skip to content

Latest commit

 

History

History
105 lines (81 loc) · 1.97 KB

README.md

File metadata and controls

105 lines (81 loc) · 1.97 KB

XiaoMi Cloud Service

package main

import (
  "log"
  "os"

  "github.com/lsongdev/miservice-go/miservice"
)

func main() {
  client := miservice.NewClient(
    os.Getenv("MI_USERNAME"),
    os.Getenv("MI_PASSWORD"),
  )

[repo]/miservice/miio.go

MiioRequest

HomeDeviceList

devices, err := client.HomeDeviceList(&miservice.DeviceListFilter{
  ShowVirtualModel: true,
  ShowHuamiDevices: 1,
})
if err != nil {
  log.Fatal(err)
}
for _, device := range devices {
  log.Println(device.Name, device.Model, device.Did, device.Token)
}

[repo]/miservice/miot.go

MiotAction

https://miot-spec.org/miot-spec-v2/instances?status=all

func (c *Client) Speak(did, text string) (H, error) {
  return c.MiotAction(did, []int{5, 1}, []any{text})
}

func (c *Client) WakeUp(did string) (H, error) {
  return c.MiotAction(did, []int{5, 2}, []any{})
}

func (c *Client) PlayRadio(did string) (H, error) {
  return c.MiotAction(did, []int{5, 3}, []any{})
}

func (c *Client) PlayMusic(did string) (H, error) {
  return c.MiotAction(did, []int{5, 4}, []any{})
}

[repo]/miservice/mina.go

ListMinaDevices

devices, _ := client.ListMinaDevices(1)
for _, device := range devices {
  log.Println(device.Name, device.DeviceID)
}

RemoteUbusCall

func (c *Client) TextToSpeech(deviceId, text string) (out H, err error) {
  out = make(map[string]any)
  err = c.RemoteUbusCall(deviceId, "mibrain.text_to_speech", H{"text": text}, out)
  return
}
did := "f1801b9f-0034-4153-bbf6-6b6453668c26"
client.PlayerSetVolume(did, 30)
resp, err := client.TextToSpeech(did, "你好,我是小爱")
if err != nil {
  log.Fatal(err)
}
log.Println(resp)