X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=r3-webstatus-spaceapi%2Fmain.go;h=322b647de2a1ca2760212bcf82803c397cc1a756;hb=60abb16ed97508b858591581f1cf8a21783d4ef8;hp=28c094bf07ff378f514825910d93016150364a50;hpb=b30fa8619ab41857c9c15aa939e05f2e406b8192;p=svn42.git diff --git a/r3-webstatus-spaceapi/main.go b/r3-webstatus-spaceapi/main.go index 28c094b..322b647 100644 --- a/r3-webstatus-spaceapi/main.go +++ b/r3-webstatus-spaceapi/main.go @@ -9,6 +9,7 @@ import ( "net/url" "regexp" "time" + "strconv" ) type SpaceState struct { @@ -18,6 +19,7 @@ type SpaceState struct { var ( re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?") + re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*") re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?") re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)") re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)") @@ -66,30 +68,35 @@ func publishStateToWeb() { func parseSocketInputLine(line string) { match_presence := re_presence_.FindStringSubmatch(line) + match_status := re_status_.FindStringSubmatch(line) match_button := re_button_.FindStringSubmatch(line) match_temp := re_temp_.FindStringSubmatch(line) match_photo := re_photo_.FindStringSubmatch(line) if match_presence != nil { statusstate.present = (match_presence[1] == "yes") + //spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed")) + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_presence[2] == "closed")) publishStateToWeb() + } else if match_status != nil { + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_status[1] == "closed")) + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", match_status[3] == "shut")) + //spaceapidata.MergeInSensor(spaceapi.MakeDoorAjarSensor("Torwaechter", "Front Door", match_presence[3] == "shut")) + 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","Decke",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","Decke","1024V/5V",newphoto)) + } } } @@ -116,11 +123,12 @@ ReOpenSocket: } func main() { - spaceapidata.AddSpaceFeed("calendar", "application/rss+xml", "http://grical.realraum.at/s/?query=!realraum&view=rss") - spaceapidata.AddSpaceFeed("google+", "text/html", "https://plus.google.com/113737596421797426873") - spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at") + spaceapidata.AddSpaceFeed("calendar", "http://grical.realraum.at/s/?query=!realraum&view=rss") + spaceapidata.AddSpaceFeed("blog", "https://plus.google.com/113737596421797426873") + spaceapidata.AddSpaceFeed("wiki", "http://realraum.at/wiki") + spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at") eventqueue := make(chan string) - ticker := time.NewTicker(time.Duration(15) * time.Minute) + ticker := time.NewTicker(time.Duration(7) * time.Minute) go readFromUSocket("/var/run/tuer/presence.socket", eventqueue) for { select {