From 28fe69fe94b57d6a93a00490c3a158d641dd398d Mon Sep 17 00:00:00 2001
From: Tim Perry <pimterry@gmail.com>
Date: Fri, 18 May 2018 20:05:24 +0200
Subject: [PATCH] Update to latest SDK in lots of easy device commands

---
 lib/actions/device.coffee | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee
index 98c8f892..9fb4eaad 100644
--- a/lib/actions/device.coffee
+++ b/lib/actions/device.coffee
@@ -125,7 +125,7 @@ exports.supported =
 			$ resin devices supported
 	'''
 	action: (params, options, done) ->
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		visuals = require('resin-cli-visuals')
 
 		resin.models.config.getDeviceTypes().then (deviceTypes) ->
@@ -161,7 +161,7 @@ exports.register =
 	]
 	action: (params, options, done) ->
 		Promise = require('bluebird')
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 
 		Promise.join(
 			resin.models.application.get(params.application)
@@ -196,7 +196,7 @@ exports.remove =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		patterns = require('../utils/patterns')
 
 		patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then ->
@@ -218,7 +218,7 @@ exports.identify =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.identify(params.uuid).nodeify(done)
 
 exports.reboot =
@@ -235,7 +235,7 @@ exports.reboot =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.reboot(params.uuid, options).nodeify(done)
 
 exports.shutdown =
@@ -252,7 +252,7 @@ exports.shutdown =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.shutdown(params.uuid, options).nodeify(done)
 
 exports.enableDeviceUrl =
@@ -268,7 +268,7 @@ exports.enableDeviceUrl =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.enableDeviceUrl(params.uuid).nodeify(done)
 
 exports.disableDeviceUrl =
@@ -284,7 +284,7 @@ exports.disableDeviceUrl =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.disableDeviceUrl(params.uuid).nodeify(done)
 
 exports.getDeviceUrl =
@@ -300,7 +300,7 @@ exports.getDeviceUrl =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.getDeviceUrl(params.uuid).then (url) ->
 			console.log(url)
 		.nodeify(done)
@@ -318,7 +318,7 @@ exports.hasDeviceUrl =
 	permission: 'user'
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		resin.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) ->
 			console.log(hasDeviceUrl)
 		.nodeify(done)
@@ -340,7 +340,7 @@ exports.rename =
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
 		Promise = require('bluebird')
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		form = require('resin-cli-form')
 
 		Promise.try ->
@@ -370,14 +370,14 @@ exports.move =
 	options: [ commandOptions.optionalApplication ]
 	action: (params, options, done) ->
 		normalizeUuidProp(params)
-		resin = require('resin-sdk-preconfigured')
+		resin = require('resin-sdk').fromSharedOptions()
 		patterns = require('../utils/patterns')
 
-		resin.models.device.get(params.uuid).then (device) ->
+		resin.models.device.get(params.uuid, expandForAppName).then (device) ->
 			return options.application or patterns.selectApplication (application) ->
 				return _.every [
 					application.device_type is device.device_type
-					device.application_name isnt application.app_name
+					device.belongs_to__application[0].app_name isnt application.app_name
 				]
 		.tap (application) ->
 			return resin.models.device.move(params.uuid, application)