Example #1
0
func createCmd() {
	connection := &common.Connection{
		Host:    ip,
		Verbose: internal.Verbose,
	}
	create := &config.Create{
		DeviceType: "ghue" + common.VERSION,
	}

	createResult, errHUE, err := config.CreateAPI(connection, create)
	internal.CheckErrors(err, errHUE)

	output, err := json.Marshal(createResult)
	internal.Check(err)

	if save {
		ghueFile := &GHUEFile{
			Host:     connection.Host,
			Username: createResult.Success.Username,
			Version:  common.VERSION,
		}
		jsonStr, err := json.MarshalIndent(ghueFile, "", "  ")
		internal.Check(err)
		jsonStr = append(jsonStr, '\n')
		dir := path.Dir(ConfigFile)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			internal.Check(os.Mkdir(dir, 0740))
		}
		internal.Check(ioutil.WriteFile(ConfigFile, jsonStr, 0600))
		fmt.Printf("file %s is created\n", ConfigFile)
	}

	fmt.Println(string(output))
}
Example #2
0
func stateCmd(id string) {
	connection := config.ReadConfig()
	setState := &lights.SetStateValues{
		On:             on,
		Alert:          alert,
		Bri:            bri,
		Hue:            hue,
		Sat:            sat,
		XY:             xy,
		Ct:             ct,
		Effect:         effect,
		TransitionTime: transitionTime,
		BriInc:         briInc,
		SatInc:         satInc,
		HueInc:         hueInc,
		CtInc:          ctInc,
		XYInc:          xyInc,
	}
	result, errHUE, err := lights.SetState(connection, id, setState)
	internal.CheckErrors(err, errHUE)

	jsonStr, err := json.MarshalIndent(result, "", "  ")
	internal.Check(err)
	internal.FormatOutputDef(jsonStr)
}
Example #3
0
File: get.go Project: yesnault/ghue
func getCmd(id string) {
	connection := config.ReadConfig()
	result, errHUE, err := rules.GetRule(connection, id)
	internal.CheckErrors(err, errHUE)

	jsonStr, err := json.MarshalIndent(result, "", "  ")
	internal.Check(err)
	internal.FormatOutputDef(jsonStr)
}
Example #4
0
File: all.go Project: yesnault/ghue
func allCmd() {
	connection := config.ReadConfig()
	result, errHUE, err := groups.GetAllGroups(connection)
	internal.CheckErrors(err, errHUE)

	jsonStr, err := json.MarshalIndent(result, "", "  ")
	internal.Check(err)
	internal.FormatOutputDef(jsonStr)
}