Skip to content

Commit

Permalink
Use better naming for the integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nickknissen committed Jul 12, 2023
1 parent 4e4b4d0 commit cf039bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions custom_components/monta/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(

self._get_token_lock = asyncio.Lock()

async def async_request_access_token(self) -> any:
async def async_request_token(self) -> any:
"""Obtain access token with clientId and secret."""

params = {"clientId": self._client_id, "clientSecret": self._client_secret}
Expand All @@ -83,6 +83,13 @@ async def async_request_access_token(self) -> any:
data=params,
)

return response_json

async def async_authenticate(self) -> str:
"""Obtain access token and store it in preferences."""

response_json = await self.async_request_token()

await self._async_update_preferences(
response_json["accessToken"],
dt_util.parse_datetime(response_json["accessTokenExpirationDate"]),
Expand Down Expand Up @@ -183,7 +190,7 @@ async def async_get_access_token(self) -> str:

return response_json["accessToken"]

return await self.async_request_access_token()
return await self.async_authenticate()

async def _api_wrapper(
self,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/monta/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def async_step_user(
_errors = {}
if user_input is not None:
try:
await self._test_credentials(
response = await self._test_credentials(
client_id=user_input[CONF_CLIENT_ID],
client_secret=user_input[CONF_CLIENT_SECRET],
)
Expand All @@ -45,7 +45,7 @@ async def async_step_user(
_errors["base"] = "unknown"
else:
return self.async_create_entry(
title=user_input[CONF_CLIENT_ID],
title=f"Monta account {response['userId']}",
data=user_input,
)

Expand All @@ -71,12 +71,12 @@ async def async_step_user(
errors=_errors,
)

async def _test_credentials(self, client_id: str, client_secret: str) -> None:
async def _test_credentials(self, client_id: str, client_secret: str) -> any:
"""Validate credentials."""
client = MontaApiClient(
client_id=client_id,
client_secret=client_secret,
session=async_create_clientsession(self.hass),
store=Store(self.hass, STORAGE_VERSION, STORAGE_KEY),
)
await client.async_request_access_token()
return await client.async_request_token()

0 comments on commit cf039bd

Please sign in to comment.