mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
few things:
- easy comparison of hourMinute with .int() - created Sunset/Sunrise vars of type hourMinute for easy end-user use
This commit is contained in:
24
app.go
24
app.go
@@ -2,7 +2,6 @@ package gomeassistant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/saml-dev/gome-assistant/internal/setup"
|
||||
@@ -17,6 +16,11 @@ type app struct {
|
||||
entityListeners []entityListener
|
||||
}
|
||||
|
||||
var (
|
||||
Sunrise hourMinute = hourMinute{1000, 0}
|
||||
Sunset hourMinute = hourMinute{1001, 0}
|
||||
)
|
||||
|
||||
/*
|
||||
App establishes the websocket connection and returns an object
|
||||
you can use to register schedules and listeners.
|
||||
@@ -43,7 +47,6 @@ func (a *app) Cleanup() {
|
||||
}
|
||||
|
||||
func (a *app) RegisterSchedule(s schedule) {
|
||||
fmt.Println(a.schedules)
|
||||
if s.err != nil {
|
||||
panic(s.err) // something wasn't configured properly when the schedule was built
|
||||
}
|
||||
@@ -56,9 +59,16 @@ func (a *app) RegisterSchedule(s schedule) {
|
||||
startTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) // start at midnight today
|
||||
|
||||
// apply offset if set
|
||||
if s.offset.Hour != 0 || s.offset.Minute != 0 {
|
||||
startTime.Add(time.Hour * time.Duration(s.offset.Hour))
|
||||
startTime.Add(time.Minute * time.Duration(s.offset.Minute))
|
||||
if s.offset.int() != 0 {
|
||||
if s.offset.int() == Sunrise.int() {
|
||||
// TODO: same as sunset w/ sunrise
|
||||
} else if s.offset.int() == Sunset.int() {
|
||||
// TODO: add an http client (w/ token) to *app, use it to get state of sun.sun
|
||||
// to get next sunset time
|
||||
} else {
|
||||
startTime.Add(time.Hour * time.Duration(s.offset.Hour))
|
||||
startTime.Add(time.Minute * time.Duration(s.offset.Minute))
|
||||
}
|
||||
}
|
||||
|
||||
// advance first scheduled time by frequency until it is in the future
|
||||
@@ -70,6 +80,10 @@ func (a *app) RegisterSchedule(s schedule) {
|
||||
a.schedules = append(a.schedules, s)
|
||||
}
|
||||
|
||||
func (a *app) Start() {
|
||||
// TODO: figure out looping listening to messages
|
||||
}
|
||||
|
||||
const (
|
||||
FrequencyMissing time.Duration = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user