forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temperature.go
29 lines (24 loc) · 817 Bytes
/
temperature.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cmd
import (
"strconv"
"github.com/spf13/cobra"
)
var temperatureCmd = &cobra.Command{
Use: "temperature [value in °C] [device names]",
Short: "Set the temperature of HKR devices",
Long: "Change the temperature of one or more HKR devices.",
Example: "fritzctl temperature 21.0 HKR_1 HKR_2",
RunE: changeTemperature,
}
func init() {
RootCmd.AddCommand(temperatureCmd)
}
func changeTemperature(cmd *cobra.Command, args []string) error {
assertStringSliceHasAtLeast(args, 2, "insufficient input: at least two parameters expected.")
temp, errorParse := strconv.ParseFloat(args[0], 64)
assertNoError(errorParse, "cannot parse temperature value:", errorParse)
c := homeAutoClient()
err := c.Temp(temp, args[1:]...)
assertNoError(err, "error setting temperature:", err)
return nil
}