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

Make fetching zones optional #75

Merged
merged 1 commit into from
Sep 25, 2023
Merged
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
3 changes: 2 additions & 1 deletion pydrawise/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class HydrawiseBase(ABC):
"""Base class for Hydrawise client APIs."""

@abstractmethod
async def get_user(self) -> User:
async def get_user(self, fetch_zones: bool = True) -> User:
"""Retrieves the currently authenticated user.

:param fetch_zones: When True, also fetch zones.
:rtype: User
"""

Expand Down
3 changes: 2 additions & 1 deletion pydrawise/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ async def _mutation(self, selector: DSLField) -> None:
# Assume bool response
raise MutationError

async def get_user(self) -> User:
async def get_user(self, fetch_zones: bool = True) -> User:
"""Retrieves the currently authenticated user.

:param fetch_zones: Not used in this implementation.
:rtype: User
"""
selector = self._schema.Query.me.select(*get_selectors(self._schema, User))
Expand Down
8 changes: 5 additions & 3 deletions pydrawise/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ async def _get(self, path: str, **kwargs) -> dict:
async with session.get(url, params=params, timeout=_TIMEOUT) as resp:
return await resp.json()

async def get_user(self) -> User:
async def get_user(self, fetch_zones: bool = True) -> User:
"""Retrieves the currently authenticated user.

:param fetch_zones: When True, also fetch zones.
:rtype: User
"""
resp_json = await self._get("customerdetails.php")
Expand All @@ -60,8 +61,9 @@ async def get_user(self) -> User:
email="",
controllers=[_controller_from_json(c) for c in resp_json["controllers"]],
)
for controller in user.controllers:
controller.zones = await self.get_zones(controller)
if fetch_zones:
for controller in user.controllers:
controller.zones = await self.get_zones(controller)
return user

async def get_controllers(self) -> list[Controller]:
Expand Down