distribute DoorProblemEvent
authorBernhard Tittelbach <xro@realraum.at>
Wed, 6 Nov 2013 20:22:46 +0000 (20:22 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Wed, 6 Nov 2013 20:22:46 +0000 (20:22 +0000)
go/r3-eventbroker_zmq/sockettoevent.go
go/r3-netstatus/main.go
go/r3-netstatus/r3xmppbot/r3xmppbot.go

index d8de48e..9e4907e 100644 (file)
@@ -6,6 +6,7 @@ import (
     "regexp"
     "strconv"
     "time"
     "regexp"
     "strconv"
     "time"
+    "bytes"
     //~ "./brain"
     pubsub "github.com/tuxychandru/pubsub"
     zmq "github.com/vaughan0/go-zmq"
     //~ "./brain"
     pubsub "github.com/tuxychandru/pubsub"
     zmq "github.com/vaughan0/go-zmq"
@@ -35,14 +36,14 @@ func parseSocketInputLine_State(lines [][]byte, ps *pubsub.PubSub, ts int64) {
         case "manual", "manual_movement":   //movement
             ps.Pub(r3events.DoorManualMovementEvent{ts}, "door")
         case "error":
         case "manual", "manual_movement":   //movement
             ps.Pub(r3events.DoorManualMovementEvent{ts}, "door")
         case "error":
-            ps.Pub(r3events.DoorProblemEvent{100, ts}, "door")
+            ps.Pub(r3events.DoorProblemEvent{100, string(bytes.Join(lines,[]byte(" "))),  ts}, "door")
         case "reset":
             ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
         case "timeout_after_open":
         case "reset":
             ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
         case "timeout_after_open":
-            ps.Pub(r3events.DoorProblemEvent{10, ts}, "door")
+            ps.Pub(r3events.DoorProblemEvent{10, string(lines[0]), ts}, "door")
             ps.Pub(r3events.DoorLockUpdate{false, ts}, "door")
         case "timeout_after_close":
             ps.Pub(r3events.DoorLockUpdate{false, ts}, "door")
         case "timeout_after_close":
-            ps.Pub(r3events.DoorProblemEvent{20, ts}, "door")
+            ps.Pub(r3events.DoorProblemEvent{20, string(lines[0]), ts}, "door")
             // can't say for sure that door is locked if we ran into timeout while closing
             //~ ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
         case "opening":
             // can't say for sure that door is locked if we ran into timeout while closing
             //~ ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
         case "opening":
index cc63daa..c897e29 100644 (file)
@@ -108,7 +108,7 @@ func EventToXMPP(events <- chan interface{}, xmpp_presence_events_chan chan <- i
                 if last_frontdoor_ajar.Shut != event.Shut {
                     xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Frontdoor is %s  (%s)",IfThenElseStr(event.Shut,"now shut.","ajar."),time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: false}
                 }
                 if last_frontdoor_ajar.Shut != event.Shut {
                     xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Frontdoor is %s  (%s)",IfThenElseStr(event.Shut,"now shut.","ajar."),time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: false}
                 }
-               last_frontdoor_ajar = event
+                last_frontdoor_ajar = event
            case r3events.BackdoorAjarUpdate:
                 xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Backdoor is %s  (%s)",IfThenElseStr(event.Shut,"now shut.","ajar!"),time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false}
             case r3events.BoreDoomButtonPressEvent:
            case r3events.BackdoorAjarUpdate:
                 xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Backdoor is %s  (%s)",IfThenElseStr(event.Shut,"now shut.","ajar!"),time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false}
             case r3events.BoreDoomButtonPressEvent:
@@ -120,6 +120,8 @@ func EventToXMPP(events <- chan interface{}, xmpp_presence_events_chan chan <- i
                     xmpp_presence_events_chan <- present_status
                     last_buttonpress = 0
                 }
                     xmpp_presence_events_chan <- present_status
                     last_buttonpress = 0
                 }
+            case r3events.DoorProblemEvent:
+                xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Door Problem: %s. SeverityLevel: %d (%s)",event.Problem, event.Severity, time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false}
         }
        }
 }
         }
        }
 }
@@ -151,12 +153,12 @@ func ParseZMQr3Event(lines [][]byte, ps *pubsub.PubSub) {
 
 func QueryLatestEventsAndInjectThem(ps *pubsub.PubSub, zmqctx *zmq.Context) {
     answ := ZmqsAskQuestionsAndClose(zmqctx, brain_connect_addr_, [][][]byte{
 
 func QueryLatestEventsAndInjectThem(ps *pubsub.PubSub, zmqctx *zmq.Context) {
     answ := ZmqsAskQuestionsAndClose(zmqctx, brain_connect_addr_, [][][]byte{
-        [][]byte{[]byte("DoorCommandEvent")}, 
-        [][]byte{[]byte("DoorLockUpdate")}, 
-        [][]byte{[]byte("DoorAjarUpdate")}, 
-        [][]byte{[]byte("BackdoorAjarUpdate")}, 
+        [][]byte{[]byte("BackdoorAjarUpdate")},
+        [][]byte{[]byte("DoorCommandEvent")},
+        [][]byte{[]byte("DoorLockUpdate")},
+        [][]byte{[]byte("DoorAjarUpdate")},
         [][]byte{[]byte("PresenceUpdate")},
         [][]byte{[]byte("PresenceUpdate")},
-        [][]byte{[]byte("IlluminationSensorUpdate")}, 
+        [][]byte{[]byte("IlluminationSensorUpdate")},
         [][]byte{[]byte("TempSensorUpdate")}})
     for _, a := range(answ) {
         ParseZMQr3Event(a, ps)
         [][]byte{[]byte("TempSensorUpdate")}})
     for _, a := range(answ) {
         ParseZMQr3Event(a, ps)
@@ -183,7 +185,7 @@ func main() {
     go EventToWeb(ps)
     // --- get update on most recent events ---
     QueryLatestEventsAndInjectThem(ps, zmqctx)
     go EventToWeb(ps)
     // --- get update on most recent events ---
     QueryLatestEventsAndInjectThem(ps, zmqctx)
-    go RunXMPPBot(ps, zmqctx) 
+    go RunXMPPBot(ps, zmqctx)
 
     // --- receive and distribute events ---
     ticker := time.NewTicker(time.Duration(7) * time.Minute)
 
     // --- receive and distribute events ---
     ticker := time.NewTicker(time.Duration(7) * time.Minute)
index e2c4588..293be18 100644 (file)
@@ -226,12 +226,12 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc
             Debug_.Printf("handleEventsforXMPP<-jabber_events: %T %+v", je, je)
             simple_jid := removeJIDResource(je.JID)
             jid_data, jid_in_map := botdata.realraum_jids_[simple_jid]
             Debug_.Printf("handleEventsforXMPP<-jabber_events: %T %+v", je, je)
             simple_jid := removeJIDResource(je.JID)
             jid_data, jid_in_map := botdata.realraum_jids_[simple_jid]
-            
+
             //send status if requested, even if user never changed any settings and thus is not in map
             if last_status_msg != nil && je.StatusNow {
                 xmppout <-  botdata.makeXMPPMessage(je.JID, last_status_msg, nil)
             }
             //send status if requested, even if user never changed any settings and thus is not in map
             if last_status_msg != nil && je.StatusNow {
                 xmppout <-  botdata.makeXMPPMessage(je.JID, last_status_msg, nil)
             }
-            
+
             if jid_in_map {
                 //if R3OnlineOnlyWithRecapInfo, we want a status update when coming online
                 if last_status_msg != nil && ! jid_data.Online && je.Online && jid_data.Wants == R3OnlineOnlyWithRecapInfo {
             if jid_in_map {
                 //if R3OnlineOnlyWithRecapInfo, we want a status update when coming online
                 if last_status_msg != nil && ! jid_data.Online && je.Online && jid_data.Wants == R3OnlineOnlyWithRecapInfo {