Skip to content

Commit

Permalink
Fix handling of empty install date (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Feb 3, 2022
1 parent 45c9b9d commit 1342bfc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pvo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class System(BaseModel):

@validator("install_date", pre=True)
@classmethod
def preparse_date(cls, value: str) -> str: # noqa: F841
def preparse_date(cls, value: str) -> str | None: # noqa: F841
"""Preparse date so Pydantic understands it.
Args:
Expand All @@ -99,4 +99,7 @@ def preparse_date(cls, value: str) -> str: # noqa: F841
Returns:
Preparsed date value.
"""
if not value:
return None

return f"{value[:4]}-{value[4:6]}-{value[6:]}"
24 changes: 24 additions & 0 deletions tests/test_pvoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,27 @@ async def test_get_system(aresponses):
assert system.system_name == "Frenck"
assert system.system_size == 5015
assert system.zipcode == "CO1"


@pytest.mark.asyncio
async def test_get_system_empty_install_date(aresponses):
"""Test get system handling with an empty install date."""
aresponses.add(
"pvoutput.org",
"/service/r2/getsystem.jsp",
"GET",
aresponses.Response(
status=200,
headers={"Content-Type": "text/plain"},
text=(
"Frenck,5015,1234,17,295,JA solar JAM-300,1,5000,"
"SolarEdge SE5000H,S,20.0,Low,,51.1234,6.1234,5;;0"
),
),
)

async with aiohttp.ClientSession() as session:
pvoutput = PVOutput(api_key="fake", system_id=12345, session=session)
system = await pvoutput.system()

assert system.install_date is None

0 comments on commit 1342bfc

Please sign in to comment.