Пример #1
0
func turn(hub *huego.Hub, args []string) {
	status, err := hub.Status()
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	name := args[2]
	if sw := status.FindSwitchable(name); sw != nil {
		sw.Switch().State(args[1] == "on").Send()
	} else {
		fmt.Println(name, " not found")
	}
}
Пример #2
0
func temp(hub *huego.Hub, args []string) {
	status, err := hub.Status()
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	name := args[1]
	temp, err := strconv.ParseInt(args[2], 10, 32)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	if sw := status.FindSwitchable(name); sw != nil {
		sw.Switch().Transition(5).Temperature(int(temp)).Send()
	} else {
		fmt.Println(name, " not found")
	}
}
Пример #3
0
func list(hub *huego.Hub, args []string) {
	status, err := hub.Status()
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	switch args[1] {
	case "lights":
		for _, light := range status.Lights {
			fmt.Println(light)
		}
	case "groups":
		for _, group := range status.Groups {
			fmt.Println(group)
		}
	default:
		fmt.Println("lights|groups")
	}
}
Пример #4
0
func colour(hub *huego.Hub, args []string) {
	status, err := hub.Status()
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	name := args[1]
	hue, err := strconv.ParseInt(args[2], 10, 32)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	sat, err := strconv.ParseInt(args[3], 10, 32)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	if sw := status.FindSwitchable(name); sw != nil {
		sw.Switch().Transition(5).Colour(int(hue), int(sat)).Send()
	} else {
		fmt.Println(name, " not found")
	}
}