"regexp"
"strconv"
"time"
+ "bytes"
//~ "./brain"
pubsub "github.com/tuxychandru/pubsub"
zmq "github.com/vaughan0/go-zmq"
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":
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:
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}
}
}
}
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)
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)
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 {