Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a NPE bug. #111

Merged
merged 2 commits into from
Dec 25, 2023
Merged

Fix a NPE bug. #111

merged 2 commits into from
Dec 25, 2023

Conversation

thomaskistler
Copy link
Contributor

To address a potential NullPointerException (NPE), this fix handles cases where the flowSummary() method returns an empty result.

The code now explicitly checks for an empty result from flowSummary(). If an empty result is detected, an empty SensorFlowSummary object is created and returned instead.

@thomaskistler thomaskistler changed the title Fixed a NPE bug. Fix a NPE bug. Dec 21, 2023
@dknowles2
Copy link
Owner

Can you add a test for this?

@dknowles2 dknowles2 added the bug Something isn't working label Dec 21, 2023
@thomaskistler
Copy link
Contributor Author

I added a test.

Also fixed an issue I ran into with the watering reports. It looks like Hydrawise does not strictly honor the start time and end time provided to the call. Hence we need to filter out events that happen before and after the provided time range. I updated the tests to cover this case as well.

@dknowles2
Copy link
Owner

Please split this into two PRs.

@@ -503,18 +504,26 @@ async def test_get_sensors(
assert "sensors {" in query


@pytest.mark.parametrize("scenario", [pytest.param("present"), pytest.param("missing")])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way pytest intends you to do this is to use Indirect parametrization. Something like this:

@fixture
def flow_summary_json(param):
  if param:
    yield {"valid": "json"}
  else:
    yield None


@pytest.mark.parametrize("flow_summary_json", (True, False), indirect=True)
def test_get_water_flow_summary(..., flow_summary_json):
  ...
  mock_session.execute.return_value = {"controller": {"sensors": [flow_sensor_json | {"flowSummary": flow_summary_json}]}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that. Thanks. Fixed.

@dknowles2 dknowles2 merged commit cacc69a into dknowles2:main Dec 25, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants