Пример #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
}
Пример #2
0
// NewThermostat returns a thermostat service.
func NewThermostat(name string, temperature, min, max, steps float64) *Thermostat {
	tempUnit := model.TempUnitCelsius
	unitChar := characteristic.NewTemperatureUnit(tempUnit)
	targetTemp := characteristic.NewTargetTemperatureCharacteristic(temperature, min, max, steps, string(tempUnit))
	mode := characteristic.NewCurrentHeatingCoolingMode(model.HeatCoolModeOff)
	targetMode := characteristic.NewTargetHeatingCoolingMode(model.HeatCoolModeOff)

	svc := NewTemperatureSensor(name, temperature, min, max, steps)
	svc.Type = typeThermostat
	svc.AddCharacteristic(mode.Characteristic)
	svc.AddCharacteristic(targetMode.Characteristic)
	svc.AddCharacteristic(targetTemp.Characteristic)
	svc.AddCharacteristic(unitChar.Characteristic)

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

	return &t
}