Example #1
0
func (a *Action) doGradient(setter Setter, lights []int, e *tasks.Execution) {
	startTime := e.Now()
	var currentD time.Duration
	var properties gohue.LightProperties
	if a.On {
		properties.On.Set(true)
	}
	idx := 1
	last := &a.G.Cds[len(a.G.Cds)-1]
	for idx < len(a.G.Cds) {
		if currentD >= a.G.Cds[idx].D {
			idx++
			continue
		}
		first := &a.G.Cds[idx-1]
		second := &a.G.Cds[idx]
		ratio := float64(currentD-first.D) / float64(second.D-first.D)
		acolor := maybeBlendColor(first.C, second.C, ratio)
		aBrightness := maybeBlendBrightness(first.Bri, second.Bri, ratio)
		properties.C = acolor
		properties.Bri = aBrightness
		multiSet(e, setter, lights, &properties)
		properties.On.Clear()
		if e.Error() != nil {
			return
		}
		if !e.Sleep(a.G.Refresh) {
			return
		}
		currentD = e.Now().Sub(startTime)
	}
	properties.C = last.C
	properties.Bri = last.Bri
	multiSet(e, setter, lights, &properties)
}
Example #2
0
func (ft *fakeTask) Do(e *tasks.Execution) {
	ft.timeStamps = append(ft.timeStamps, e.Now())
	if ft.err != nil {
		e.SetError(ft.err)
	}
	if ft.runDuration > 0 {
		e.Sleep(ft.runDuration)
	}
	ft.timesRun++
}
Example #3
0
func multiSet(
	e *tasks.Execution,
	setter Setter,
	lights []int,
	properties *gohue.LightProperties) {
	if len(lights) == 0 {
		if resp, err := setter.Set(0, properties); err != nil {
			e.SetError(fixError(0, resp, err))
			return
		}
	} else {
		for _, light := range lights {
			if light == 0 {
				e.SetError(fixError(0, kInvalidLightIdBytes, gohue.NoSuchResourceError))
				return
			}
			if resp, err := setter.Set(light, properties); err != nil {
				e.SetError(fixError(light, resp, err))
				return
			}
		}
	}
}
Example #4
0
func (ft *fakeTask2) Do(e *tasks.Execution) {
	ft.Starting <- true
	e.Sleep(ft.runDuration)
}