Пример #1
0
// NewContactSensor returns a contact sensor service.
func NewContactSensor(name string) *ContactSensor {
	contactSensorChar := characteristic.NewCurrentContactSensorState(model.ContactNotDetected)
	nameChar := characteristic.NewName(name)

	svc := New()
	svc.Type = typeContactSensor
	svc.AddCharacteristic(contactSensorChar.Characteristic)
	svc.AddCharacteristic(nameChar.Characteristic)

	return &ContactSensor{svc, contactSensorChar, nameChar}
}
Пример #2
0
// NewSwitch returns a switch service.
func NewSwitch(name string, on bool) *Switch {
	onChar := characteristic.NewOn(on)
	nameChar := characteristic.NewName(name)

	svc := New()
	svc.Type = typeSwitch
	svc.AddCharacteristic(onChar.Characteristic)
	svc.AddCharacteristic(nameChar.Characteristic)

	return &Switch{svc, onChar, nameChar}
}
Пример #3
0
// NewAccessoryInfo returns a accessory info
func NewAccessoryInfo(accessoryName, serialNumber, manufacturerName, modelName, firmwareRevision, hardwareRevision, softwareRevision string) *AccessoryInfo {

	if len(accessoryName) == 0 {
		accessoryName = "Undefined"
	}
	if len(serialNumber) == 0 {
		serialNumber = "Undefined"
	}
	if len(manufacturerName) == 0 {
		manufacturerName = "Undefined"
	}
	if len(modelName) == 0 {
		modelName = "Undefined"
	}

	identify := characteristic.NewIdentify()
	serial := characteristic.NewSerialNumber(serialNumber)
	model := characteristic.NewModel(modelName)
	manufacturer := characteristic.NewManufacturer(manufacturerName)
	name := characteristic.NewName(accessoryName)

	svc := New()
	svc.Type = typeAccessoryInfo
	svc.AddCharacteristic(name.Characteristic)
	svc.AddCharacteristic(manufacturer.Characteristic)
	svc.AddCharacteristic(model.Characteristic)
	svc.AddCharacteristic(serial.Characteristic)
	svc.AddCharacteristic(identify.Characteristic)

	var firmware *characteristic.Revision
	if firmwareRevision != "" {
		firmware = characteristic.NewFirmwareRevision(firmwareRevision)
		svc.AddCharacteristic(firmware.Characteristic)
	}

	var hardware *characteristic.Revision
	if hardwareRevision != "" {
		hardware = characteristic.NewHardwareRevision(hardwareRevision)
		svc.AddCharacteristic(hardware.Characteristic)
	}

	var software *characteristic.Revision
	if softwareRevision != "" {
		software = characteristic.NewSoftwareRevision(softwareRevision)
		svc.AddCharacteristic(software.Characteristic)
	}

	return &AccessoryInfo{svc, identify, serial, model, manufacturer, name, firmware, hardware, software}
}
Пример #4
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
}
Пример #5
0
// NewGarageDoorOpener returns a thermostat service.
func NewGarageDoorOpener(name string, currentState model.DoorStateType) *GarageDoorOpener {
	nameChar := characteristic.NewName(name)
	state := characteristic.NewCurrentDoorState(currentState)
	targetState := characteristic.NewTargetDoorState(model.DoorStateClosed)
	obstructionDetected := characteristic.NewObstructionDetected(false)
	lockTargetState := characteristic.NewLockTargetState(model.LockStateSecured)

	svc := New()
	svc.Type = typeGarageDoorOpener
	svc.AddCharacteristic(nameChar.Characteristic)
	svc.AddCharacteristic(state.Characteristic)
	svc.AddCharacteristic(targetState.Characteristic)
	svc.AddCharacteristic(obstructionDetected.Characteristic)
	svc.AddCharacteristic(lockTargetState.Characteristic)

	return &GarageDoorOpener{svc, nameChar, state, targetState, obstructionDetected, lockTargetState, nil, nil}
}
Пример #6
0
// NewLightBulb returns a light bulb service.
func NewLightBulb(name string, on bool) *LightBulb {
	onChar := characteristic.NewOn(on)
	nameChar := characteristic.NewName(name)
	brightness := characteristic.NewBrightness(100) // 100%
	saturation := characteristic.NewSaturation(0.0)
	hue := characteristic.NewHue(0.0)

	svc := New()
	svc.Type = typeLightBulb
	svc.AddCharacteristic(onChar.Characteristic)
	svc.AddCharacteristic(nameChar.Characteristic)
	svc.AddCharacteristic(brightness.Characteristic)
	svc.AddCharacteristic(saturation.Characteristic)
	svc.AddCharacteristic(hue.Characteristic)

	return &LightBulb{svc, onChar, nameChar, brightness, saturation, hue}
}
Пример #7
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
}