예제 #1
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)
	}
}
예제 #2
0
func updateHaColors(light common.Light, haLight model.LightBulb) (err error) {
	color, err := light.GetColor()

	if err != nil {
		log.WithField(`error`, err).Error(`Getting color state of light`)
		return err
	}

	hue := color.Hue
	saturation := color.Saturation
	brightness := color.Brightness
	convertedHue := float64(hue) * 360 / math.MaxUint16
	convertedSaturation := float64(saturation) * 100 / math.MaxUint16
	convertedBrightness := int(brightness) * 100 / math.MaxUint16

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

	haLight.SetHue(convertedHue)
	haLight.SetSaturation(convertedSaturation)
	haLight.SetBrightness(convertedBrightness)

	return nil
}