2023-10-12 17:46:43 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
type IBP struct {
|
|
|
|
Spk *IBPRefMap
|
|
|
|
Emp *IBPRefMap
|
|
|
|
}
|
|
|
|
|
2023-10-17 15:05:13 +08:00
|
|
|
func NewIBP() *IBP {
|
2023-10-12 17:46:43 +08:00
|
|
|
return &IBP{
|
2023-10-20 13:13:44 +08:00
|
|
|
Spk: newIBPRefMap(),
|
|
|
|
Emp: newIBPRefMap(),
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type IBPRefMap struct {
|
|
|
|
buttonMap map[string]*Button
|
|
|
|
relayMap map[string]*Relay
|
|
|
|
alarmMap map[string]*Alarm
|
2023-10-17 17:47:19 +08:00
|
|
|
lightMap map[string]*Light
|
2023-10-20 13:13:44 +08:00
|
|
|
keyMap map[string]*Key
|
|
|
|
}
|
|
|
|
|
|
|
|
func newIBPRefMap() *IBPRefMap {
|
|
|
|
return &IBPRefMap{
|
|
|
|
buttonMap: make(map[string]*Button),
|
|
|
|
relayMap: make(map[string]*Relay),
|
|
|
|
alarmMap: make(map[string]*Alarm),
|
|
|
|
lightMap: make(map[string]*Light),
|
|
|
|
keyMap: make(map[string]*Key),
|
|
|
|
}
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) AddButton(btn *Button) {
|
|
|
|
ibp.buttonMap[btn.Id()] = btn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) AddRelay(relay *Relay) {
|
|
|
|
ibp.relayMap[relay.Id()] = relay
|
|
|
|
}
|
|
|
|
|
2023-10-17 17:47:19 +08:00
|
|
|
func (ibp *IBPRefMap) AddLight(light *Light) {
|
|
|
|
ibp.lightMap[light.Id()] = light
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:46:43 +08:00
|
|
|
func (ibp *IBPRefMap) AddAlarm(fmq *Alarm) {
|
|
|
|
ibp.alarmMap[fmq.Id()] = fmq
|
|
|
|
}
|
|
|
|
|
2023-10-20 13:13:44 +08:00
|
|
|
func (ibp *IBPRefMap) AddKey(key *Key) {
|
|
|
|
ibp.keyMap[key.Id()] = key
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:46:43 +08:00
|
|
|
func (ibp *IBPRefMap) Buttons() []*Button {
|
|
|
|
var buttons []*Button
|
|
|
|
for _, b := range ibp.buttonMap {
|
|
|
|
buttons = append(buttons, b)
|
|
|
|
}
|
|
|
|
return buttons
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Relays() []*Relay {
|
|
|
|
var relays []*Relay
|
|
|
|
for _, b := range ibp.relayMap {
|
|
|
|
relays = append(relays, b)
|
|
|
|
}
|
|
|
|
return relays
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Alarms() []*Alarm {
|
|
|
|
var alarms []*Alarm
|
|
|
|
for _, b := range ibp.alarmMap {
|
|
|
|
alarms = append(alarms, b)
|
|
|
|
}
|
|
|
|
return alarms
|
|
|
|
}
|
2023-10-17 17:47:19 +08:00
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Lights() []*Light {
|
|
|
|
var lights []*Light
|
|
|
|
for _, b := range ibp.lightMap {
|
|
|
|
lights = append(lights, b)
|
|
|
|
}
|
|
|
|
return lights
|
|
|
|
}
|
2023-10-20 13:13:44 +08:00
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Keys() []*Key {
|
|
|
|
var keys []*Key
|
|
|
|
for _, b := range ibp.keyMap {
|
|
|
|
keys = append(keys, b)
|
|
|
|
}
|
|
|
|
return keys
|
|
|
|
}
|