Skip to content

Commit

Permalink
Update api_renpho.py
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Nov 8, 2023
1 parent 9cc180a commit 4e68a25
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions custom_components/renpho/api_renpho.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def get_user_id(self):
return self.user_id

@staticmethod
def get_timestamp(days=60) -> int:
ago = datetime.date.today() - datetime.timedelta(days=days)
return int(time.mktime(ago.timetuple()))
def get_ago_timestamp() -> int:
start_date = datetime.date(1998, 1, 1)
return int(time.mktime(start_date.timetuple()))

def prepare_data(self, data):
if isinstance(data, bytes):
Expand Down Expand Up @@ -223,8 +223,7 @@ async def get_measurements(self) -> Optional[List[Dict]]:
Exception: For any other unexpected errors.
"""
try:
today = datetime.date.today()
ago_timestamp = self.get_ago_timestamp(60)
ago_timestamp = int(time.mktime(datetime.date(1998, 1, 1).timetuple()))
url = f"{API_MEASUREMENTS_URL}?user_id={self.user_id}&last_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
parsed = await self._request("GET", url)

Expand Down Expand Up @@ -378,7 +377,7 @@ async def get_device_info(self):
Returns:
dict: The API response as a dictionary.
"""
ago_timestamp = self.get_ago_timestamp(60)
week_ago_timestamp = self.get_ago_timestamp()
url = f"{DEVICE_INFO_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
Expand All @@ -393,8 +392,8 @@ async def list_latest_model(self):
Returns:
dict: The API response as a dictionary.
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{LATEST_MODEL_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{LATEST_MODEL_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand All @@ -408,8 +407,8 @@ async def list_girth(self) -> Optional[dict]:
Returns:
Optional[dict]: The API response as a dictionary, or None if the request fails.
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{GIRTH_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{GIRTH_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand Down Expand Up @@ -450,8 +449,8 @@ async def list_girth_goal(self):
Returns:
dict: The API response as a dictionary.
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{GIRTH_GOAL_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{GIRTH_GOAL_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand Down Expand Up @@ -502,8 +501,8 @@ async def list_growth_record(self):
Returns:
dict: The API response as a dictionary.
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{GROWTH_RECORD_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{GROWTH_RECORD_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand Down Expand Up @@ -544,8 +543,8 @@ async def message_list(self):
"""
Asynchronously list messages.
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{MESSAGE_LIST_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{MESSAGE_LIST_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand All @@ -557,8 +556,8 @@ async def request_user(self):
"""
Asynchronously request user
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{USER_REQUEST_URL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{USER_REQUEST_URL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand All @@ -570,8 +569,8 @@ async def reach_goal(self):
"""
Asynchronously reach_goal
"""
ago_timestamp = self.get_ago_timestamp(60)
url = f"{USERS_REACH_GOAL}?user_id={self.user_id}&last_updated_at={ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
week_ago_timestamp = self.get_ago_timestamp()
url = f"{USERS_REACH_GOAL}?user_id={self.user_id}&last_updated_at={week_ago_timestamp}&locale=en&app_id=Renpho&terminal_user_session_key={self.session_key}"
try:
return await self._request("GET", url)
except Exception as e:
Expand Down

0 comments on commit 4e68a25

Please sign in to comment.