mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-08 02:07:21 -06:00
add exceptions to entityListener
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user