hyperion-ng is library that helps communicate with Hyperion-NG JSON API.
go get -u github.com/denwwer/hyperion-ng
import (
"log"
"github.com/denwwer/hyperion-ng"
"github.com/denwwer/hyperion-ng/model"
)
func main() {
// Create configuration
conf := hyperion.Config{
VerboseLog: false,
Connection: hyperion.Connection{
Token: "6c224a4c-6ebf-491a-9d70-fb7681ca2a59",
Type: hyperion.ConnectHTTP,
Host: "192.168.53.130",
Port: 8090,
SSL: false,
Timeout: 10,
},
}
// Create client with custom header options
cl := hyperion.NewClient(conf, hyperion.WithHeader(map[string]string{"my-header": "value"}))
// Get full information
info, err := cl.ServerInfo()
if err != nil {
log.Panic(err)
}
// Manage Instances
for _, instance := range info.Instances {
log.Printf(`name: "%s" active: %t`, instance.Name, instance.Running)
err = cl.Instance(instance.Instance, model.InstanceCmdStop)
if err != nil {
log.Fatalln(err)
}
}
// Manage Components
for _, comp := range info.Components {
if comp.Switchable() {
err = cl.ComponentState(comp.Name, false)
if err != nil {
log.Fatalln(err)
}
}
}
// List user defined effects
for _, effect := range info.Effects.Users() {
log.Printf(`name: "%s"`, effect.Name)
}
// Change video mode
err = cl.VideoMode(model.VideoMode2D)
if err != nil {
log.Fatalln(err)
}
}
Additional doumentation on pkg.go.dev