Ejemplo n.º 1
0
func TestSetGroup(t *testing.T) {
	fmt.Println("groups.SetGroup()")
	portal := portal.GetPortal()
	hostname := portal[0].InternalIpAddress
	gg := NewGroup(hostname, username_api_key)
	// office!
	group_id := 1
	group := Group{Name: "Office", Lights: []string{"1", "2"}}
	data := gg.SetGroup(group_id, group)
	fmt.Println(data)
	// bedroom!
	group_id = 2
	group = Group{Name: "Bedroom", Lights: []string{"3", "4"}}
	data = gg.SetGroup(group_id, group)
	fmt.Println(data)
	// living room!
	group_id = 3
	group = Group{Name: "Living Room", Lights: []string{"5", "6"}}
	data = gg.SetGroup(group_id, group)
	fmt.Println(data)
	// upstairs!
	group_id = 4
	group = Group{Name: "Upstairs", Lights: []string{"1", "2", "3", "4", "5", "6", "8"}}
	data = gg.SetGroup(group_id, group)
	fmt.Println(data)
}
Ejemplo n.º 2
0
func TestGetLight(t *testing.T) {
	fmt.Println("lights.GetLight()")
	portal := portal.GetPortal()
	lll := NewLights(portal[0].InternalIpAddress, username_api_key)
	for _, light_id := range test_lights {
		light := lll.GetLight(light_id)
		print_light_state(light)
	}
}
Ejemplo n.º 3
0
func TestGetGroup(t *testing.T) {
	fmt.Println("groups.GetGroup()")
	portal := portal.GetPortal()
	hostname := portal[0].InternalIpAddress
	gg := NewGroup(hostname, username_api_key)
	for _, group_id := range test_groups {
		group := gg.GetGroup(group_id)
		print_group_state(group)
	}
}
Ejemplo n.º 4
0
func TestGetAllLights(t *testing.T) {
	fmt.Println("lights.GetAllLights()")
	portal := portal.GetPortal()
	lll := NewLights(portal[0].InternalIpAddress, username_api_key)
	lights := lll.GetAllLights()
	fmt.Println("\tLights: ")
	for _, lll := range lights {
		fmt.Println("\t\tId:   ", lll.Id)
		fmt.Println("\t\tName: ", lll.Name)
		fmt.Println("\t\t------")
	}
}
Ejemplo n.º 5
0
func TestGetGroups(t *testing.T) {
	fmt.Println("groups.GetGroups()")
	portal := portal.GetPortal()
	hostname := portal[0].InternalIpAddress
	ggg := NewGroup(hostname, username_api_key)
	groups := ggg.GetGroups()
	fmt.Println("\tGroups: ")
	for _, gg := range groups {
		fmt.Println("\t\tId:   ", gg.Id)
		fmt.Println("\t\tName: ", gg.Name)
		fmt.Println("\t\t------")
	}
}
Ejemplo n.º 6
0
func TestRenameLight(t *testing.T) {
	fmt.Println("lights.RenameLight()")
	portal := portal.GetPortal()
	lll := NewLights(portal[0].InternalIpAddress, username_api_key)
	light_id := 1
	light_before := lll.GetLight(light_id)
	fmt.Println("\t [BEFORE] Name:   ", light_before.Name)
	resp := lll.RenameLight(light_id, "Testing 123")
	fmt.Println(resp[0].Success)
	light_after := lll.GetLight(light_id)
	fmt.Println("\t [AFTER] Name:    ", light_after.Name)
	resp = lll.RenameLight(light_id, light_before.Name)
	fmt.Println(resp[0].Success)
}
Ejemplo n.º 7
0
func main() {
	if config_filename != "" {
		k := key.New(config_filename)
		portal := portal.GetPortal()
		ll := lights.NewLights(portal[0].InternalIpAddress, k.Username)
		lights := ll.GetAllLights()
		fmt.Println("All Lights: ")
		for _, l := range lights {
			light := ll.GetLight(l.Id)
			print_light(light)
		}
	} else {
		usage()
	}
}
Ejemplo n.º 8
0
func TestSetLightState(t *testing.T) {
	fmt.Println("lights.SetLightState()")
	portal := portal.GetPortal()
	lll := NewLights(portal[0].InternalIpAddress, username_api_key)
	lights_before := make([]Light, len(test_lights))
	// save current state.
	fmt.Println("\n\nBACKING UP original state ...")
	for _, light_id := range test_lights {
		ls := lll.GetLight(light_id)
		lights_before = append(lights_before, ls)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))
	// lets turn them red!
	fmt.Println("\n\nRED ...")
	red := State{On: true, Hue: 65527, Effect: "none", Bri: 13, Sat: 253, Ct: 500, Xy: []float32{0.6736, 0.3221}, Alert: "none", TransitionTime: transition_time}
	for _, light_id := range test_lights {
		r := lll.SetLightState(light_id, red)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))
	// lets turn them blue!
	fmt.Println("\n\nBLUE ...")
	blue := State{On: true, Hue: 46573, Effect: "none", Bri: 254, Sat: 251, Ct: 500, Xy: []float32{0.1754, 0.0556}, Alert: "none", TransitionTime: transition_time}
	for _, light_id := range test_lights {
		r := lll.SetLightState(light_id, blue)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them white!
	fmt.Println("\n\nWHITE ...")
	white := State{On: true, Hue: 34495, Effect: "none", Bri: 203, Sat: 232, Ct: 155, Xy: []float32{0.3151, 0.3252}, Alert: "none", TransitionTime: transition_time}
	for _, light_id := range test_lights {
		r := lll.SetLightState(light_id, white)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them off!
	fmt.Println("\n\nOFF ...")
	off := State{On: false, Hue: 34495, Effect: "none", Bri: 203, Sat: 232, Ct: 155, Xy: []float32{0.3151, 0.3252}, Alert: "none", TransitionTime: 4}
	for _, light_id := range test_lights {
		r := lll.SetLightState(light_id, off)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets RESTORE
	fmt.Println("\n\nRESTORING original state ...")
	for _, llll := range lights_before {
		if llll.Id == 0 {
			continue
		}
		original_state := redo_state(llll.State)
		r := lll.SetLightState(llll.Id, original_state)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	fmt.Println("Fin.\n\n")
}
Ejemplo n.º 9
0
func TestSetGroupState(t *testing.T) {
	fmt.Println("groups.SetGroupState()")
	portal := portal.GetPortal()
	hostname := portal[0].InternalIpAddress
	gg := NewGroup(hostname, username_api_key)
	_test_groups := []int{3}
	groups_before := make([]GroupState, len(_test_groups))
	// save current state.
	fmt.Println("\n\nBACKING UP original state ...")
	for _, group_id := range _test_groups {
		gs := gg.GetGroup(group_id)
		groups_before = append(groups_before, gs)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))
	// lets turn them virgin america!
	fmt.Println("\n\nVirgin America ...")
	virgin_america := lights.State{On: true, Hue: 54179, Effect: "none", Bri: 230, Sat: 253, Ct: 223, Xy: []float32{0.3621, 0.1491}, Alert: "none", TransitionTime: transition_time}
	for _, group_id := range _test_groups {
		r := gg.SetGroupState(group_id, virgin_america)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them off!
	fmt.Println("\n\nOFF ...")
	off := lights.State{On: false}
	for _, group_id := range _test_groups {
		r := gg.SetGroupState(group_id, off)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them on!
	fmt.Println("\n\nON ...")
	on := lights.State{On: true}
	for _, group_id := range _test_groups {
		r := gg.SetGroupState(group_id, on)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them blue!
	fmt.Println("\n\nBLUE ...")
	blue := lights.State{On: true, Hue: 46573, Effect: "none", Bri: 254, Sat: 251, Ct: 500, Xy: []float32{0.1754, 0.0556}, Alert: "none", TransitionTime: transition_time}
	for _, group_id := range _test_groups {
		r := gg.SetGroupState(group_id, blue)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets turn them white!
	fmt.Println("\n\nWHITE ...")
	white := lights.State{On: true, Hue: 34495, Effect: "none", Bri: 203, Sat: 232, Ct: 155, Xy: []float32{0.3151, 0.3252}, Alert: "none", TransitionTime: transition_time}
	for _, group_id := range _test_groups {
		r := gg.SetGroupState(group_id, white)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	time.Sleep(time.Second * time.Duration(sleep_seconds))

	// lets RESTORE
	fmt.Println("\n\nRESTORING original state ...")
	time.Sleep(time.Second * time.Duration(sleep_seconds))
	for _, gggg := range groups_before {
		if gggg.Id == 0 {
			continue
		}
		original_state := redo_state(gggg.Action)
		r := gg.SetGroupState(gggg.Id, original_state)
		fmt.Println(r)
		time.Sleep(time.Millisecond * time.Duration(sleep_ms))
	}
	fmt.Println("Fin.\n\n")
}