Skip to content

Commit b1a267a

Browse files
Replace pytz with timezone module
This is done for handling UTC timezone without importing the module pytz which is currently installed through pandas. Signed-off-by: Daniel Zullo <[email protected]>
1 parent 7f04fd9 commit b1a267a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/frequenz/sdk/microgrid/component/_component_data.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
from abc import ABC, abstractmethod
88
from dataclasses import dataclass, field
9-
from datetime import datetime
9+
from datetime import datetime, timezone
1010
from typing import List, Optional, Tuple
1111

1212
import frequenz.api.microgrid.battery_pb2 as battery_pb
1313
import frequenz.api.microgrid.inverter_pb2 as inverter_pb
1414
import frequenz.api.microgrid.microgrid_pb2 as microgrid_pb
15-
import pytz
1615

1716
from ._component_states import EVChargerCableState, EVChargerComponentState
1817

@@ -93,7 +92,7 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> MeterData:
9392
"""
9493
meter_data = cls(
9594
component_id=raw.id,
96-
timestamp=raw.ts.ToDatetime(tzinfo=pytz.UTC),
95+
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
9796
active_power=raw.meter.data.ac.power_active.value,
9897
current_per_phase=(
9998
raw.meter.data.ac.phase_1.current.value,
@@ -166,7 +165,7 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
166165
"""
167166
battery_data = cls(
168167
component_id=raw.id,
169-
timestamp=raw.ts.ToDatetime(tzinfo=pytz.UTC),
168+
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
170169
soc=raw.battery.data.soc.avg,
171170
soc_lower_bound=raw.battery.data.soc.system_bounds.lower,
172171
soc_upper_bound=raw.battery.data.soc.system_bounds.upper,
@@ -221,7 +220,7 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
221220
"""
222221
inverter_data = cls(
223222
component_id=raw.id,
224-
timestamp=raw.ts.ToDatetime(tzinfo=pytz.UTC),
223+
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
225224
active_power=raw.inverter.data.ac.power_active.value,
226225
active_power_lower_bound=raw.inverter.data.ac.power_active.system_bounds.lower,
227226
active_power_upper_bound=raw.inverter.data.ac.power_active.system_bounds.upper,
@@ -272,7 +271,7 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> EVChargerData:
272271
"""
273272
ev_charger_data = cls(
274273
component_id=raw.id,
275-
timestamp=raw.ts.ToDatetime(tzinfo=pytz.UTC),
274+
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
276275
active_power=raw.ev_charger.data.ac.power_active.value,
277276
current_per_phase=(
278277
raw.ev_charger.data.ac.phase_1.current.value,

tests/actor/test_battery_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def battery_data(
5353
Args:
5454
component_id: component id
5555
timestamp: Timestamp of the component message.
56-
Defaults to datetime.now(tz=pytz.utc).
56+
Defaults to datetime.now(tz=timezone.utc).
5757
relay_state: Battery relay state.
5858
Defaults to BatteryRelayState.RELAY_STATE_CLOSED.
5959
component_state: Component state.
@@ -88,7 +88,7 @@ def inverter_data(
8888
Args:
8989
component_id: component id
9090
timestamp: Timestamp of the component message.
91-
Defaults to datetime.now(tz=pytz.utc).
91+
Defaults to datetime.now(tz=timezone.utc).
9292
component_state: Component state.
9393
Defaults to InverterState.CHARGING.
9494
errors: List of the components error. By default empty list will be created.

0 commit comments

Comments
 (0)