#!/bin/sh

HELP="Usage: $0 <func> <param1> <param2> ..."

SWITCH_SENSOR="switch_sensor"

show_log() {
	# 重定向到串口输出，不会被管道捕获
	echo "/dz/switch_sensor] ^^^ $*" > /dev/console
}

result=""

script_operate() {
	local method=$1

	if [ "$method" = "$SWITCH_SENSOR" ]; then
		if [ $# = 3 ]; then
			ubus call dz_cmd dz_switch_sensor "{\"id\":$2,\"position\":$3}"
			return 1
		else
			echo "$3"
			echo "missing some paras"
			return 0
		fi
	fi

	return 1
}

script_operate $@
if [ $? -ne 1 ]; then
	show_log $HELP
	exit 1
fi
exit 0
