remove unnecessary check from throttle check

This commit is contained in:
Sam Lewis
2022-10-17 12:32:26 -04:00
parent 2c5e68903a
commit b92147a6a6
2 changed files with 13 additions and 20 deletions

View File

@@ -178,9 +178,8 @@ func callEntityListeners(app *app, msgBytes []byte) {
} }
// don't run callback if Throttle is set and that duration hasn't passed since lastRan // don't run callback if Throttle is set and that duration hasn't passed since lastRan
if l.throttle.Seconds() > 0 && // throttle is set if l.throttle.Seconds() > 0 &&
!l.lastRan.Eq(carbon.Now().StartOfCentury()) && // lastRan is set aka this callback has been called since starting gomeassistant l.lastRan.DiffAbsInSeconds(carbon.Now()) < int64(l.throttle.Seconds()) {
l.lastRan.DiffAbsInSeconds(carbon.Now()) < int64(l.throttle.Seconds()) { // it's been less than <throttle> seconds since it last ran
return return
} }

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"log" "log"
ga "github.com/saml-dev/gome-assistant" ga "github.com/saml-dev/gome-assistant"
@@ -10,31 +9,26 @@ import (
func main() { func main() {
app := ga.NewApp("192.168.86.67:8123") app := ga.NewApp("192.168.86.67:8123")
defer app.Cleanup() defer app.Cleanup()
s := ga.ScheduleBuilder().Call(lightsOut).Daily().At(app.Sunset("1h")).Build() pantryDoor := ga.
s2 := ga.ScheduleBuilder().Call(lightsOut).Every("2h").Offset("10m").Build() EntityListenerBuilder().
fmt.Println(s2) EntityIds("binary_sensor.pantry_door").
app.RegisterSchedule(s) Call(pantryLights).
app.RegisterSchedule(s2)
simpleListener := ga.EntityListenerBuilder().
EntityIds("group.office_ceiling_lights").
Call(listenerCB).
OnlyAfter("23:03").
// Throttle("5s").
Build() Build()
app.RegisterEntityListener(simpleListener) app.RegisterEntityListener(pantryDoor)
app.Start() app.Start()
} }
func lightsOut(service *ga.Service, state *ga.State) { func pantryLights(service *ga.Service, data ga.EntityData) {
// service.InputDatetime.Set("input_datetime.garage_last_triggered_ts", time.Now()) // service.InputDatetime.Set("input_datetime.garage_last_triggered_ts", time.Now())
// service.HomeAssistant.Toggle("group.living_room_lamps", map[string]any{"brightness_pct": 100}) // service.HomeAssistant.Toggle("group.living_room_lamps", map[string]any{"brightness_pct": 100})
// service.Light.Toggle("light.entryway_lamp", map[string]any{"brightness_pct": 100}) // service.Light.Toggle("light.entryway_lamp", map[string]any{"brightness_pct": 100})
service.HomeAssistant.Toggle("light.entryway_lamp") if data.ToState == "on" {
log.Default().Println("running lightsOut") service.HomeAssistant.TurnOn("switch.pantry_light_2")
// service.HomeAssistant.Toggle("light.entryway_lamp") } else {
// log.Default().Println("A") service.HomeAssistant.TurnOff("switch.pantry_light_2")
}
} }
func cool(service *ga.Service, state *ga.State) { func cool(service *ga.Service, state *ga.State) {