Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI support for new Green LED APIs #423

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions cmd/os_boards_green.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"fmt"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var osBoardsGreenCmd = &cobra.Command{
Use: "green",
Aliases: []string{"grn"},
Short: "See or change settings of the current Green board",
Long: `
This command allows you to see or change settings of the Green board that Home
Assistant is running on.`,
Example: `
ha os boards green`,
ValidArgsFunction: cobra.NoFileCompletions,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("os boards green")

section := "os"
command := "boards/green"

resp, err := helper.GenericJSONGet(section, command)
if err != nil {
fmt.Println(err)
ExitWithError = true
} else {
ExitWithError = !helper.ShowJSONResponse(resp)
}
},
}

func init() {
osBoardsCmd.AddCommand(osBoardsGreenCmd)
}
61 changes: 61 additions & 0 deletions cmd/os_boards_green_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmd

import (
"fmt"
"strings"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var osBoardsGreenOptionsCmd = &cobra.Command{
Use: "options",
Aliases: []string{"option", "opt", "opts", "op"},
Short: "Change settings of the current Green board",
Long: `
This command allows you to change settings of the Green board that Home
Assistant is running on. A host reboot is required for changes to take effect.`,
Example: `
ha os boards green options --activity-led=false`,
ValidArgsFunction: cobra.NoFileCompletions,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("os boards green options")

section := "os"
command := "boards/green"

options := make(map[string]interface{})

for _, value := range []string{
"activity-led",
"power-led",
"user-led",
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved
} {
data, err := cmd.Flags().GetBool(value)
if err == nil && cmd.Flags().Changed(value) {
options[strings.Replace(value, "-", "_", -1)] = data
}
}

resp, err := helper.GenericJSONPost(section, command, options)
if err != nil {
fmt.Println(err)
ExitWithError = true
} else {
ExitWithError = !helper.ShowJSONResponse(resp)
}
},
}

func init() {
osBoardsGreenOptionsCmd.Flags().Bool("activity-led", true, "Enable/disable the activity LED")
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved
osBoardsGreenOptionsCmd.Flags().Bool("power-led", true, "Enable/disable the power LED")
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved
osBoardsGreenOptionsCmd.Flags().Bool("user-led", true, "Enable/disable the user LED")
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved
osBoardsGreenOptionsCmd.Flags().Lookup("activity-led").NoOptDefVal = "true"
osBoardsGreenOptionsCmd.Flags().Lookup("power-led").NoOptDefVal = "true"
osBoardsGreenOptionsCmd.Flags().Lookup("user-led").NoOptDefVal = "true"
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved

osBoardsGreenCmd.AddCommand(osBoardsGreenOptionsCmd)
}