Skip to content

Commit

Permalink
Merge pull request #84 from kodymallory/use_sunrise
Browse files Browse the repository at this point in the history
Account for sunrise when determining sunset_valid
  • Loading branch information
basbruss authored Mar 26, 2024
2 parents e263a2b + 14ac9ef commit 3b583aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions custom_components/adaptive_cover/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def valid(self) -> bool:
def sunset_valid(self) -> bool:
"""Determine if it is after sunset plus offset."""
sunset = self.sun_data.sunset().replace(tzinfo=None)
condition = datetime.utcnow() > sunset + timedelta(minutes=self.sunset_off)
return condition
sunrise = self.sun_data.sunrise().replace(tzinfo=None)
after_sunset = datetime.utcnow() > (sunset + timedelta(minutes=self.sunset_off))
before_sunrise = datetime.utcnow() < (sunrise - timedelta(minutes=self.sunset_off))
return (after_sunset and before_sunrise)

@property
def default(self) -> float:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/adaptive_cover/sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def sunset(self) -> datetime:
"""Fetch sunset time."""
return self.location.sunset(date.today(), local=False)

def sunrise(self) -> datetime:
"""Fetch tomorrow's sunrise time."""
return self.location.sunrise(date.today() + timedelta(1), local=False)

# def df_today(self)-> pd.DataFrame:
# """Create dataframe with azimuth and elevation data"""
# df_today = pd.DataFrame({"azimuth":self.solar_azimuth, "elevation":self.solar_elevation})
Expand Down

0 comments on commit 3b583aa

Please sign in to comment.