add before/after sunset/sunrise to state

This commit is contained in:
Sam Lewis
2022-11-06 16:10:05 -05:00
parent ba9132745e
commit 5afa301f36
3 changed files with 27 additions and 5 deletions
+18
View File
@@ -40,3 +40,21 @@ func (s *State) Equals(entityId string, expectedState string) (bool, error) {
}
return currentState.State == expectedState, nil
}
func (s *State) BeforeSunrise(offset ...DurationString) bool {
sunrise := getSunriseSunsetFromState(s, true, offset...)
return sunrise.IsToday()
}
func (s *State) AfterSunrise(offset ...DurationString) bool {
return !s.BeforeSunrise(offset...)
}
func (s *State) BeforeSunset(offset ...DurationString) bool {
sunset := getSunriseSunsetFromState(s, false, offset...)
return sunset.IsToday()
}
func (s *State) AfterSunset(offset ...DurationString) bool {
return !s.BeforeSunset(offset...)
}