untested update to space api v0.13
[svn42.git] / r3-webstatus-spaceapi / main.go
index 07bb194..114777e 100644 (file)
@@ -9,6 +9,7 @@ import (
        "net/url"
        "regexp"
        "time"
+    "strconv"
 )
 
 type SpaceState struct {
@@ -72,24 +73,22 @@ func parseSocketInputLine(line string) {
 
        if match_presence != nil {
                statusstate.present = (match_presence[1] == "yes")
+        spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed"))
                publishStateToWeb()
        } else if match_button != nil {
                statusstate.buttonpress_until = time.Now().Unix() + 3600
                spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
                publishStateToWeb()
        } else if match_temp != nil {
-               spaceapidata.UpdateSensorData("temp", "Ceiling", match_temp[1]+"C")
-               //newtemp, err = strconv.ParseFloat((match_temp[1]), 32)
-               //if err == nil {
-               //      spaceapidata.UpdateSensorData("temp", "Ceiling", strconv.FormatFloat(newtemp, 'f', 2, 32)+"C")
-               //      spacestate.temperature = newtemp
-               //}
+               newtemp, err := strconv.ParseFloat((match_temp[1]), 32)
+               if err == nil {
+            spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Ceiling",newtemp))
+               }
        } else if match_photo != nil {
-               spaceapidata.UpdateSensorData("light", "Front", match_photo[1])
-               //newphoto, err = strconv.ParseInt(match_photo[1], 10, 32)
-               //if err == nil {
-               //      spacestate.lightlevel = newphoto
-               //}
+               newphoto, err := strconv.ParseInt(match_photo[1], 10, 32)
+               if err == nil {
+                       spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Ceiling","1024V/5V",newphoto))
+               }
        }
 }