eventdb

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCloudSendEventAge = 24 * time.Hour

If we're resyncing with the cloud, then ignore events older than this. If this was infinite, and a system was connected to the cloud for the first time, then there could be a gigantic backlog. So we need to limit this.

View Source
const MaxEventCount = 100000

Maximum number of events to keep in the database.

Variables

This section is empty.

Functions

func Migrations

func Migrations(log logs.Log) []migration.Migrator

Types

type AlarmCause

type AlarmCause string
const (
	// SYNC-ALARM-CAUSES
	AlarmCauseCameraObject AlarmCause = "camera-object" // Camera detected an object
	AlarmCausePanic        AlarmCause = "panic"         // Panic button pressed
)

type Event

type Event struct {
	ID        int64                       `json:"id" gorm:"primaryKey"`
	Time      dbh.IntTime                 `json:"time" gorm:"not null"`
	EventType EventType                   `json:"eventType" gorm:"not null"`
	Detail    *dbh.JSONField[EventDetail] `json:"detail"`
	InCloud   bool                        `json:"inCloud" gorm:"not null"` // True if we've sent to the cloud
}

SYNC-EVENT

type EventDB

type EventDB struct {
	Log logs.Log
	DB  *gorm.DB
	// contains filtered or unexported fields
}

EventDB tracks high level events, such as alarm activations

func NewEventDB

func NewEventDB(logger logs.Log, dbFilename string) (*EventDB, error)

func (*EventDB) AddEvent

func (e *EventDB) AddEvent(eventType EventType, detail *EventDetail) error

func (*EventDB) AddListener

func (e *EventDB) AddListener(listener chan *Event)

Add listener channel that will receive new events. Your channel should not block - give it a buffer and keep it drained.

func (*EventDB) Arm

func (e *EventDB) Arm(userID int64, deviceID string) error

func (*EventDB) ArmDisarm

func (e *EventDB) ArmDisarm(arm bool, userID int64, deviceID string) error

func (*EventDB) Disarm

func (e *EventDB) Disarm(userID int64, deviceID string) error

func (*EventDB) GetCloudQueue

func (e *EventDB) GetCloudQueue() ([]*Event, error)

Get the list of events that need to be sent to the cloud, from oldest to newest

func (*EventDB) IsAlarmTriggered

func (e *EventDB) IsAlarmTriggered() bool

func (*EventDB) IsArmed

func (e *EventDB) IsArmed() bool

func (*EventDB) IsArmedAndUntriggered

func (e *EventDB) IsArmedAndUntriggered() bool

func (*EventDB) MarkInCloud

func (e *EventDB) MarkInCloud(eventIDs []int64) error

Mark the given events as being sent to the cloud.

func (*EventDB) Panic

func (e *EventDB) Panic(userID int64, deviceID string)

Trigger the alarm immediately, regardless of whether the system is armed or not

type EventDetail

type EventDetail struct {
	UserID     int64      `json:"userID,omitempty"`     // Populated for arm,disarm,panic
	DeviceID   string     `json:"deviceID,omitempty"`   // Populated for arm,disarm,panic
	AlarmCause AlarmCause `json:"alarmCause,omitempty"` // Populated for any alarm
	CameraID   int64      `json:"cameraID,omitempty"`   // Populated for alarm, if cause is "camera-object"
}

SYNC-EVENT-DETAIL

type EventType

type EventType string

Type of event (eg arm, disarm, alarm)

const (
	// SYNC-EVENT-TYPES
	EventTypeArm    EventType = "arm"    // Arm the system
	EventTypeDisarm EventType = "disarm" // Disarm the system
	EventTypeAlarm  EventType = "alarm"  // Alarm event, triggered by a camera
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL