From b13a048a21a3b0635f3d449571e8b920136cb2a5 Mon Sep 17 00:00:00 2001 From: Bartosz Wieczorek Date: Wed, 10 Sep 2025 13:47:40 +0200 Subject: [PATCH] add shedule by date --- src/app.py | 10 ++++++++-- .../VictronShedule.py | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app.py b/src/app.py index ad1c142..b18dc73 100644 --- a/src/app.py +++ b/src/app.py @@ -4,6 +4,8 @@ from __future__ import annotations import os import sys +from datetime import datetime, timedelta + from os.path import dirname sys.path.append(dirname(__file__)) @@ -40,5 +42,9 @@ vic = VictronShedule.VictronPriceDailyWriter( calculator=calc ) -prices = vic.build_buy_price_schedule() -print(prices) \ No newline at end of file + +prices = vic.build_buy_price_schedule_by_date(datetime.now().date()) +print(prices) + +prices = vic.build_buy_price_schedule_by_date(datetime.now().date() + timedelta(days=1)) +print(prices) diff --git a/src/victron_energy_price_calculator/VictronShedule.py b/src/victron_energy_price_calculator/VictronShedule.py index 10ef05a..4360ede 100644 --- a/src/victron_energy_price_calculator/VictronShedule.py +++ b/src/victron_energy_price_calculator/VictronShedule.py @@ -51,12 +51,9 @@ class VictronPriceDailyWriter: "schedule": self.build_schedule_for_day(d), } - def build_buy_price_schedule(self) -> dict[str, list[dict[str, Any]]] | None: - today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date() - start_date = today_waw + timedelta(days=1) # jutro - + def build_buy_price_schedule_by_date(self, start_date:date) -> dict[str, list[dict[str, Any]]] | None: if not self.calculator.has_rate(local_midnight(start_date, WARSAW_TZ)): - start_date = today_waw + timedelta(days=0) + return None blocks: List[Dict[str, Any]] = [] single_block = self.build_buy_day_block(start_date) @@ -66,6 +63,17 @@ class VictronPriceDailyWriter: return {"buyPriceSchedule": blocks} + def build_buy_price_schedule(self) -> dict[str, list[dict[str, Any]]] | None: + today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date() + start_date = today_waw + timedelta(days=1) # jutro + + prices = self.build_buy_price_schedule_by_date(start_date) + if prices is None: + start_date = today_waw + timedelta(days=0) # dziƛ + + return self.build_buy_price_schedule_by_date(start_date) + + def build_buy_price_schedule_ending_tomorrow(self) -> dict[str, list[dict[str, Any]]] | None: today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date() end_date = today_waw + timedelta(days=0) # jutro