Beispiel #1
0
func main() {
	flag.Parse()

	fe, _ := frontend.OpenFrontend("/dev/ttyAMA0")
	if e := fe.Beep(frontend.BEEP_SHORT); e != nil {
		fmt.Println("cannot beep")
	}

	hometec, _ := hometec.OpenHometec()
	tuerstatusChannel := make(chan tuerstatus.Tuerstatus)
	go tuerstatus.TuerstatusPoll(tuerstatusChannel, 250*time.Millisecond)
	go func() {
		for {
			newStatus = <-tuerstatusChannel
			if newStatus.Open {
				fe.LcdSet(" \nOpen")
			} else {
				fe.LcdSet(" \nClosed")
			}
		}
	}()

	// Ensure last door state is published. For example, if door state was
	// changed during netsplit, we need to ensure that the newest state
	// will be published as soon as network is up again.
	go func() {
		for {
			if newStatus.Open && !lastPublishedStatus.Open {
				publishMqtt()
			} else if !newStatus.Open && lastPublishedStatus.Open {
				publishMqtt()
			}
			time.Sleep(250 * time.Millisecond)
		}
	}()

	pins, err := pinstore.Load(*pin_path)
	if err != nil {
		log.Fatalf("Could not load pins: %v", err)
	}
	if err := pins.Update(*pin_url, fe); err != nil {
		fmt.Printf("Cannot update pins: %v\n", err)
	}

	go updatePins(pins, fe)

	ctrlsocket.Listen(fe, hometec.Control)
	pinpad.ValidatePin(pins, fe, hometec.Control)
}
Beispiel #2
0
func TestPinValidation(t *testing.T) {
	testfe := testfrontend.NewTestFrontend()
	frontend := frontend.OpenFrontendish(testfe)

	pins := pinstore.Load("/tmp/testcase")
	pins.Pins["123456"] = "secure"

	hometec := make(chan string)
	go ValidatePin(pins, frontend, hometec)

	invalidPin := constructPinBuffer("1234")
	validPin := constructPinBuffer("123456")

	if _, ok := resultWithBuffer(testfe, invalidPin, hometec); ok {
		t.Error("Hometec got an instruction for an invalid pin")
	}

	if _, ok := resultWithBuffer(testfe, validPin, hometec); ok {
		t.Error("Hometec got an instruction for an invalid pin")
	}
}