Skip to content

Commit

Permalink
Merge pull request #73 from dknowles2/async-user
Browse files Browse the repository at this point in the history
Implement the get_user() method in LegacyHydrawiseAync
  • Loading branch information
dknowles2 committed Sep 25, 2023
2 parents 87a73be + b520fa0 commit f4171f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pydrawise/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ async def get_user(self) -> User:
:rtype: User
"""
raise NotImplementedError
resp_json = await self._get("customerdetails.php")
return User(
id=0,
customer_id=resp_json["customer_id"],
name="",
email="",
controllers=[],
)

async def get_controllers(self) -> list[Controller]:
"""Retrieves all controllers associated with the currently authenticated user.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ def mock_request(customer_details, status_schedule):
class TestLegacyHydrawiseAsync:
"""Test the LegacyHydrawiseAsync class."""

async def test_get_user(self, customer_details: dict) -> None:
"""Test the get_user method."""
client = legacy.LegacyHydrawiseAsync(API_KEY)
with aioresponses() as m:
m.get(
re.compile("https://api.hydrawise.com/api/v1/customerdetails.php"),
status=200,
payload=customer_details,
)
user = await client.get_user()
m.assert_called_once_with(
"https://api.hydrawise.com/api/v1/customerdetails.php",
method="GET",
params={"api_key": API_KEY},
timeout=10,
)
assert user.customer_id == 47076

async def test_get_controllers(self, customer_details: dict) -> None:
"""Test the get_controllers method."""
client = legacy.LegacyHydrawiseAsync(API_KEY)
Expand Down

0 comments on commit f4171f9

Please sign in to comment.