125 lines
5.3 KiB
Go
125 lines
5.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"strings"
|
|
|
|
"github.com/probakowski/go-satel"
|
|
)
|
|
|
|
type MsgContent struct {
|
|
SatelEvent satel.Event
|
|
}
|
|
|
|
type GenericMessage struct {
|
|
ChatIds ChatId
|
|
Messages []MsgContent
|
|
}
|
|
|
|
func (self GenericMessage) Format(template *template.Template) string {
|
|
b := strings.Builder{}
|
|
template.Execute(&b, self)
|
|
return b.String()
|
|
}
|
|
|
|
func getEmojiWhenTrueIsGood(v bool) string {
|
|
if v {
|
|
return "✅"
|
|
} else {
|
|
return "🔴"
|
|
}
|
|
}
|
|
|
|
func getEmojiWhenTrueIsBad(v bool) string {
|
|
if v {
|
|
return "🔴"
|
|
} else {
|
|
return "✅"
|
|
}
|
|
}
|
|
|
|
func (self MsgContent) FormatEvent() string {
|
|
switch self.SatelEvent.Type {
|
|
case satel.ZoneViolation:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.ZoneTamper:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.ZoneAlarm:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.ZoneTamperAlarm:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.ZoneAlarmMemory:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ZoneTamperAlarmMemory:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ZoneBypass:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ZoneNoViolationTrouble:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ZoneLongViolationTrouble:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ArmedPartitionSuppressed:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ArmedPartition:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsGood(self.SatelEvent.Value))
|
|
case satel.PartitionArmedInMode2:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionArmedInMode3:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionWith1stCodeEntered:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionEntryTime:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionExitTimeOver10s:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionExitTimeUnder10s:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionTemporaryBlocked:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionBlockedForGuardRound:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionAlarm:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.PartitionFireAlarm:
|
|
return fmt.Sprintf("%s: %s", self.SatelEvent.Type.String(), getEmojiWhenTrueIsBad(self.SatelEvent.Value))
|
|
case satel.PartitionAlarmMemory:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionFireAlarmMemory:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.Output:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.DoorOpened:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.DoorOpenedLong:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.StatusBit:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroublePart1:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroublePart2:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroublePart3:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroublePart4:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroublePart5:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroubleMemoryPart1:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroubleMemoryPart2:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroubleMemoryPart3:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroubleMemoryPart4:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.TroubleMemoryPart5:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.PartitionWithViolatedZones:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
case satel.ZoneIsolate:
|
|
return fmt.Sprintf("%s: %t", self.SatelEvent.Type.String(), self.SatelEvent.Value)
|
|
}
|
|
panic(fmt.Sprint("Unknown event received: ", self.SatelEvent))
|
|
}
|