add exceptions to entityListener

This commit is contained in:
Sam Lewis
2022-10-31 02:14:13 -04:00
parent d158524783
commit b1928496cc

View File

@@ -13,12 +13,17 @@ type EntityListener struct {
callback EntityListenerCallback callback EntityListenerCallback
fromState string fromState string
toState string toState string
betweenStart string
betweenEnd string
throttle time.Duration throttle time.Duration
lastRan carbon.Carbon lastRan carbon.Carbon
betweenStart string
betweenEnd string
delay time.Duration delay time.Duration
delayTimer *time.Timer delayTimer *time.Timer
exceptionDays []time.Time
exceptionRanges []timeRange
} }
type EntityListenerCallback func(*Service, EntityData) type EntityListenerCallback func(*Service, EntityData)
@@ -125,6 +130,16 @@ func (b elBuilder3) Throttle(s DurationString) elBuilder3 {
return b return b
} }
func (b elBuilder3) ExceptionDay(t time.Time) elBuilder3 {
b.entityListener.exceptionDays = append(b.entityListener.exceptionDays, t)
return b
}
func (b elBuilder3) ExceptionRange(start, end time.Time) elBuilder3 {
b.entityListener.exceptionRanges = append(b.entityListener.exceptionRanges, timeRange{start, end})
return b
}
func (b elBuilder3) Build() EntityListener { func (b elBuilder3) Build() EntityListener {
return b.entityListener return b.entityListener
} }
@@ -158,6 +173,12 @@ func callEntityListeners(app *app, msgBytes []byte) {
if c := checkThrottle(l.throttle, l.lastRan); c.fail { if c := checkThrottle(l.throttle, l.lastRan); c.fail {
continue continue
} }
if c := checkExceptionDays(l.exceptionDays); c.fail {
continue
}
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
continue
}
entityData := EntityData{ entityData := EntityData{
TriggerEntityId: eid, TriggerEntityId: eid,