Sendhubcommand building and sending the commands

im using “sendhubcommand” to send some commands to a local TV in my device app. there is probably a 3rd way to do this even more neatly than I am, but as it is ive come up with two solutions to achieve the same thing. One runs all of the code required within one method. the other sets a state to what i need to send and then calls another method to send it. I am likely to have 30 or more buttons exactly the same in the code with basically just the string being sent different,

this is the original method

def tv_source() {
	log.debug "Executing Source"
    def rawcmd = "AAAAAQAAAAEAAAAlAw=="  //tv source
    def sonycmd = new physicalgraph.device.HubSoapAction(
            path:    '/sony/IRCC',
            urn:     "urn:schemas-sony-com:service:IRCC:1",
            action:  "X_SendIRCC",
            body:    ["IRCCCode":rawcmd],
            headers: [Host:"${state.tv_ip}:${tv_port}", 'X-Auth-PSK':"${tv_psk}"]
     )
     sendHubCommand(sonycmd)
     //log.debug( "hubAction = ${sonycmd}" )
}

this is called from a button, builds the string to send and sends it all in one method. ill need 30 copies of this to achieve all of the buttons the TV is capable of.

my second solution is this

def picoff(){
	//Set Remote command to send
	state.remotecommand = "AAAAAQAAAAEAAAA+Aw=="
	state.button = "Pic Off"
	sendremotecommand()
}

def sendremotecommand(){
	log.debug "Sending Button: ${state.button} ${state.remotecommand}"
    def rawcmd = "${state.remotecommand}"
    def sonycmd = new physicalgraph.device.HubSoapAction(
            path:    '/sony/IRCC',
            urn:     "urn:schemas-sony-com:service:IRCC:1",
            action:  "X_SendIRCC",
            body:    ["IRCCCode":rawcmd],
            headers: [Host:"${state.tv_ip}:${tv_port}", 'X-Auth-PSK':"${tv_psk}"]
     )
     sendHubCommand(sonycmd)
     log.debug( "hubAction = ${sonycmd}" )
}

this second version means i only need one copy of the sendremotecommand method and 30 copies of the picoff method, but for other buttons such as source of mute and so on.

my question is, is this a safe way to code this? i feel like because the second idea is separated out i could somehow end up sending the wrong commands if someone tried to send more than one command at once with a smart app or something like that. both version work fine in my limited testing.

thanks