Rename Hub Variable Throws Error [SOLVED]

I'm writing to hub variables in my app. If I have a variable linked, and use the "rename" option in the hub variable menu, the app is throwing an error.

After this, app updates that should be setting the variable are also throwing an error (I presume it's still trying to set the "old" variable since the name update is failing.

The variable itself still lists the correct "In use by". EC_Stuff is a dashboard and _testing is the app throwing the error.

Is there something from an app dev aspect I need to do to allow for the rename?

1 Like

You have to provide a method in your app called renameVariable that takes two string parameters, the old name and new name. Looks like you didn't do that.

That method has to track down all settings and state that refer to the old name, and update them to use the new name.

Oh...ye old case of RTFM:

1 Like

My head hurts now :smiley: but I think I've got it implemented.

void renameVariable(String oldName,String newName) {
	log.warn "Old name is ${oldName} and new name is ${newName}"
	if(state.find{it.value == oldName}) {
		stateVariableRename = state.find{it.value == oldName}.key
		log.warn "Found in ${stateVariableRename}; setting to ${newName}"
		state[stateVariableRename] = newName
	} else {
		state.energies.each{k,v -> 
		v.each {i,j -> if(j == oldName) {
			log.warn "Found in device ${k} variable of ${i}; setting to ${newName}"
			state.energies[k][i] = newName
			}
			}
		}
	}
}
2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.