func GetLightsBrightness(hueBridge *hue.Hue) (float64, error) { var resp hue.GetLightsResponse err := hueBridge.GetLights(&resp) if err != nil { return 0.0, err } for light, _ := range resp { var lightResp hue.GetLightResponse err := hueBridge.GetLight(light, &lightResp) if err != nil { continue } return float64(lightResp.State.Bri) / 255.0, nil } return 0.0, nil }
func setBrightnessInternal(hueBridge *hue.Hue, onOffState int, brightness float64) error { var resp hue.GetLightsResponse err := hueBridge.GetLights(&resp) if err != nil { return err } var lightRequest hue.PutLightRequest stateOn := onOffState < 1 stateBri := int(math.Max(math.Min(brightness*255, 255), 0)) lightRequest.On = &stateOn lightRequest.Bri = &stateBri for light, _ := range resp { hueBridge.PutLight(light, &lightRequest) } return nil }
func AreLightsOn(hueBridge *hue.Hue) (bool, error) { var resp hue.GetLightsResponse err := hueBridge.GetLights(&resp) if err != nil { return false, err } for light, _ := range resp { var lightResp hue.GetLightResponse err := hueBridge.GetLight(light, &lightResp) if err != nil { continue } if lightResp.State.On { return true, nil } } return false, nil }