func TestGetConfiguration(t *testing.T) {
	portal := portal.GetPortal()
	fmt.Println("configuration.GetConfiguration()")
	for i := range portal {
		p := portal[i]
		h := NewConfiguration(p.InternalIpAddress)
		c := h.GetConfiguration(username_api_key)
		fmt.Printf("\tName:         %s\n", c.Name)
		fmt.Printf("\tUtc:          %s\n", c.Utc)
		fmt.Printf("\tSwVersion:    %s\n", c.SwVersion)
		fmt.Printf("\tProxyAddress: %s\n", c.ProxyAddress)
		fmt.Printf("\tProxyPort:    %d\n", c.ProxyPort)
		fmt.Printf("\tMac:          %s\n", c.Mac)
		fmt.Printf("\tLinkButton:   %t\n", c.LinkButton)
		fmt.Printf("\tIpAddress:    %s\n", c.IpAddress)
		fmt.Printf("\tNetMask:      %s\n", c.NetMask)
		fmt.Printf("\tGateway:      %s\n", c.Gateway)
		fmt.Printf("\tDhcp:         %t\n", c.Dhcp)
		fmt.Printf("\tSwUpdate:\n")
		fmt.Printf("\t\tUpdateState: %d\n", c.SwUpdate.UpdateState)
		fmt.Printf("\t\tUrl:         %s\n", c.SwUpdate.Url)
		fmt.Printf("\t\tText:        %s\n", c.SwUpdate.Text)
		fmt.Printf("\t\tNotify:      %t\n", c.SwUpdate.Notify)
		fmt.Printf("\tWhitelist:\n")
		for j := range c.Whitelist {
			fmt.Printf("\t\tKey: %s\n", j)
			fmt.Printf("\t\t\tLastUseDate: %s\n", c.Whitelist[j].LastUseDate)
			fmt.Printf("\t\t\tCreateDate:  %s\n", c.Whitelist[j].CreateDate)
			fmt.Printf("\t\t\tName:        %s\n", c.Whitelist[j].Name)
		}
		t.Log(p.InternalIpAddress)
	}
}
Beispiel #2
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)
}
func TestGetFullState(t *testing.T) {
	fmt.Println("configuration.GetFullState()")
	portal := portal.GetPortal()
	ccc := NewConfiguration(portal[0].InternalIpAddress)
	response := ccc.GetFullState(username_api_key)
	fmt.Println(response)
}
func TestDeleteUser(t *testing.T) {
	fmt.Println("configuration.DeleteUser()")
	portal := portal.GetPortal()
	ccc := NewConfiguration(portal[0].InternalIpAddress)
	response := ccc.DeleteUser(username_api_key, "ae2b1fca515949e5d54fb22b8ed95575")
	fmt.Println("\t", response[0])
}
func TestCreateUser(t *testing.T) {
	fmt.Println("configuration.CreateUser()")
	portal := portal.GetPortal()
	ccc := NewConfiguration(portal[0].InternalIpAddress)
	response := ccc.CreateUser("go-hue-user", "go-lang-test")
	fmt.Println("\t", response[0])
}
Beispiel #6
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)
	}
}
Beispiel #7
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)
	}
}
Beispiel #8
0
func main() {
	if config_filename != "" {
		k := key.New(config_filename)
		username_api_key = k.Username
		portal := portal.GetPortal()
		hue_hostname = portal[0].InternalIpAddress
		web_start()
	} else {
		usage()
	}
}
Beispiel #9
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------")
	}
}
Beispiel #10
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------")
	}
}
Beispiel #11
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)
}
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()
	}
}
Beispiel #13
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")
}
Beispiel #14
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")
}