//~ "log"
)
-type doorstate struct {
- locked bool
- shut bool
-}
-
func MetaEventRoutine_Presence(ps *pubsub.PubSub) {
//~ var last_door_cmd *DoorCommandEvent
var last_presence bool
var last_movement, last_buttonpress int64
- doorstatemap := make(map[int]doorstate,1)
+ var front_locked, front_shut, back_shut bool = true, true, true
events_chan := ps.Sub("door", "doorcmd", "buttons", "movement")
defer ps.Unsub(events_chan, "door", "doorcmd", "buttons", "movement")
} else {
last_movement = 0
}
- case r3events.ButtonPressUpdate:
+ case r3events.BoreDoomButtonPressEvent:
last_buttonpress = evnt.Ts
new_presence = true
//~ case DoorCommandEvent:
//~ last_door_cmd = &evnt
case r3events.DoorLockUpdate:
- doorstatemap[evnt.DoorID]=doorstate{locked:evnt.Locked, shut:doorstatemap[evnt.DoorID].shut}
+ front_locked = evnt.Locked
case r3events.DoorAjarUpdate:
- doorstatemap[evnt.DoorID]=doorstate{locked:doorstatemap[evnt.DoorID].locked, shut:evnt.Shut}
+ front_shut = evnt.Shut
+ case r3events.BackdoorAjarUpdate:
+ back_shut = evnt.Shut
}
- any_door_unlocked := false
- any_door_ajar := false
- for _, ds := range(doorstatemap) {
- if ds.locked == false {any_door_unlocked = true }
- if ds.shut == false {any_door_ajar = true }
- }
+ any_door_unlocked := ! front_locked
+ any_door_ajar := ! (front_shut && back_shut)
if new_presence != last_presence {
//... skip state check .. we had a definite presence event
type DoorLockUpdate struct {
- DoorID int
Locked bool
Ts int64
}
type DoorAjarUpdate struct {
- DoorID int
+ Shut bool
+ Ts int64
+}
+
+type BackdoorAjarUpdate struct {
Shut bool
Ts int64
}
Ts int64
}
-type ButtonPressUpdate struct {
- Buttonindex int
+type BoreDoomButtonPressEvent struct {
Ts int64
}
case "DoorAjarUpdate":
event := new(DoorAjarUpdate)
err = json.Unmarshal(data[1], event)
+ case "BackdoorAjarUpdate":
+ event := new(DoorAjarUpdate)
+ err = json.Unmarshal(data[1], event)
case "DoorCommandEvent":
event := new(DoorCommandEvent)
err = json.Unmarshal(data[1], event)
- case "ButtonPressUpdate":
- event := new(ButtonPressUpdate)
+ case "BoreDoomButtonPressEvent":
+ event := new(BoreDoomButtonPressEvent)
err = json.Unmarshal(data[1], event)
case "TempSensorUpdate":
event := new(TempSensorUpdate)
func parseSocketInputLine_State(lines [][]byte, ps *pubsub.PubSub, ts int64) {
switch string(lines[0]) {
case "closed":
- ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door")
+ ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
case "opened":
- ps.Pub(r3events.DoorLockUpdate{0, false, ts}, "door")
+ ps.Pub(r3events.DoorLockUpdate{false, ts}, "door")
case "manual": //movement
case "error":
case "reset":
- ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door")
+ ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
case "timeout": //after open | after close
case "opening":
case "closing":
parseSocketInputLine_State(lines[1:], ps, ts)
case "Status:":
if len(lines) < 3 { return }
- ps.Pub(r3events.DoorLockUpdate{0, string(lines[1]) == "closed,", ts}, "door")
- ps.Pub(r3events.DoorAjarUpdate{0, string(lines[len(lines)-1]) == "shut", ts}, "door")
+ ps.Pub(r3events.DoorLockUpdate{string(lines[1]) == "closed,", ts}, "door")
+ ps.Pub(r3events.DoorAjarUpdate{string(lines[len(lines)-1]) == "shut", ts}, "door")
case "Info(card):":
if len(lines) < 3 { return }
if string(lines[2]) != "found" { return }
}
case "Info(ajar):":
if len(lines) < 5 { return }
- ps.Pub(r3events.DoorAjarUpdate{0, string(lines[4]) == "shut", ts}, "door")
+ ps.Pub(r3events.DoorAjarUpdate{string(lines[4]) == "shut", ts}, "door")
case "open", "close", "toggle", "reset":
ps.Pub(r3events.DoorCommandEvent{string(lines[0]), string(lines[1]), string(lines[2]), ts},"doorcmd")
case "photo0":
//try decode r3event
evnt, err := r3events.UnmarshalByteByte2Event(lines)
if err == nil {ps.Pub(evnt, "movement")}
- case "ButtonPressUpdate" :
+ case "BoreDoomButtonPressEvent" :
//try decode r3event
evnt, err := r3events.UnmarshalByteByte2Event(lines)
if err == nil {ps.Pub(evnt, "buttons")}
//~ match_photo := re_photo_.FindStringSubmatch(line)
//~ if match_button != nil {
//~ // brn.Oboite("button0", ts)
- //~ ps.Pub(ButtonPressUpdate{0, ts}, "buttons")
+ //~ ps.Pub(BoreDoomButtonPressEvent{0, ts}, "buttons")
//~ } else if match_temp != nil {
//~ newtemp, err := strconv.ParseFloat((match_temp[1]), 32)
//~ if err == nil {
var present, locked, shut bool = false, true, true
var last_buttonpress int64 = 0
var who string
- button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)"
+ button_msg := "Dooom ! The button has been pressed ! Propably someone is bored and in need of company ! ;-)"
present_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"}
notpresent_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"}
button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"}
case r3events.DoorAjarUpdate:
shut = event.Shut
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: true}
- case r3events.ButtonPressUpdate:
+ case r3events.BoreDoomButtonPressEvent:
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo}
xmpp_presence_events_chan_ <- button_status
last_buttonpress = event.Ts
evnt := new(r3events.MovementSensorUpdate)
err := json.Unmarshal(lines[1],evnt)
if err == nil {ps.Pub(*evnt, "movement")}
- case "ButtonPressUpdate" :
- evnt := new(r3events.ButtonPressUpdate)
+ case "BoreDoomButtonPressEvent" :
+ evnt := new(r3events.BoreDoomButtonPressEvent)
err := json.Unmarshal(lines[1],evnt)
if err == nil {ps.Pub(*evnt, "buttons")}
case "DoorLockUpdate" :
case r3events.DoorLockUpdate:
spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", event.Locked))
publishStateToWeb()
- case r3events.ButtonPressUpdate:
+ case r3events.BoreDoomButtonPressEvent:
statusstate.buttonpress_until = event.Ts + 3600
- spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
+ spaceapidata.AddSpaceEvent("BoreDOOMButton", "check-in", "The button has been pressed")
publishStateToWeb()
case r3events.TempSensorUpdate:
spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke", event.Value))