refactor: move types out of app.go into types/, renamed module files

This commit is contained in:
2025-08-01 18:08:01 -05:00
parent 3d178ad05e
commit 21358b73e1
13 changed files with 105 additions and 88 deletions

View File

@@ -9,13 +9,14 @@ import (
"github.com/golang-module/carbon"
internal "github.com/Xevion/go-ha/internal"
"github.com/Xevion/go-ha/types"
)
type State interface {
AfterSunrise(...DurationString) bool
BeforeSunrise(...DurationString) bool
AfterSunset(...DurationString) bool
BeforeSunset(...DurationString) bool
AfterSunrise(...types.DurationString) bool
BeforeSunrise(...types.DurationString) bool
AfterSunset(...types.DurationString) bool
BeforeSunset(...types.DurationString) bool
ListEntities() ([]EntityState, error)
Get(entityId string) (EntityState, error)
Equals(entityId, state string) (bool, error)
@@ -99,20 +100,20 @@ func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error)
return currentState.State == expectedState, nil
}
func (s *StateImpl) BeforeSunrise(offset ...DurationString) bool {
func (s *StateImpl) BeforeSunrise(offset ...types.DurationString) bool {
sunrise := getSunriseSunset(s /* sunrise = */, true, carbon.Now(), offset...)
return carbon.Now().Lt(sunrise)
}
func (s *StateImpl) AfterSunrise(offset ...DurationString) bool {
func (s *StateImpl) AfterSunrise(offset ...types.DurationString) bool {
return !s.BeforeSunrise(offset...)
}
func (s *StateImpl) BeforeSunset(offset ...DurationString) bool {
func (s *StateImpl) BeforeSunset(offset ...types.DurationString) bool {
sunset := getSunriseSunset(s /* sunrise = */, false, carbon.Now(), offset...)
return carbon.Now().Lt(sunset)
}
func (s *StateImpl) AfterSunset(offset ...DurationString) bool {
func (s *StateImpl) AfterSunset(offset ...types.DurationString) bool {
return !s.BeforeSunset(offset...)
}