diff --git a/app.go b/app.go index 3e4d028..449b688 100644 --- a/app.go +++ b/app.go @@ -43,7 +43,7 @@ func NewApp(connString string) app { httpClient := http.NewHttpClient(connString, token) service := NewService(conn, ctx, httpClient) - state := NewState(httpClient) + state := newState(httpClient) return app{ conn: conn, @@ -159,7 +159,7 @@ func carbon2TimeString(c carbon.Carbon) string { func (a *app) Start() { // schedules - go RunSchedules(a) + go runSchedules(a) // subscribe to state_changed events id := internal.GetId() diff --git a/entitylistener.go b/entitylistener.go index f7a4db4..c742589 100644 --- a/entitylistener.go +++ b/entitylistener.go @@ -138,16 +138,16 @@ func callEntityListeners(app *app, msgBytes []byte) { for _, l := range listeners { // Check conditions - if c := CheckWithinTimeRange(l.betweenStart, l.betweenEnd); c.fail { + if c := checkWithinTimeRange(l.betweenStart, l.betweenEnd); c.fail { return } - if c := CheckStatesMatch(l.fromState, data.OldState.State); c.fail { + if c := checkStatesMatch(l.fromState, data.OldState.State); c.fail { return } - if c := CheckStatesMatch(l.toState, data.NewState.State); c.fail { + if c := checkStatesMatch(l.toState, data.NewState.State); c.fail { return } - if c := CheckThrottle(l.throttle, l.lastRan); c.fail { + if c := checkThrottle(l.throttle, l.lastRan); c.fail { return } diff --git a/eventListener.go b/eventListener.go index 98d3175..a3ce691 100644 --- a/eventListener.go +++ b/eventListener.go @@ -105,10 +105,10 @@ func callEventListeners(app *app, msg ws.ChanMsg) { for _, l := range listeners { // Check conditions - if c := CheckWithinTimeRange(l.betweenStart, l.betweenEnd); c.fail { + if c := checkWithinTimeRange(l.betweenStart, l.betweenEnd); c.fail { return } - if c := CheckThrottle(l.throttle, l.lastRan); c.fail { + if c := checkThrottle(l.throttle, l.lastRan); c.fail { return } diff --git a/listeners.go b/listeners.go index 1e21f1f..e32c55f 100644 --- a/listeners.go +++ b/listeners.go @@ -11,7 +11,7 @@ type conditionCheck struct { fail bool } -func CheckWithinTimeRange(startTime, endTime string) conditionCheck { +func checkWithinTimeRange(startTime, endTime string) conditionCheck { cc := conditionCheck{fail: false} // if betweenStart and betweenEnd both set, first account for midnight // overlap, then check if between those times. @@ -42,7 +42,7 @@ func CheckWithinTimeRange(startTime, endTime string) conditionCheck { return cc } -func CheckStatesMatch(listenerState, s string) conditionCheck { +func checkStatesMatch(listenerState, s string) conditionCheck { cc := conditionCheck{fail: false} // check if fromState or toState are set and don't match if listenerState != "" && listenerState != s { @@ -51,7 +51,7 @@ func CheckStatesMatch(listenerState, s string) conditionCheck { return cc } -func CheckThrottle(throttle time.Duration, lastRan carbon.Carbon) conditionCheck { +func checkThrottle(throttle time.Duration, lastRan carbon.Carbon) conditionCheck { cc := conditionCheck{fail: false} // check if Throttle is set and that duration hasn't passed since lastRan if throttle.Seconds() > 0 && diff --git a/schedule.go b/schedule.go index b726a70..ef6c319 100644 --- a/schedule.go +++ b/schedule.go @@ -138,7 +138,7 @@ func getFunctionName(i interface{}) string { } // app.Start() functions -func RunSchedules(a *app) { +func runSchedules(a *app) { if a.schedules.Len() == 0 { return } @@ -167,6 +167,11 @@ func popSchedule(a *app) schedule { } func requeueSchedule(a *app, s schedule) { + // TODO: figure out how to handle sunset/sunrise in here. Maybe just + // add sunrise bool and sunset bool to Schedule, might have to change + // API to be .Call().Sunset("1h") instead of .Call().At(ga.Sunset("1h")) + // then that function could easily set the flag. Kinda ruins the english + // language sentence structure but maybe simplest way to get it working s.realStartTime = s.realStartTime.Add(s.frequency) a.schedules.Insert(s, float64(s.realStartTime.Unix())) } diff --git a/state.go b/state.go index ba153d1..6e86253 100644 --- a/state.go +++ b/state.go @@ -17,10 +17,9 @@ type EntityState struct { State string `json:"state"` Attributes map[string]any `json:"attributes"` LastChanged time.Time `json:"last_changed"` - LastUpdated time.Time `json:"last_updated"` } -func NewState(c *http.HttpClient) *State { +func newState(c *http.HttpClient) *State { return &State{httpClient: c} }