Ejemplo n.º 1
0
// NewSwitch returns a switch which implements model.Switch.
func NewSwitch(info model.Info) *switcher {
	accessory := New(info)
	s := service.NewSwitch(info.Name, false) // off

	accessory.AddService(s.Service)

	sw := switcher{accessory, s}

	return &sw
}
Ejemplo n.º 2
0
// NewSwitch returns a switch which implements model.Switch.
func NewSwitch(info model.Info) *switcher {
	accessory := New(info)
	s := service.NewSwitch(info.Name, false) // off

	accessory.AddService(s.Service)

	sw := switcher{accessory, s, nil}

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

	return &sw
}