From 394acb2a3c198dfa678153b2cad064af3f1fc810 Mon Sep 17 00:00:00 2001
From: tomsmeding <tom.smeding@gmail.com>
Date: Wed, 13 Jan 2016 22:22:51 +0100
Subject: get state, get graph data

---
 functions.sh | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/functions.sh b/functions.sh
index 857ae55..b24f80b 100755
--- a/functions.sh
+++ b/functions.sh
@@ -90,6 +90,30 @@ function finctemp() {
 	fcurlwithtoken -d "increment=$1" 'https://www.e-thermostaat.nl/processing/temperature' >/dev/null
 }
 
+#returns number in [1-4], the selected state
+function fgetstate() {
+	local page linklist selectedstate
+	page="$(fgetthermpage)"
+	linklist="$(grep -m 1 -C 4 '<div id="termostat-states">' <<<"$page" | tail -n 4)"
+	selectedstate="$(sed 's/.*class="\([^"]*\)".*/\1/' <<<"$linklist" | grep -nm 1 selected | cut -d: -f1)"
+	echo $selectedstate
+}
+
+#returns 4 words, the names of the 4 states
+function fgetstatenames() {
+	local page linklist statenames
+	page="$(fgetthermpage)"
+	linklist="$(grep -m 1 -C 4 '<div id="termostat-states">' <<<"$page" | tail -n 4)"
+	statenames="$(sed 's/.*setState(\(&quot;\)\?\([^)&]*\)\(&quot;\)\?).*/\2/' <<<"$linklist")"
+	echo $statenames
+}
+
+function fgetprogress() {
+	fensurelogin
+	json="$(fcurlwithtoken 'https://www.e-thermostaat.nl/pages/temperature_progress' | grep -m 1 'var json_data =' | sed 's/[^=]*= *\({.*}\);.*/\1/')"
+	echo $json
+}
+
 
 function fissourced() {
 	test ${BASH_SOURCE[0]} != $0
-- 
cgit v1.2.3-70-g09d2