[dss-commits] r8814 - dss/trunk/tools
dss-commits at forum.digitalstrom.org
dss-commits at forum.digitalstrom.org
Mon Oct 5 15:21:59 CEST 2009
Author: jwinkelmann
Date: 2009-10-05 15:21:59 +0200 (Mon, 05 Oct 2009)
New Revision: 8814
Added:
dss/trunk/tools/ds3
Log:
add dss interface shell script (ds3)
Added: dss/trunk/tools/ds3
===================================================================
--- dss/trunk/tools/ds3 (rev 0)
+++ dss/trunk/tools/ds3 2009-10-05 13:21:59 UTC (rev 8814)
@@ -0,0 +1,114 @@
+#!/bin/bash
+#
+# DSS shell (ds3) - simple shell interface to the dss json api
+# Johannes Winkelmann, johannes.winkelmann at aizo.com
+
+APPNAME=$(basename $0)
+
+# target, commands, args
+function call_dss() {
+ URL=http://localhost:8080/json/$1/$2
+ shift; shift
+
+ if [ -n "$1" ]; then
+ URL="$URL?$1"
+ shift
+ fi
+ while [ -n "$1" ]; do
+ URL="$URL&$1"
+ shift
+ done
+
+ result=$(wget -q -O - $URL)
+ if [ -n "$(echo $result|grep '"ok":false')" ]; then
+ echo $result|sed -e 's|.*message\":\"||g' -e 's|\"}$||g'
+ exit 1
+ else
+ if [ -n "$PRINT_RESULT" ]; then
+ echo $result|sed -e 's|.*result\":\s*{\s*||g' -e 's|}\s*}$||g'
+ fi
+ fi
+ return 0
+}
+
+usage() {
+ if [ -n "$target_command" ]; then
+ echo "Unknown target/command combination"
+ elif [ -n "$target" ]; then
+ echo "Command missing for target '$target'"
+ fi
+ echo "Usage: $APPNAME <target> <command> <args>"
+ echo ""
+ echo "Supported commands:"
+ echo " device:"
+ echo " turnOn, turnOff, getState, getName, getConsumption | <dsid>"
+ echo " setName | <dsid> <new name>"
+ echo " Example: $APPNAME device getState 3504175fe0000000000012e7"
+ echo ""
+ echo " zone:"
+ echo " turnOn, turnOff | <zone id>"
+ echo " callScene | <zone id> <scene #>"
+ echo " Example: $APPNAME zone turnOn 172"
+ echo ""
+ echo " apartment"
+ echo " turnOn, turnOff, getName, getConsumption"
+ echo " callScene | <scene #>"
+ echo " setName | <new name>"
+ echo " Example: $APPNAME apartment callScene 5"
+}
+
+command="$1_$2"
+target=$1
+target_command=$2
+shift; shift
+
+case "$command" in
+ ###
+ ## device commands
+ #
+ "device_turnOn"|"device_turnOff")
+ call_dss "device" "$target_command" "dsid=$1"
+ ;;
+ "device_getState"|"device_getName"|"device_getConsumption")
+ PRINT_RESULT="yes" call_dss "device" "$target_command" "dsid=$1"
+ ;;
+ "device_setName")
+ call_dss "device" "$target_command" "dsid=$1" "newName=$2"
+ ;;
+
+ ###
+ ## zone commands
+ #
+ "zone_turnOn"|"zone_turnOff")
+ call_dss "$target" "$target_command" "id=$1"
+ ;;
+ "zone_callScene")
+ call_dss "$target" "$target_command" "id=$1" "sceneNr=$2"
+ ;;
+ "zone_getConsumption")
+ PRINT_RESULT="yes" call_dss "$target" "$target_command" "id=$1" "sceneNr=$2"
+ ;;
+
+ ###
+ ## apartment
+ #
+ "apartment_turnOn"|"apartment_turnOff")
+ call_dss "$target" "$target_command"
+ ;;
+ "apartment_callScene")
+ call_dss "$target" "$target_command" "sceneNr=$1"
+ ;;
+ "apartment_getName"|"apartment_getConsumption")
+ PRINT_RESULT="yes" call_dss "$target" "$target_command"
+ ;;
+ "apartment_setName")
+ call_dss "$target" "$target_command" "newName=$1"
+ ;;
+
+ *)
+ usage
+ exit 1
+ ;;
+esac
+
+exit 0
\ No newline at end of file
Property changes on: dss/trunk/tools/ds3
___________________________________________________________________
Added: svn:executable
+ *
More information about the dss-commits
mailing list