Skip to content

Commit

Permalink
revert 9739d1f
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Oct 10, 2024
1 parent 9739d1f commit 8aba586
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions custom_components/medisafe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,31 @@ def __init__(
self._username = username
self._password = password
self._session = session
self._auth = None

async def async_get_data(self) -> dict:
if self._auth is None:
auth = await self.api_wrapper(
"post",
"https://web.medisafe.com/api/auth",
{"username": self._username, "password": self._password},
)
if "error" in auth:
if "message" in auth["error"]:
_LOGGER.error(f"Authentication failed: {auth['error']['message']}")
raise ConfigEntryAuthFailed(auth["error"]["message"])
else:
_LOGGER.error(f"Authentication failed: {auth['error']}")
raise ConfigEntryAuthFailed(auth["error"])

if "token" not in auth:
_LOGGER.error("No token recieved")
raise ConfigEntryAuthFailed("Authentication Failed")
auth = await self.api_wrapper(
"post",
"https://web.medisafe.com/api/auth",
{"username": self._username, "password": self._password},
)
if "error" in auth:
if "message" in auth["error"]:
_LOGGER.error(f"Authentication failed: {auth['error']['message']}")
raise ConfigEntryAuthFailed(auth["error"]["message"])
else:
_LOGGER.error(f"Authentication failed: {auth['error']}")
raise ConfigEntryAuthFailed(auth["error"])

self._auth = auth
if "token" not in auth:
_LOGGER.error(f"No token recieved")
raise ConfigEntryAuthFailed("Authentication Failed")

start = int((datetime.today() - timedelta(days=1)).timestamp() * 1000)
end = int((datetime.today() + timedelta(days=1)).timestamp() * 1000)
return await self.api_wrapper(
"get",
f"https://web.medisafe.com/api/sync/{start}/{end}?id={self._auth['id']}",
headers={"Authorization": "Bearer " + self._auth["token"]},
f"https://web.medisafe.com/api/sync/{start}/{end}?id={auth['id']}",
headers={"Authorization": "Bearer " + auth["token"]},
)

async def api_wrapper(
Expand Down

0 comments on commit 8aba586

Please sign in to comment.