From: Bernhard Tittelbach Date: Wed, 6 Nov 2013 20:22:46 +0000 (+0000) Subject: distribute DoorProblemEvent X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=36c81737d355f02eb05b150472c9bf44fbf46120;p=svn42.git distribute DoorProblemEvent --- diff --git a/go/r3-eventbroker_zmq/sockettoevent.go b/go/r3-eventbroker_zmq/sockettoevent.go index d8de48e..9e4907e 100644 --- a/go/r3-eventbroker_zmq/sockettoevent.go +++ b/go/r3-eventbroker_zmq/sockettoevent.go @@ -6,6 +6,7 @@ import ( "regexp" "strconv" "time" + "bytes" //~ "./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": - 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": - 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.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": diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index cc63daa..c897e29 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -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} } - 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: @@ -120,6 +120,8 @@ func EventToXMPP(events <- chan interface{}, xmpp_presence_events_chan chan <- i 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{ - [][]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("IlluminationSensorUpdate")}, + [][]byte{[]byte("IlluminationSensorUpdate")}, [][]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 RunXMPPBot(ps, zmqctx) + go RunXMPPBot(ps, zmqctx) // --- receive and distribute events --- ticker := time.NewTicker(time.Duration(7) * time.Minute) diff --git a/go/r3-netstatus/r3xmppbot/r3xmppbot.go b/go/r3-netstatus/r3xmppbot/r3xmppbot.go index e2c4588..293be18 100644 --- a/go/r3-netstatus/r3xmppbot/r3xmppbot.go +++ b/go/r3-netstatus/r3xmppbot/r3xmppbot.go @@ -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] - + //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 {