Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/flexmeasures_client/s2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Callable, Coroutine, Dict, Type
from zoneinfo import ZoneInfo

import pydantic
import pytz

try:
from s2python.common import ReceptionStatus, ReceptionStatusValues, RevokeObject
Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(self, max_size: int = 100, timezone: str = "UTC") -> None:

self.outgoing_messages_status = SizeLimitOrderedDict(max_size=max_size)

self._timezone = pytz.timezone(timezone)
self._timezone = ZoneInfo(timezone)

self.discover()

Expand Down
7 changes: 3 additions & 4 deletions src/flexmeasures_client/s2/control_types/FRBC/frbc_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"""

from datetime import datetime, timedelta

import pytz
from zoneinfo import ZoneInfo

try:
from s2python.frbc import (
Expand Down Expand Up @@ -52,14 +51,14 @@ def __init__(
self._schedule_duration = schedule_duration
self._soc_sensor_id = soc_sensor_id
self._rm_discharge_sensor_id = rm_discharge_sensor_id
self._timezone = pytz.timezone(timezone)
self._timezone = ZoneInfo(timezone)

# delay the start of the schedule from the time `valid_from`
# of the FRBC.SystemDescription.
self._valid_from_shift = valid_from_shift

def now(self):
return self._timezone.localize(datetime.now())
return datetime.now(self._timezone)

async def send_storage_status(self, status: FRBCStorageStatus):
await self._fm_client.post_measurements(
Expand Down
4 changes: 2 additions & 2 deletions src/flexmeasures_client/s2/control_types/FRBC/frbc_tunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import math
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import pandas as pd
from requests.exceptions import HTTPError
Expand All @@ -25,7 +26,6 @@
from typing import cast

import pydantic
import pytz

try:
from s2python.common import (
Expand Down Expand Up @@ -153,7 +153,7 @@ def __init__(
self._consumption_price_sensor_id = consumption_price_sensor
self._production_price_sensor_id = production_price_sensor

self._timezone = pytz.timezone(timezone)
self._timezone = ZoneInfo(timezone)

# delay the start of the schedule from the time `valid_from` of the FRBC.SystemDescription
self._valid_from_shift = valid_from_shift
Expand Down
6 changes: 2 additions & 4 deletions src/flexmeasures_client/s2/script/websockets_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
from datetime import datetime
from zoneinfo import ZoneInfo

import aiohttp
import pytz
from s2python.common import (
Commodity,
CommodityQuantity,
Expand Down Expand Up @@ -139,9 +139,7 @@ async def main_s2():
fill_level_range=NumberRange(start_of_range=0.05, end_of_range=0.45),
)

valid_from = pytz.timezone("Europe/Amsterdam").localize(
datetime(2026, 1, 15, 20)
)
valid_from = datetime(2026, 1, 15, 20, tzinfo=ZoneInfo("Europe/Amsterdam"))

system_description_message = FRBCSystemDescription(
message_id=get_unique_id(),
Expand Down
22 changes: 22 additions & 0 deletions tests/s2/test_timezone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from zoneinfo import ZoneInfo

from flexmeasures_client.s2 import Handler
from flexmeasures_client.s2.control_types.FRBC.frbc_simple import FRBCSimple


def test_handler_uses_zoneinfo_timezone():
handler = Handler(timezone="Europe/Amsterdam")

assert handler.now().tzinfo == ZoneInfo("Europe/Amsterdam")


def test_frbc_simple_now_uses_zoneinfo_timezone():
frbc = FRBCSimple(
power_sensor_id=1,
soc_sensor_id=2,
rm_discharge_sensor_id=3,
price_sensor_id=4,
timezone="Europe/Amsterdam",
)

assert frbc.now().tzinfo == ZoneInfo("Europe/Amsterdam")
Loading