Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
fix Screen time values incorrect - timezone issue #3
update application client ID pantherale0/ha-familysafety#35
  • Loading branch information
pantherale0 committed Feb 24, 2024
1 parent 30371db commit 40340f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
16 changes: 9 additions & 7 deletions pyfamilysafety/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"""Family safety account handler."""

import logging
from datetime import datetime, date, time, timedelta
from datetime import datetime, date, time
from urllib.parse import quote_plus

from .api import FamilySafetyAPI
from .device import Device
from .application import Application
from .enum import OverrideTarget, OverrideType
from .helpers import localise_datetime, API_TIMEZONE

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -92,19 +94,19 @@ async def get_screentime_usage(self,
default = False
if start_time is None:
default = True
start_time = datetime.combine(date.today(), time(0,0,0))
start_time = localise_datetime(datetime.combine(date.today(), time(0,0,0), tzinfo=API_TIMEZONE))
if end_time is None:
default = True
end_time = datetime.combine(date.today(), time(23,59,59))
end_time = localise_datetime(datetime.combine(date.today(), time(23,59,59), tzinfo=API_TIMEZONE))

device_usage = await self._api.send_request(
endpoint="get_user_device_screentime_usage",
headers={
"Plat-Info": platform
},
USER_ID=self.user_id,
BEGIN_TIME=start_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
END_TIME=end_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
BEGIN_TIME=quote_plus(start_time.strftime('%Y-%m-%dT%H:%M:%S%z')),
END_TIME=quote_plus(end_time.strftime('%Y-%m-%dT%H:%M:%S%z')),
DEVICE_COUNT=device_count
)

Expand All @@ -114,8 +116,8 @@ async def get_screentime_usage(self,
"Plat-Info": platform
},
USER_ID=self.user_id,
BEGIN_TIME=start_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
END_TIME=end_time.strftime("%Y-%m-%dT%H:%M:%SZ")
BEGIN_TIME=quote_plus(start_time.strftime('%Y-%m-%dT%H:%M:%S%z')),
END_TIME=quote_plus(end_time.strftime('%Y-%m-%dT%H:%M:%S%z'))
)

if default:
Expand Down
2 changes: 1 addition & 1 deletion pyfamilysafety/authenticator/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=line-too-long
"""Authenticator constants"""

CLIENT_ID = "dce5010f-c52d-4353-ae86-d666373528d8"
CLIENT_ID = "000000000004893A"
SCOPE = "service::familymobile.microsoft.com::MBI_SSL"

BASE_URL = "https://login.live.com/"
Expand Down
15 changes: 15 additions & 0 deletions pyfamilysafety/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Helper functions for pyfamilysafety."""

from datetime import datetime
from dateutil import tz

API_TIMEZONE = tz.tzutc()
LOCAL_TIMEZONE = tz.tzlocal()

def localise_datetime(dt: datetime) -> datetime:
"""Localise the datetime into the current timezone."""
return dt.replace(tzinfo=LOCAL_TIMEZONE)

def standardise_datetime(dt: datetime) -> datetime:
"""Standardise the datetime into UTC."""
return dt.replace(tzinfo=API_TIMEZONE)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

setup(name="pyfamilysafety",
version="0.2.1",
version="0.3.0",
description="Microsoft Family Safety API library",
url="https://github.com/pantherale0/pyfamilysafety",
author="pantherale0",
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def main():
login = True
while login:
try:
auth = await FamilySafety.create(token=input("Response URL: "), use_refresh_token=True)
auth = await FamilySafety.create(token=input("Response URL: "), use_refresh_token=False)
_LOGGER.info("Logged in, ready.")
_LOGGER.debug("Access token is: %s", auth.api.authenticator.refresh_token)
login = False
Expand Down

0 comments on commit 40340f9

Please sign in to comment.