Skip to content

Commit

Permalink
feat: add the command getSchema
Browse files Browse the repository at this point in the history
This command is handy to retrieve the schema used on the device. This
provides the information about the available parameters and the minimum
and maximum value ranges. As well as their defaults.

Signed-off-by: Christian Ege <[email protected]>
  • Loading branch information
graugans committed Aug 9, 2023
1 parent a4c2db7 commit 2b526af
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/ovp8xx/cmd/getSchema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright © 2023 Christian Ege <[email protected]>
*/
package cmd

import (
"fmt"

"github.com/graugans/go-ovp8xx/pkg/ovp8xx"
"github.com/spf13/cobra"
)

func getSchemaCommand(cmd *cobra.Command, args []string) error {

host, err := rootCmd.PersistentFlags().GetString("ip")
if err != nil {
return err
}

o3r := ovp8xx.NewClient(
ovp8xx.WithHost(host),
)

if result, err := o3r.GetSchema(); err != nil {
return err
} else {
fmt.Printf("%s\n", result)
}
return nil
}

// getCmd represents the get command
var getSchemaCmd = &cobra.Command{
Use: "getSchema",
Short: "Retrieve the currently used JSON schema from the device",
RunE: getSchemaCommand,
}

func init() {
rootCmd.AddCommand(getSchemaCmd)
}
17 changes: 17 additions & 0 deletions pkg/ovp8xx/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,20 @@ func (device *Client) FactoryReset(keepNetworkSettings bool) error {
}
return client.Call("factoryReset", arg, nil)
}

func (device *Client) GetSchema() (string, error) {
client, err := xmlrpc.NewClient(device.url)
if err != nil {
return "", err
}
defer client.Close()

result := &struct {
JSON string
}{}

if err := client.Call("getSchema", nil, result); err != nil {
return "", err
}
return result.JSON, nil
}

0 comments on commit 2b526af

Please sign in to comment.