#!/usr/bin/fish
# vi:syntax=zsh
set apikey eoBeM0xXhuJ8oRjIqTmrx9fuuUVPH0uyKseiYHNf
set bridge 192.168.43.254
set api http://$bridge/api/$apikey
set lights 1 2

function put
	for light in $lights
		echo "$argv[2..-1]" | curl -sS -T - $api/lights/$light/$argv[1] >/dev/null
	end
end
function json
	echo -n "{"
	set start 1
	for i in $argv
		test $start -eq 0; and echo -n ,
		echo -n $i | sed 's;^\(.*\):\(.*\)$;"\1":\2;g'
		set start 0
	end
	echo -n "}"
end

function die
	put state (json bri:112 hue:60954 sat:254)
	exit 0
end

trap 'die' USR1

