Repository: klaasnicolaas/python-energyzero (language: python)

Issue:
Gasprices
No value available for gasprices between 0:00 hr en 06:00 hr


Discussion / hints:

Fix patch:
diff --git a/energyzero/energyzero.py b/energyzero/energyzero.py
index c1d3dfc..c19ea2b 100644
--- a/energyzero/energyzero.py
+++ b/energyzero/energyzero.py
@@ -124,21 +124,23 @@ async def gas_prices(
         """
         start_date_utc: datetime
         end_date_utc: datetime
-        if get_utcnow().hour < 5:
-            # Set start_date to 05:00:00 prev day and the end_date to 04:59:59 UTC
+        if get_utcnow().hour >= 5 and get_utcnow().hour <= 22:
+            # Set start_date to 05:00:00 and the end_date to 04:59:59 UTC next day
             start_date_utc = datetime(
-                start_date.year, start_date.month, start_date.day - 1, 5, 0, 0
+                start_date.year, start_date.month, start_date.day, 5, 0, 0
             )
+            end_date_utc = datetime(
+                end_date.year, end_date.month, end_date.day, 4, 59, 59
+            ) + timedelta(days=1)
+        else:
+            # Set start_date to 05:00:00 prev day and the end_date to 04:59:59 UTC
+            start_date_utc = datetime(
+                start_date.year, start_date.month, start_date.day, 5, 0, 0
+            ) - timedelta(days=1)
             end_date_utc = datetime(
                 end_date.year, end_date.month, end_date.day, 4, 59, 59
             )
-        # Set start_date to 05:00:00 and the end_date to 04:59:59 UTC next day
-        start_date_utc = datetime(
-            start_date.year, start_date.month, start_date.day, 5, 0, 0
-        )
-        end_date_utc = datetime(
-            end_date.year, end_date.month, end_date.day + 1, 4, 59, 59
-        )
+
         data = await self._request(
             "energyprices",
             params={


Test patch:
diff --git a/test_output.py b/test_output.py
index 4ca0d19..fa32552 100644
--- a/test_output.py
+++ b/test_output.py
@@ -11,9 +11,9 @@
 async def main() -> None:
     """Show example on fetching the energy prices from EnergyZero."""
     async with EnergyZero() as client:
-        local = pytz.timezone("Europe/Amsterdam")
-        today = date(2022, 12, 28)
-        tomorrow = date(2022, 12, 28)
+        local = pytz.timezone("CET")
+        today = date(2022, 12, 30)
+        tomorrow = date(2022, 12, 30)
 
         # Select your test readings
         energy_reading: bool = True
diff --git a/tests/test_models.py b/tests/test_models.py
index a5a9bb3..a0b8d3f 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -97,6 +97,9 @@ async def test_no_electricity_data(aresponses: ResponsesMockServer) -> None:
 
 
 @pytest.mark.asyncio
+@patch(
+    "energyzero.energyzero.get_utcnow", Mock(return_value=datetime(2022, 12, 7, 14, 0))
+)
 @patch(
     "energyzero.models.Gas.utcnow",
     Mock(return_value=datetime(2022, 12, 7, 14, 0).replace(tzinfo=timezone.utc)),
@@ -128,9 +131,6 @@ async def test_gas_model(aresponses: ResponsesMockServer) -> None:
 
 
 @pytest.mark.asyncio
-@patch(
-    "energyzero.energyzero.get_utcnow", Mock(return_value=datetime(2022, 12, 7, 4, 0))
-)
 @patch(
     "energyzero.models.Gas.utcnow",
     Mock(return_value=datetime(2022, 12, 7, 5, 0).replace(tzinfo=timezone.utc)),