Пример #1
0
func main() {
	info := accessory.Info{
		Name:         "Personal Light Bulb",
		Manufacturer: "Matthias",
	}

	acc := accessory.NewLightbulb(info)

	acc.Lightbulb.On.OnValueRemoteUpdate(func(on bool) {
		if on == true {
			turnLightOn()
		} else {
			turnLightOff()
		}
	})

	t, err := hc.NewIPTransport(hc.Config{Pin: "32191123"}, acc.Accessory)
	if err != nil {
		log.Fatal(err)
	}

	hc.OnTermination(func() {
		t.Stop()
	})

	t.Start()
}
Пример #2
0
func main() {
	lights = map[uint64]*HKLight{}

	pinArg := flag.String("pin", "", "PIN used to pair the LIFX bulbs with HomeKit")
	verboseArg := flag.Bool("v", false, "Whether or not log output is displayed")
	transitionArg := flag.Float64("transition-duration", 1, "Transition time in seconds")

	flag.Parse()

	pin = *pinArg

	if *verboseArg {
		log.Debug.Enable()
	}

	transitionDuration = time.Duration(*transitionArg) * time.Second

	hc.OnTermination(func() {
		for _, light := range lights {
			light.transport.Stop()
		}

		time.Sleep(100 * time.Millisecond)
		os.Exit(1)
	})

	Connect()
}
Пример #3
0
func main() {
	switches = map[uint8]*HKSwitch{}
	client = &http.Client{}

	pinArg := flag.String("pin", "", "PIN used to pair the MPower switches with HomeKit")
	configArg := flag.String("config", ".", "Directory where config.json is stored")
	verboseArg := flag.Bool("v", false, "Whether or not log output is displayed")

	flag.Parse()

	pin = *pinArg

	viper.SetConfigName("config")
	viper.AddConfigPath(*configArg)
	viper.ReadInConfig()

	if !*verboseArg {
		log.Info = false
		log.Verbose = false
	}

	hc.OnTermination(func() {
		for _, switcher := range switches {
			switcher.transport.Stop()
		}

		time.Sleep(100 * time.Millisecond)
		os.Exit(1)
	})

	Connect()
}
Пример #4
0
func main() {
	switchInfo := accessory.Info{
		Name: "Lamp",
	}
	acc := accessory.NewSwitch(switchInfo)

	config := hc.Config{Pin: "12344321", Port: "12345", StoragePath: "./db"}
	t, err := hc.NewIPTransport(config, acc.Accessory)

	if err != nil {
		log.Info.Panic(err)
	}

	// Log to console when client (e.g. iOS app) changes the value of the on characteristic
	acc.Switch.On.OnValueRemoteUpdate(func(on bool) {
		if on == true {
			log.Debug.Println("Client changed switch to on")
		} else {
			log.Debug.Println("Client changed switch to off")
		}
	})

	// Periodically toggle the switch's on characteristic
	go func() {
		for {
			on := !acc.Switch.On.GetValue()
			if on == true {
				log.Debug.Println("Switch is on")
			} else {
				log.Debug.Println("Switch is off")
			}
			acc.Switch.On.SetValue(on)
			time.Sleep(5 * time.Second)
		}
	}()

	hc.OnTermination(func() {
		t.Stop()
	})

	t.Start()
}