Example #1
0
// NewLightBulb returns a light bulb which implements model.LightBulb.
func NewLightBulb(info model.Info) *lightBulb {
	accessory := New(info)
	bulb := service.NewLightBulb(info.Name, false) // off

	accessory.AddService(bulb.Service)

	lightBulb := lightBulb{accessory, bulb, nil, nil, nil, nil}

	bulb.On.OnConnChange(func(conn net.Conn, c *characteristic.Characteristic, new, old interface{}) {
		if lightBulb.onChanged != nil {
			lightBulb.onChanged(bulb.On.On())
		}
	})

	bulb.Brightness.OnConnChange(func(conn net.Conn, c *characteristic.Characteristic, new, old interface{}) {
		if lightBulb.brightnessChanged != nil {
			lightBulb.brightnessChanged(bulb.Brightness.IntValue())
		}
	})

	bulb.Hue.OnConnChange(func(conn net.Conn, c *characteristic.Characteristic, new, old interface{}) {
		if lightBulb.hueChanged != nil {
			lightBulb.hueChanged(bulb.Hue.FloatValue())
		}
	})

	bulb.Saturation.OnConnChange(func(conn net.Conn, c *characteristic.Characteristic, new, old interface{}) {
		if lightBulb.saturationChanged != nil {
			lightBulb.saturationChanged(bulb.Saturation.FloatValue())
		}
	})

	return &lightBulb
}
Example #2
0
// NewLightBulb returns a light bulb which implements model.LightBulb.
func NewLightBulb(info model.Info) *lightBulb {
	accessory := New(info)
	bulb := service.NewLightBulb(info.Name, false) // off

	accessory.AddService(bulb.Service)

	return &lightBulb{accessory, bulb}
}