示例#1
0
func updateLightColors(light common.Light, haLight model.LightBulb) {
	// HAP: [0...360]
	// LIFX: [0...MAX_UINT16]
	hue := haLight.GetHue()
	convertedHue := uint16(math.MaxUint16 * float64(hue) / 360)

	// HAP: [0...100]
	// LIFX: [0...MAX_UINT16]
	saturation := haLight.GetSaturation()
	convertedSaturation := uint16(math.MaxUint16 * float64(saturation) / 100)

	// HAP: [0...100]
	// LIFX: [0...MAX_UINT16]
	brightness := haLight.GetBrightness()
	convertedBrightness := uint16(math.MaxUint16 * int(brightness) / 100)

	// HAP: ?
	// LIFX: [2500..9000]
	kelvin := HSBKKelvinDefault

	log.Infof("[updateLightColors] Hue: %s => %s, Saturation: %s => %s, Brightness: %s => %s", hue, convertedHue, saturation, convertedSaturation, brightness, convertedBrightness)

	color := common.Color{
		Hue:        convertedHue,
		Saturation: convertedSaturation,
		Brightness: convertedBrightness,
		Kelvin:     kelvin,
	}

	light.SetColor(color, 1*time.Second)
}
示例#2
0
func TestLightBulb(t *testing.T) {
	info := model.Info{
		Name:         "My Light Bulb",
		SerialNumber: "001",
		Manufacturer: "Google",
		Model:        "Switchy",
	}

	var bulb model.LightBulb = NewLightBulb(info)

	if is, want := bulb.GetBrightness(), 100; is != want {
		t.Fatalf("is=%v want=%v", is, want)
	}

	bulb.SetBrightness(90)

	if is, want := bulb.GetBrightness(), 90; is != want {
		t.Fatalf("is=%v want=%v", is, want)
	}
}