Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Sep 12, 2024
1 parent 1f4db15 commit d0e4a3c
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ def min_price(self) -> float:

@property
def current_offset(self) -> int:
self._set_offset()
return self.model.raw_offsets[0].get(datetime.now().hour, 0)
ret = 0
try:
# self._set_offset()
if len(self.model.raw_offsets):
latest_key = max((key for key in self.model.raw_offsets if key <= datetime.now()), default=None)
if latest_key is not None:
ret = self.model.raw_offsets[latest_key]
else:
ret = 0
except KeyError as e:
_LOGGER.error(
f"Unable to get current offset: {e}. raw_offsets: {self.model.raw_offsets}"
)
finally:
return ret

#self.model.current_offset_dict_combined = ret.calculated_offsets

Expand Down

0 comments on commit d0e4a3c

Please sign in to comment.