getNamespace()

@bravenel @mike.maxwell

Guys
have you implemented the getNamespace() method?

I'm getting the 'groovy.lang.MissingMethodException' error when trying to use it.

If not implemented, is there an alternative way to get a driver/app namespace into a variable?

Andy

Appears we have an internal method that serves that purpose, just not a public one, can't see any reason it shouldn't be public, I'll check.

Thanks Mike

Resurrecting the dead here, but can't find any mention of this anywhere else, was the getNamespace() method ever made public? Or is there any other way of getting the namespace for the driver of a device?

In case someone comes here looking, this works today:

From a device driver:
device.device.deviceType.namespace

From an application:
getChildDevice(String deviceNetworkId).device.deviceType.namespace

2 Likes

Why do you need this info, out of curiosity?

Not sure 'other' use cases that started this thread, but for HubiThings Replica the 'replica' namespace driver(s) are special and knowing identity helps in functionality design of the application.

Thanks for just context. I am intrigued.

Is it a situation where the name of the driver is the same as a built-in type, except the namespace is different? And this is how you tell the difference?

Is there some advantage to this compared to just using a slightly different name?

The replica application allows anyone to write drivers and if they use the 'replica' namespace the application will present it to the user for device creation. This is done so the application doesn't really need to know what drivers are loaded in HE. Here is the source code that will poll to get a list of the drivers for the device creation picker:

getDriverList()
/ ******** Thanks to Dominick Meglio for the code below! ********
Map getDriverList() {
	def params = [
		uri: "http://127.0.0.1:8080/device/drivers",
		headers: [
			Cookie: state.cookie //shouldn't need since we are using this only in the UI after the user logs in
		]
	  ]
	Map result = [items:[]]
	try {
		httpGet(params) { resp ->
			for (driver in resp.data.drivers) {
				result.items.add([id:driver.id.toString(),name:driver.name,namespace:driver.namespace])
			}
		}
	} catch (e) {
		logWarn "Error retrieving installed drivers: ${e}"
	}
	return result
}
// ******** Thanks to Dominick Meglio for the code above! - End ********

But just knowing the drivers really doesn't allow the application to actually know the namespace if the device was built outside of the application which is allowed. Here is an example of a application setting that knowing the namespace helped me determine the correct default setting for a user:

app.updateSetting("pageConfigureDeviceDisableStatusUpdate", (replicaDevice && replicaDevice?.device?.deviceType?.namespace!="replica"))

3 Likes

Whoa, this is awesome! I didn't know you could do this sort of thing without a virtual device instance of that driver type. Thanks for the tip.