Beispiel #1
0
// Test DeviceClass JSON marshaling
func TestJsonDeviceClass(t *testing.T) {
	deviceClass := core.NewDeviceClass("class-name", "1.2.3")
	deviceClass.OfflineTimeout = 60
	testCheckJson(t, deviceClass, `{"name":"class-name","version":"1.2.3","offlineTimeout":60}`)

	deviceClass.Data = "custom data"
	deviceClass.Id = 100
	testCheckJson(t, deviceClass, `{"id":100,"name":"class-name","version":"1.2.3","offlineTimeout":60,"data":"custom data"}`)
}
Beispiel #2
0
// Test Device JSON marshaling
func TestJsonDevice(t *testing.T) {
	device := core.NewDevice("dev-id", "dev-name", nil)
	device.Key = "dev-key"
	device.Status = "Online"
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online"}`)

	device.Data = "custom data"
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data"}`)

	device.Network = core.NewNetwork("net-name", "net-key")
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data","network":{"name":"net-name","key":"net-key"}}`)

	device.DeviceClass = core.NewDeviceClass("class-name", "3.4.5")
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data","network":{"name":"net-name","key":"net-key"},"deviceClass":{"name":"class-name","version":"3.4.5"}}`)
}
Beispiel #3
0
// NewDeviceClass creates a new device class.
// No user data and no equipment by default.
func NewDeviceClass(name, version string) *core.DeviceClass {
	return core.NewDeviceClass(name, version)
}
// creates new test Device with device class initialized
func testNewDevice() (device *core.Device) {
	dc := core.NewDeviceClass(testDeviceClassName, testDeviceClassVersion)
	device = core.NewDevice(testDeviceId, testDeviceName, dc)
	device.Key = testDeviceKey
	return
}