コード例 #1
0
ファイル: main.go プロジェクト: samthor/acdash
func main() {
	// nb. since we have a token, ignore all params
	client := nest.New("", "", "", "")
	client.Token = readToken()

	unit, err := acdash.NewDaikin(ACUnit)
	if err != nil {
		log.Fatalf("can't create unit: %v", err)
	}

	log.Printf("Streaming...")
	for devices := range stream(client) {
		t := devices.Thermostats[Device]
		if t == nil {
			log.Fatalf("couldn't find device: %s", Device)
		}

		c := acdash.ControlInfo{}
		target := float64(t.TargetTemperatureC)
		on := t.HvacState != "off"
		c.Power = on
		c.SetPoint = &target
		if t.HvacState == "heating" {
			c.Mode = acdash.ModeHeat
		} else if t.HvacState == "cooling" {
			c.Mode = acdash.ModeCool
		} else if on {
			log.Fatalf("expected state 'heating' or 'cooling', was: %v", t.HvacState)
		}

		log.Printf("sending control: %+v", c)
		unit.Set(&c, 0)
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: samthor/acdash
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	router = NewRouter(updateManager, *delayBase)

	for _, addr := range flag.Args() {
		unit, err := lib.NewDaikin(addr)
		if err != nil {
			log.Fatalf("can't create unit %v: %v", addr, err)
		}

		go func() {
			for {
				err := router.Feed(unit)
				log.Printf("unit fail (addr=%+v): %v", unit, err)
				time.Sleep(20 * time.Second)
			}
		}()
	}

	writer := updateManager.Listen()
	go func() {
		for {
			x := writer.Next().(updateData)
			logValue(*outsidePath, "", x.SensorInfo.Outside)
			logValue(*insidePathPrefix, x.BasicInfo.MAC, &x.SensorInfo.Inside)
		}
	}()

	log.Printf("listening on :%d...", *port)
	http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
}