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

Screen time values incorrect - timezone issue #3

Closed
manonstreet opened this issue Feb 24, 2024 · 7 comments
Closed

Screen time values incorrect - timezone issue #3

manonstreet opened this issue Feb 24, 2024 · 7 comments

Comments

@manonstreet
Copy link

As described in the home assistant integration issue the screen time values are not returning expected results and matched by the Family Safety app and other independent sources.

I think I've identified two problems:

  1. I am fairly certain that the the family API is using GMT, whereas I am in GMT-5. Therefore when this module returns the time used for today, it's actually counting from 7pm local time the day before.
  2. The time parameter being sent does not seem to be honored. In trying to correct for the first issue, I'm setting a start_time for for 5am. However the returned json for device_usage.get("json") always reflects a daily usage starting at midnight. Example:

pyfamilysafety.api DEBUG: Request to https://mobileaggregator.family.microsoft.com/api/v4/activityReport/appUsage/<redacted>?beginTime=2024-02-24T05:00:00Z&endTime=2024-02-24T23:59:59Z status code 200

2024-02-24 16:48:18 pyfamilysafety.account DEBUG: extra logging {"dailyDeviceUsage": [{"timeUsed": 11520000, "date": "2024-02-24T00:00:00", "deviceScreenTimeUsages": [{"deviceId": "<redacted>", "deviceName": "<redacted>", "platform": "Windows", "timeUsed": 11520000}]}], "deviceUsageAggregates": {"dailyAverage": 11520000.0, "totalScreenTime": 11520000, "otherDevicesCount": 0, "deviceAggregates": [{"deviceId": "<redacted>", "deviceName": "<redacted>", "platform": "Windows", "timeUsed": 11520000}]}, "connectedDevices": {"totalConnectedDevicesCount": 2, "otherConnectedDevicesCount": 0, "connectedDeviceAggregate": [{"deviceId": "g:<redacted>", "deviceName": "<redacted>", "platform": "Windows"}, {"deviceId": "g:<redacted>", "deviceName": "<redacted>", "platform": "Windows"}]}}

@pantherale0
Copy link
Owner

This is interesting, thanks for identifying that.

I think it would be much more likely the API is using UTC and perhaps doesn't account for timezones. Although I don't think a timezone is ever sent from the mobile app so I'm curious as to how that is handling timezones (maybe converting UTC to local before sending the request?)

I'm in the UK myself so its not something I can easily replicate / test with on my devices.

2nd issue should be easy to fix though I think.

@pantherale0
Copy link
Owner

Actually 2nd issue is intended otherwise if you were to issue a query for previous days, it would overwrite the current screentime.

@pantherale0
Copy link
Owner

Ok, I see the problem.

The mobile app does in fact send the timezone in the requests (ISO8601 format), however customised slightly in that the API does not accept the separator in the timezone section (00:00 is not accepted, 0000 is however).

@manonstreet
Copy link
Author

These two issues are related. If you convert to UTC before sending the request, that means you are reliant on the time component of the date time. This is what I tried to do manually by sending a request with 5am as the start_time (which is backing out the 5 hours from midnight). However from all of my testing, the time is ignored. I am not sure if the time is improperly formatted? In any case, as noted, the time returned seems to always account from midnight. As is, it's not possible to account for timezones.

pantherale0 added a commit that referenced this issue Feb 24, 2024
fix Screen time values incorrect - timezone issue #3
update application client ID pantherale0/ha-familysafety#35
@pantherale0
Copy link
Owner

module version 0.3.0 should fix this (plus auth issue). We're always going to be reliant on the timezones for this. But its not like we are rewriting the time directly (eg 00:00 to 23:00 for UTC-1), instead it will append the timezone to the end. At least I'm hoping thats all the mobile app does.

Will release a beta of the HA integration for testing.

@pantherale0
Copy link
Owner

Could you try latest beta please and let us know how you get on?

https://github.com/pantherale0/ha-familysafety/releases/tag/1.2.0

@manonstreet
Copy link
Author

manonstreet commented Feb 24, 2024

I just tested the module and it looks like it's now returning the correct screen time usage data!

I also tested the auth URL, and everything seems to be working. Thanks @pantherale0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants