Esempio n. 1
0
func NewSensorForInputValue(v uvr.Value, info model.Info) *Sensor {
	input_type, _ := uvr1611.DecodeInputValue(v)

	var s *Sensor
	inUse := true
	switch input_type {
	case uvr1611.InputTypeUnused:
		inUse = false
		fallthrough
	case uvr1611.InputTypeDigital:
		o := accessory.NewOutlet(info)
		o.SetInUse(inUse)
		s = &Sensor{o, o.Accessory}
	case uvr1611.InputTypeRoomTemperature:
		// -50 ... +199°C
		t := accessory.NewThermostat(info, 0, -50, 199, 1)
		s = &Sensor{t, t.Accessory}
	case uvr1611.InputTypeTemperature:
		t := accessory.NewThermometer(info, 0, -50, 199, 1)
		s = &Sensor{t, t.Accessory}
	case uvr1611.InputTypeVolumeFlow:
		// TODO(brutella) ?
		break
	case uvr1611.InputTypeRadiation:
		// TODO(brutella) ?
		break
	}

	if s != nil {
		UpdateAccessoryWithInputValue(s.Model, v)
	}

	return s
}
Esempio n. 2
0
func NewHomeKitService(thermostat *Thermostat) *HomeKitService {
	thermostatInfo := model.Info{
		Name: "Thermostat",
	}

	hkThermostat := accessory.NewThermostat(thermostatInfo, temp, 17, 25, 0.5)
	hkThermostat.SetTargetMode(model.HeatCoolModeHeat)
	hkThermostat.OnTargetTempChange(func(temp float64) {
		log.Println("[INFO] HomeKit requested thermostat to change to", temp)
		thermostat.targetTemp = temp
	})

	hkThermostat.OnTargetModeChange(func(mode model.HeatCoolModeType) {
		log.Println("[INFO] HomeKit requested thermostat to change to", mode)

		switch mode {
		case model.HeatCoolModeHeat:
			log.Println("[INFO] HomeKit setting thermostat to default on temp of", defaultOnTemp)
			thermostat.targetTemp = defaultOnTemp
		case model.HeatCoolModeOff:
			log.Println("[INFO] HomeKit setting thermostat to default off temp of", defaultOffTemp)
			thermostat.targetTemp = defaultOffTemp
		case model.HeatCoolModeAuto, model.HeatCoolModeCool:
			hkThermostat.SetTargetMode(model.HeatCoolModeHeat)
		}

	})

	transport, err := hap.NewIPTransport("24282428", hkThermostat.Accessory)
	if err != nil {
		log.Fatal(err)
	}

	t := HomeKitService{
		thermostat:   thermostat,
		done:         make(chan bool),
		hkThermostat: hkThermostat,
		transport:    transport,
	}

	return &t
}