示例#1
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"}}`)
}
示例#2
0
// NewDevice creates a new device without network.
// No user data by default.
func NewDevice(id, name string, class *core.DeviceClass) *core.Device {
	return core.NewDevice(id, name, class)
}
示例#3
0
// 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
}