Skip to content

Commit

Permalink
Merge pull request #188 from JaccoR/bugfix-update-min-max-values
Browse files Browse the repository at this point in the history
Make sure the filtered hourprices get updated every hour.
  • Loading branch information
Roeland54 authored Oct 5, 2024
2 parents 8c6e24f + db93d96 commit 264d52e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions custom_components/entsoe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ async def get_energy_prices(self, start_date, end_date):
}
return self.parse_hourprices(await self.fetch_prices(start_date, end_date))

def today_data_available(self):
def update_data(self):
now = dt.now()
if self.today.date() != now.date():
self.logger.debug(f"new day detected: update today and filtered hourprices")
self.today = now.replace(hour=0, minute=0, second=0, microsecond=0)
self.filtered_hourprices = self._filter_calculated_hourprices(self.data)

self.filtered_hourprices = self._filter_calculated_hourprices(self.data)

def today_data_available(self):
return len(self.get_data_today()) > MIN_HOURS

def _filter_calculated_hourprices(self, data):
Expand Down
8 changes: 6 additions & 2 deletions custom_components/entsoe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class EntsoeEntityDescription(SensorEntityDescription):
value_fn: Callable[[dict], StateType] = None


def sensor_descriptions(currency: str, energy_scale: str) -> tuple[EntsoeEntityDescription, ...]:
def sensor_descriptions(
currency: str, energy_scale: str
) -> tuple[EntsoeEntityDescription, ...]:
"""Construct EntsoeEntityDescription."""
return (
EntsoeEntityDescription(
Expand Down Expand Up @@ -132,7 +134,7 @@ async def async_setup_entry(
entity = {}
for description in sensor_descriptions(
currency=config_entry.options.get(CONF_CURRENCY, DEFAULT_CURRENCY),
energy_scale=config_entry.options.get(CONF_ENERGY_SCALE, DEFAULT_ENERGY_SCALE)
energy_scale=config_entry.options.get(CONF_ENERGY_SCALE, DEFAULT_ENERGY_SCALE),
):
entity = description
entities.append(
Expand Down Expand Up @@ -213,6 +215,8 @@ async def async_update(self) -> None:
utcnow().replace(minute=0, second=0) + timedelta(hours=1),
)

self.coordinator.update_data()

if (
self.coordinator.data is not None
and self.coordinator.today_data_available()
Expand Down

0 comments on commit 264d52e

Please sign in to comment.