Ejemplo n.º 1
0
// Process GetDevice task
func (service *Service) processGetDevice(task *Task, device *core.Device) (err error) {
	// check response status
	err = task.CheckStatus()
	if err != nil {
		log.Warnf("WS: bad /device/get status (error: %s)", err)
		return
	}

	// parse response
	err = device.AssignJSON(task.dataRecved["device"])
	if err != nil {
		log.Warnf("WS: failed to parse /device/get body (error: %s)", err)
		return
	}

	return
}
Ejemplo n.º 2
0
// check the RegisterDevice method
func testCheckRegisterDevice(t *testing.T, service Service, device core.Device, suffix string) {
	if service == nil {
		return // do nothing
	}

	device.Id += suffix
	if len(device.Key) != 0 {
		device.Key += suffix
	}
	device.Name += suffix

	// create new device
	testCheckRegisterDevice1(t, service, device, true)
	testCheckGetDevice(t, service, device)

	// change some data
	device.Data = "new data"
	device.Status = "Bad"
	device.Name += "-new"

	// update device
	testCheckRegisterDevice1(t, service, device, false)
	testCheckGetDevice(t, service, device)
}