Skip to content
Open
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
2 changes: 1 addition & 1 deletion aioflo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ async def _request(self, method: str, url: str, **kwargs) -> dict:

try:
async with session.request(method, url, **kwargs) as resp:
data: dict = await resp.json(content_type=None)
resp.raise_for_status()
data: dict = await resp.json(content_type=None)
return data
except ClientError as err:
raise RequestError(f"There was an error while requesting {url}") from err
Expand Down
21 changes: 14 additions & 7 deletions aioflo/water.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Define /water endpoints."""
from datetime import datetime
from typing import Awaitable, Callable
from typing import Awaitable, Callable, Optional

from .const import API_V2_BASE
from .util import raise_on_invalid_argument
Expand All @@ -24,6 +24,7 @@ async def get_consumption_info(
start: datetime,
end: datetime,
interval: str = INTERVAL_HOURLY,
device_mac_address: Optional[str] = None,
) -> dict:
"""Return user account data.

Expand All @@ -33,19 +34,25 @@ async def get_consumption_info(
:type start: ``datetime.datetime``
:param end: The end datetime of the range to examine
:type end: ``datetime.datetime``
:param device_mac_address: Limit results to a single device at the location
:type device_mac_address: ``Optional[str]``
:rtype: ``dict``
"""
raise_on_invalid_argument(interval, INTERVALS)

params = {
"endDate": end.isoformat(),
"interval": interval,
"locationId": location_id,
"startDate": start.isoformat(),
}
if device_mac_address:
params["macAddress"] = device_mac_address.replace(":", "")

return await self._request(
"get",
f"{API_V2_BASE}/water/consumption",
params={
"endDate": end.isoformat(),
"interval": interval,
"locationId": location_id,
"startDate": start.isoformat(),
},
params=params,
)

async def get_metrics(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use_parentheses = true

[tool.poetry]
name = "aioflo"
version = "2021.11.0"
version = "2021.11.1"
description = "A Python3, async-friendly library for Flo by Moen Smart Water Detectors"
readme = "README.md"
authors = ["Aaron Bach <bachya1208@gmail.com>"]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ async def test_get_consumption_info(aresponses, auth_success_response):
text=load_fixture("water_consumption_info_response.json"), status=200
),
)
aresponses.add(
"api-gw.meetflo.com",
"/api/v2/water/consumption",
"get",
aresponses.Response(
text=load_fixture("water_consumption_info_response.json"), status=200
),
)

start = datetime(2020, 1, 16, 0, 0)
end = datetime(2020, 1, 16, 23, 59, 59, 999000)
Expand All @@ -45,6 +53,11 @@ async def test_get_consumption_info(aresponses, auth_success_response):
)
assert len(consumption_info["items"]) == 5

consumption_info = await api.water.get_consumption_info(
TEST_LOCATION_ID, start, end, device_mac_address=TEST_MAC_ADDRESS
)
assert len(consumption_info["items"]) == 5

# Test various cases of using invalid parameter values in set_mode_sleep:
with pytest.raises(RequestError):
await api.water.get_consumption_info(
Expand Down