https://github.com/lsongdev/miservice-go
:cloud: XiaoMi Cloud Service
https://github.com/lsongdev/miservice-go
Last synced: 7 months ago
JSON representation
:cloud: XiaoMi Cloud Service
- Host: GitHub
- URL: https://github.com/lsongdev/miservice-go
- Owner: lsongdev
- Created: 2024-11-26T12:37:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-27T15:04:11.000Z (over 1 year ago)
- Last Synced: 2024-12-31T10:05:29.757Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# XiaoMi Cloud Service
```go
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](./miservice/miio.go)*
#### MiioRequest
+ HomeRequest
+ [HomeDeviceList](#homedevicelist)
+ HomeGetProps
+ HomeSetProps
#### HomeDeviceList
```go
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](./miservice/miot.go)*
+ MiotGetProps
+ MiotSetProps
+ [MiotAction](#miotaction)
#### MiotAction
```go
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](./miservice/mina.go)*
+ MinaRequest
+ [ListMinaDevices](#listminadevices)
+ [RemoteUbusCall](#remoteubuscall)
#### ListMinaDevices
```go
devices, _ := client.ListMinaDevices(1)
for _, device := range devices {
log.Println(device.Name, device.DeviceID)
}
```
#### RemoteUbusCall
```go
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
}
```
```go
did := "f1801b9f-0034-4153-bbf6-6b6453668c26"
client.PlayerSetVolume(did, 30)
resp, err := client.TextToSpeech(did, "你好,我是小爱")
if err != nil {
log.Fatal(err)
}
log.Println(resp)
```