From b1928496cc4a7fc4008b238fb22a7ceb822544f3 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Mon, 31 Oct 2022 02:14:13 -0400 Subject: [PATCH] add exceptions to entityListener --- entitylistener.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/entitylistener.go b/entitylistener.go index 3c3d281..67ca2a5 100644 --- a/entitylistener.go +++ b/entitylistener.go @@ -9,16 +9,21 @@ import ( ) type EntityListener struct { - entityIds []string - callback EntityListenerCallback - fromState string - toState string + entityIds []string + callback EntityListenerCallback + fromState string + toState string + throttle time.Duration + lastRan carbon.Carbon + betweenStart string betweenEnd string - throttle time.Duration - lastRan carbon.Carbon - delay time.Duration - delayTimer *time.Timer + + delay time.Duration + delayTimer *time.Timer + + exceptionDays []time.Time + exceptionRanges []timeRange } type EntityListenerCallback func(*Service, EntityData) @@ -125,6 +130,16 @@ func (b elBuilder3) Throttle(s DurationString) elBuilder3 { 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 { return b.entityListener } @@ -158,6 +173,12 @@ func callEntityListeners(app *app, msgBytes []byte) { if c := checkThrottle(l.throttle, l.lastRan); c.fail { continue } + if c := checkExceptionDays(l.exceptionDays); c.fail { + continue + } + if c := checkExceptionRanges(l.exceptionRanges); c.fail { + continue + } entityData := EntityData{ TriggerEntityId: eid,