Exemple #1
0
// NewTemperatureSensor returns a temperature service service.
func NewTemperatureSensor(name string, temperature, min, max, steps float64) *TemperatureSensor {
	nameChar := characteristic.NewName(name)
	tempUnit := model.TempUnitCelsius
	unitChar := characteristic.NewTemperatureUnit(tempUnit)
	temp := characteristic.NewCurrentTemperatureCharacteristic(temperature, min, max, steps, string(tempUnit))

	svc := New()
	svc.Type = typeTemperatureSensor
	svc.AddCharacteristic(temp.Characteristic)
	svc.AddCharacteristic(nameChar.Characteristic)
	svc.AddCharacteristic(unitChar.Characteristic)

	t := TemperatureSensor{svc, temp, nameChar, unitChar}

	return &t
}
Exemple #2
0
// NewThermostat returns a thermostat service.
func NewThermostat(name string, temperature, min, max, steps float64) *Thermostat {
	nameChar := characteristic.NewName(name)
	tempUnit := model.TempUnitCelsius
	unitChar := characteristic.NewTemperatureUnit(tempUnit)
	temp := characteristic.NewCurrentTemperatureCharacteristic(temperature, min, max, steps, string(tempUnit))
	targetTemp := characteristic.NewTargetTemperatureCharacteristic(temperature, min, max, steps, string(tempUnit))
	mode := characteristic.NewCurrentHeatingCoolingMode(model.HeatCoolModeOff)
	targetMode := characteristic.NewTargetHeatingCoolingMode(model.HeatCoolModeOff)

	svc := New()
	svc.Type = typeThermostat
	svc.AddCharacteristic(mode.Characteristic)
	svc.AddCharacteristic(targetMode.Characteristic)
	svc.AddCharacteristic(temp.Characteristic)
	svc.AddCharacteristic(targetTemp.Characteristic)
	svc.AddCharacteristic(unitChar.Characteristic)
	svc.AddCharacteristic(nameChar.Characteristic)

	t := Thermostat{svc, nameChar, unitChar, temp, targetTemp, mode, targetMode, nil}

	return &t
}