Skip to content

Commit

Permalink
fix: Fixed target rate not re-evaluating every minute when no rates a…
Browse files Browse the repository at this point in the history
…re available for target period
  • Loading branch information
BottlecapDave committed Oct 5, 2024
1 parent 6882f06 commit c2899ef
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,38 +175,40 @@ def _handle_coordinator_update(self) -> None:
all_rates,
self._config[CONFIG_ROLLING_TARGET_HOURS_LOOK_AHEAD]
)

number_of_slots = math.ceil(target_hours * 2)
weighting = create_weighting(self._config[CONFIG_TARGET_WEIGHTING] if CONFIG_TARGET_WEIGHTING in self._config else None, number_of_slots)

if (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_CONTINUOUS):
self._target_rates = calculate_continuous_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
weighting,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
elif (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_INTERMITTENT):
self._target_rates = calculate_intermittent_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
else:
_LOGGER.error(f"Unexpected target type: {self._config[CONFIG_TARGET_TYPE]}")

if applicable_rates is not None:
number_of_slots = math.ceil(target_hours * 2)
weighting = create_weighting(self._config[CONFIG_TARGET_WEIGHTING] if CONFIG_TARGET_WEIGHTING in self._config else None, number_of_slots)

if (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_CONTINUOUS):
self._target_rates = calculate_continuous_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
weighting,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
elif (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_INTERMITTENT):
self._target_rates = calculate_intermittent_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
else:
_LOGGER.error(f"Unexpected target type: {self._config[CONFIG_TARGET_TYPE]}")

self._attributes["target_times"] = self._target_rates
self._attributes["target_times_last_evaluated"] = current_date
_LOGGER.debug(f"calculated rates: {self._target_rates}")

self._attributes["rates_incomplete"] = applicable_rates is None
self._attributes["target_times"] = self._target_rates
self._attributes["target_times_last_evaluated"] = current_date
_LOGGER.debug(f"calculated rates: {self._target_rates}")

active_result = get_target_rate_info(current_date, self._target_rates, offset)

Expand Down
62 changes: 32 additions & 30 deletions custom_components/octopus_energy/target_rates/target_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,38 +195,40 @@ def _handle_coordinator_update(self) -> None:
all_rates,
is_rolling_target
)

number_of_slots = math.ceil(target_hours * 2)
weighting = create_weighting(self._config[CONFIG_TARGET_WEIGHTING] if CONFIG_TARGET_WEIGHTING in self._config else None, number_of_slots)

if (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_CONTINUOUS):
self._target_rates = calculate_continuous_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
weighting,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
elif (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_INTERMITTENT):
self._target_rates = calculate_intermittent_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
else:
_LOGGER.error(f"Unexpected target type: {self._config[CONFIG_TARGET_TYPE]}")

if applicable_rates is not None:
number_of_slots = math.ceil(target_hours * 2)
weighting = create_weighting(self._config[CONFIG_TARGET_WEIGHTING] if CONFIG_TARGET_WEIGHTING in self._config else None, number_of_slots)

if (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_CONTINUOUS):
self._target_rates = calculate_continuous_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
weighting,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
elif (self._config[CONFIG_TARGET_TYPE] == CONFIG_TARGET_TYPE_INTERMITTENT):
self._target_rates = calculate_intermittent_times(
applicable_rates,
target_hours,
find_highest_rates,
find_last_rates,
min_rate,
max_rate,
hours_mode = self._config[CONFIG_TARGET_HOURS_MODE]
)
else:
_LOGGER.error(f"Unexpected target type: {self._config[CONFIG_TARGET_TYPE]}")

self._attributes["target_times"] = self._target_rates
self._attributes["target_times_last_evaluated"] = current_date
_LOGGER.debug(f"calculated rates: {self._target_rates}")

self._attributes["rates_incomplete"] = applicable_rates is None
self._attributes["target_times"] = self._target_rates
self._attributes["target_times_last_evaluated"] = current_date
_LOGGER.debug(f"calculated rates: {self._target_rates}")

active_result = get_target_rate_info(current_date, self._target_rates, offset)

Expand Down

0 comments on commit c2899ef

Please sign in to comment.