Skip to content

Commit caa2404

Browse files
committed
Fix inconsistencies in OMI group
1 parent c2c3450 commit caa2404

2 files changed

Lines changed: 57 additions & 24 deletions

File tree

src/entsoe/OMI/OMI.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ class OMI(Base):
1010
def __init__(
1111
self,
1212
security_token: str,
13+
control_area_domain: str, # Required - EIC code of Scheduling Area
1314
period_start: Optional[int] = None,
1415
period_end: Optional[int] = None,
15-
# Domain parameters - required based on query type
16-
control_area_domain: Optional[str] = None,
1716
# Alternative period parameters for update-based queries
1817
period_start_update: Optional[int] = None,
1918
period_end_update: Optional[int] = None,
@@ -30,11 +29,11 @@ def __init__(
3029
3130
Args:
3231
security_token: API security token
32+
control_area_domain: EIC code of Scheduling Area (required)
3333
period_start: Start period (YYYYMMDDHHMM format, optional if
34-
period_start_update is defined)
34+
period_start_update and period_end_update are defined)
3535
period_end: End period (YYYYMMDDHHMM format, optional if
36-
period_end_update is defined)
37-
control_area_domain: EIC code of Scheduling Area (typically required)
36+
period_start_update and period_end_update are defined)
3837
period_start_update: Start of update period (YYYYMMDDHHMM format,
3938
mandatory if period_start and period_end not defined)
4039
period_end_update: End of update period (YYYYMMDDHHMM format,
@@ -48,13 +47,17 @@ def __init__(
4847
4948
Raises:
5049
ValueError: If doc_status is not one of A05, A09, A13
50+
ValueError: If neither (period_start, period_end) nor
51+
(period_start_update, period_end_update) are provided
5152
5253
Notes:
5354
- Document type is fixed to B47 (Other Market Information)
5455
- Used for various market notifications and information not covered
5556
by other specific document types
5657
- Supports both standard period queries and update-based queries
5758
- Time range limitations may apply depending on query type
59+
- Either (period_start, period_end) OR (period_start_update,
60+
period_end_update) must be provided
5861
"""
5962
# Validate doc_status if provided
6063
if doc_status is not None:
@@ -64,25 +67,33 @@ def __init__(
6467
f"doc_status must be one of {valid_statuses}, got: {doc_status}"
6568
)
6669

70+
# Validate that either (period_start, period_end) or
71+
# (period_start_update, period_end_update) are provided
72+
has_period = period_start is not None and period_end is not None
73+
has_update_period = (
74+
period_start_update is not None and period_end_update is not None
75+
)
76+
77+
if not has_period and not has_update_period:
78+
raise ValueError(
79+
"Either (period_start, period_end) or "
80+
"(period_start_update, period_end_update) must be provided"
81+
)
82+
6783
# Initialize base parameters using proper encapsulation
6884
super().__init__(
6985
document_type="B47", # Fixed to B47 for Other Market Information
7086
security_token=security_token,
7187
period_start=period_start,
7288
period_end=period_end,
7389
timeout=timeout,
74-
offset=offset,
90+
offset=0, # Don't pass offset to base, we'll handle it with correct name
7591
)
7692

77-
# Add update period parameters
78-
self.add_update_params(
79-
period_start_update=period_start_update,
80-
period_end_update=period_end_update,
81-
)
82-
83-
# Add domain parameters
84-
self.add_domain_params(control_area_domain=control_area_domain)
85-
86-
# Add OMI-specific parameters
87-
self.add_optional_param("docStatus", doc_status)
93+
# Add OMI-specific parameters using exact JSON parameter names
94+
self.add_optional_param("ControlArea_Domain", control_area_domain)
95+
self.add_optional_param("DocStatus", doc_status)
96+
self.add_optional_param("PeriodStartUpdate", period_start_update)
97+
self.add_optional_param("PeriodEndUpdate", period_end_update)
98+
self.add_optional_param("Offset", offset)
8899
self.add_optional_param("mRID", m_rid)

tests/test_encapsulation.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def test_omi_parameter_initialization(self):
1414
class methods."""
1515
omi = OMI(
1616
security_token="test_token",
17+
control_area_domain="10YBE----------2",
1718
period_start=202301010000,
1819
period_end=202301020000,
19-
control_area_domain="10YBE----------2",
2020
doc_status="A05",
2121
m_rid="test_mrid",
2222
offset=100,
@@ -27,21 +27,28 @@ class methods."""
2727
assert omi.params["securityToken"] == "test_token"
2828
assert omi.params["periodStart"] == 202301010000
2929
assert omi.params["periodEnd"] == 202301020000
30-
assert omi.params["controlArea_Domain"] == "10YBE----------2"
31-
assert omi.params["docStatus"] == "A05"
30+
assert omi.params["ControlArea_Domain"] == "10YBE----------2"
31+
assert omi.params["DocStatus"] == "A05"
3232
assert omi.params["mRID"] == "test_mrid"
33-
assert omi.params["offset"] == 100
33+
assert omi.params["Offset"] == 100
3434

3535
def test_omi_optional_periods(self):
36-
"""Test that OMI class handles optional period parameters correctly."""
36+
"""Test that OMI class handles period parameters correctly - either
37+
standard or update periods must be provided."""
38+
# Test with update periods instead of standard periods
3739
omi = OMI(
3840
security_token="test_token",
3941
control_area_domain="10YBE----------2",
42+
period_start_update=202301010000,
43+
period_end_update=202301020000,
4044
)
4145

42-
# Verify that optional period parameters are not included
46+
# Verify that standard period parameters are not included
4347
assert "periodStart" not in omi.params
4448
assert "periodEnd" not in omi.params
49+
# But update period parameters should be included
50+
assert omi.params["PeriodStartUpdate"] == 202301010000
51+
assert omi.params["PeriodEndUpdate"] == 202301020000
4552
assert omi.params["documentType"] == "B47"
4653
assert omi.params["securityToken"] == "test_token"
4754

@@ -92,7 +99,20 @@ def test_omi_validation_error(self):
9299
with pytest.raises(ValueError, match="doc_status must be one of"):
93100
OMI(
94101
security_token="test_token",
95-
doc_status="INVALID",
102+
control_area_domain="10YBE----------2",
103+
period_start=202301010000,
104+
period_end=202301020000,
105+
doc_status="INVALID", # type: ignore
106+
)
107+
108+
def test_omi_period_validation_error(self):
109+
"""Test that OMI class requires either standard or update periods."""
110+
with pytest.raises(
111+
ValueError, match="Either \\(period_start, period_end\\) or"
112+
):
113+
OMI(
114+
security_token="test_token",
115+
control_area_domain="10YBE----------2",
96116
)
97117

98118
def test_encapsulation_no_direct_params_access(self):
@@ -101,6 +121,8 @@ def test_encapsulation_no_direct_params_access(self):
101121
omi = OMI(
102122
security_token="test_token",
103123
control_area_domain="10YBE----------2",
124+
period_start=202301010000,
125+
period_end=202301020000,
104126
)
105127

106128
# The params dictionary should be properly initialized through Base

0 commit comments

Comments
 (0)