Fundamental Problem with the dhcp hotplug interface

Hi

I've been trying to write a script to interface with dnsmasq on my openwrt router and I've noticed a fundamental problem with the way the date is passed to the hotplug scripts. Put simply as the hostname associated with the event is passed in a variable called HOSTNAME, if there is no host set (as some IOT devices don't supply hostnames for example) then the hostname of the router will already be set in that variable.
So far I’ve worked out that the script ls /usr/lib/dnsmasq/dhcp-script.sh is set as the --dhcp-script in the configuration of dnsmasq. That script put the information passed to it by dnsmasq on the ubus by a call such as:

ubus call hotplug.dhcp call '{"env":["MACADDR=something","IPADDR=something","ACTION=update","HOSTNAME=helloworld"]}'

I’ve not been able to find what program or script picks this up and executes the script I would put in /etc/hotplug.d/dhcp/ but clearly if the HOSTNAME is left blank, i.e. “HOSTNAME=” then when it is called the HOSTNAME variable would be set to the hostname of my router....
I can't think of a simple way to determine when this situation arises from inside my script? As I’m not 100% sure how the ubus call gets translated into the hotplug call I’m not sure how I can fix it. From a quick experiment if I change the call to:

ubus call hotplug.dhcp call '{"env":["MACADDR=something","IPADDR=something","ACTION=update","ACTIONHOSTNAME=helloworld"]}'
that translates to the variable being passed changing to ACTIONHOSTNAME, but then my script won’t work without editing the /usr/lib/dnsmasq/dhcp-script.sh on any router I place it on. Similarly I would have to set and store the hostname (and possible IP) of the router to test for this situation, which also seems messy.

Any suggestions? Am I the only one to have had this problem?

X$hostname != x

But when a hostname is supplied it over writes hostname, so I would have to store the hostname somewhere and then set it up on every router I placed my script. Also there is a chance I'd want to call it with the hostname as the hostname of the router...