velux-cli/move.go

53 lines
1.3 KiB
Go
Raw Permalink Normal View History

package main
import "fmt"
import "encoding/json"
2019-08-11 21:13:44 +02:00
import "github.com/nougad/velux-cli/models"
import "github.com/nougad/velux-cli/client/operations"
2019-08-11 20:47:16 +02:00
import "github.com/go-openapi/swag"
2019-08-11 20:47:16 +02:00
func Move(state *State, shutters []string, position int64) {
fmt.Printf("Moving shutters: %+v to %+v\n", shutters, position)
if len(shutters) == 0 {
return
}
2019-08-11 20:47:16 +02:00
var updates []*models.ModulePercentage
for _, x := range shutters {
2019-08-11 20:47:16 +02:00
m := &models.ModulePercentage{
Bridge: state.ModuleStatus[state.ModuleForName[x]].Bridge,
2019-08-11 20:47:16 +02:00
ID: state.ModuleForName[x],
TargetPosition: swag.Int64(position),
}
updates = append(updates, m)
}
2019-08-11 20:47:16 +02:00
param := operations.NewSetStateParams()
param.WithBody(&models.SetState{
Home: &models.SetStateHome{
ID: swag.String(state.HomeId),
Modules: updates,
},
2019-08-11 20:47:16 +02:00
})
2019-08-11 20:47:16 +02:00
fmt.Printf("> request: %+v\n", param.Body)
fmt.Printf("> request: %+v\n", param.Body.Home)
fmt.Printf("> request: %+v\n", param.Body.Home.Modules)
j, err := json.Marshal(param)
if err != nil {
panic(err)
}
fmt.Printf("> request: %+v\n", string(j))
2019-08-11 20:47:16 +02:00
response, err := state.Api.Operations.SetState(param, state.Auth)
if err != nil {
panic(err)
}
j, err = json.Marshal(response)
if err != nil {
panic(err)
}
fmt.Printf("> response: %+v\n", string(j))
}