mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 15:15:14 -06:00
add state as second arg for eventListenerCallback
This commit is contained in:
9
app.go
9
app.go
@@ -86,6 +86,15 @@ func (a *App) RegisterSchedules(schedules ...Schedule) {
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
// TODO: on the day that daylight savings starts/ends,
|
||||
// this results in schedules being an hour late or hour early because
|
||||
// StartOfDay() occurs before the switch. This happens if you start
|
||||
// gome assistant on this day, and VERIFY I think will persist until you
|
||||
// start it again. Sunrise/sunset should be unaffected since those come
|
||||
// from HA.
|
||||
//
|
||||
// IDEA: splitting schedule into Interval and DailySchedule could address this on schedule
|
||||
// side, by using SetTime instead of Add(time.Duration).
|
||||
startTime := carbon.Now().StartOfDay().Carbon2Time()
|
||||
// apply offset if set
|
||||
if s.offset.Minutes() > 0 {
|
||||
|
||||
@@ -26,7 +26,8 @@ type EntityListener struct {
|
||||
exceptionRanges []timeRange
|
||||
}
|
||||
|
||||
// TODO: add state object as second arg
|
||||
// TODO: add RunOnStartup() to etl, evl, schedule
|
||||
|
||||
type EntityListenerCallback func(*Service, *State, EntityData)
|
||||
|
||||
type EntityData struct {
|
||||
|
||||
@@ -22,7 +22,7 @@ type EventListener struct {
|
||||
}
|
||||
|
||||
// TODO: add state object as second arg
|
||||
type EventListenerCallback func(*Service, EventData)
|
||||
type EventListenerCallback func(*Service, *State, EventData)
|
||||
|
||||
type EventData struct {
|
||||
Type string
|
||||
@@ -130,7 +130,7 @@ func callEventListeners(app *App, msg ws.ChanMsg) {
|
||||
Type: baseEventMsg.Event.EventType,
|
||||
RawEventJSON: msg.Raw,
|
||||
}
|
||||
go l.callback(app.service, eventData)
|
||||
go l.callback(app.service, app.state, eventData)
|
||||
l.lastRan = carbon.Now()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func pantryLights(service *ga.Service, state *ga.State, sensor ga.EntityData) {
|
||||
}
|
||||
}
|
||||
|
||||
func onEvent(service *ga.Service, data ga.EventData) {
|
||||
func onEvent(service *ga.Service, state *ga.State, data ga.EventData) {
|
||||
// Since the structure of the event changes depending
|
||||
// on the event type, you can Unmarshal the raw json
|
||||
// into a Go type. If a type for your event doesn't
|
||||
|
||||
Reference in New Issue
Block a user