package main
import (
"log"
"os"
"github.com/lsongdev/miservice-go/miservice"
)
func main() {
client := miservice.NewClient(
os.Getenv("MI_USERNAME"),
os.Getenv("MI_PASSWORD"),
)
- HomeRequest
- HomeDeviceList
- HomeGetProps
- HomeSetProps
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)
}
- MiotGetProps
- MiotSetProps
- 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{})
}
- MinaRequest
- ListMinaDevices
- RemoteUbusCall
devices, _ := client.ListMinaDevices(1)
for _, device := range devices {
log.Println(device.Name, device.DeviceID)
}
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)