|
2 | 2 | from datetime import datetime, timedelta
|
3 | 3 |
|
4 | 4 | import pause
|
| 5 | +import requests.exceptions |
5 | 6 | from abscence_handler import AbsenceHandler
|
6 | 7 | from aiohttp import ClientError
|
7 | 8 | from energy_amount import EnergyAmount, EnergyRate
|
@@ -58,7 +59,10 @@ def start(self) -> None:
|
58 | 59 | time_to_sleep_to = now.replace(hour=14, minute=0, second=0, microsecond=0)
|
59 | 60 | if now > time_to_sleep_to:
|
60 | 61 | time_to_sleep_to += timedelta(days=1)
|
61 |
| - self.log.info(f"The price minimum has to re-checked --> Waiting until {time_to_sleep_to}...") |
| 62 | + self.log.info( |
| 63 | + f"The price minimum {next_price_minimum} has to re-checked " |
| 64 | + + f"--> Waiting until {time_to_sleep_to}..." |
| 65 | + ) |
62 | 66 | pause.until(time_to_sleep_to)
|
63 | 67 | self.log.info("Waking up since the the price minimum has to re-checked")
|
64 | 68 | next_price_minimum = self.tibber_api_handler.get_next_price_minimum(True)
|
@@ -110,12 +114,19 @@ def _do_iteration(self, current_energy_rate: float) -> EnergyRate:
|
110 | 114 | "The price minimum has to be re-checked since it is at the end of a day and the price rates for tomorrow are unavailable"
|
111 | 115 | )
|
112 | 116 |
|
113 |
| - expected_power_harvested_till_next_minimum = self.sun_forecast_handler.get_solar_output_in_timeframe( |
114 |
| - timestamp_now, next_price_minimum.timestamp |
115 |
| - ) |
116 |
| - self.log.info( |
117 |
| - f"The expected energy harvested by the sun till the next price minimum is {expected_power_harvested_till_next_minimum}" |
118 |
| - ) |
| 117 | + try: |
| 118 | + expected_power_harvested_till_next_minimum = self.sun_forecast_handler.get_solar_output_in_timeframe( |
| 119 | + timestamp_now, next_price_minimum.timestamp |
| 120 | + ) |
| 121 | + self.log.info( |
| 122 | + f"The expected energy harvested by the sun till the next price minimum is {expected_power_harvested_till_next_minimum}" |
| 123 | + ) |
| 124 | + except requests.exceptions.HTTPError as e: |
| 125 | + if e.response.status_code != 429: |
| 126 | + raise e |
| 127 | + |
| 128 | + self.log.warning("Too many requests to the solar forecast API, using the debug solar output instead") |
| 129 | + expected_power_harvested_till_next_minimum = self.sun_forecast_handler.get_debug_solar_output() |
119 | 130 |
|
120 | 131 | if self.absence_handler.check_for_current_absence():
|
121 | 132 | self.log.info(
|
|
0 commit comments