cyberjunky / home-assistant-google_fit

:hearts: This component tracks your Google Fit activities.
MIT License
99 stars 20 forks source link

Sleep sensor: Session limit of 10000 exceeded. #3

Closed syphernl closed 3 years ago

syphernl commented 3 years ago

I noticed this in my logs:

2021-03-29 08:30:54 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.sleep fails
Traceback (most recent call last):
  File "/srv/hass/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 277, in async_update_ha_state
    await self.async_device_update()
  File "/srv/hass/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 473, in async_device_update
    raise exc
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/hass/lib/python3.8/site-packages/homeassistant/util/__init__.py", line 285, in wrapper
    result = method(*args, **kwargs)
  File "/srv/hass/lib/python3.8/site-packages/homeassistant/util/__init__.py", line 285, in wrapper
    result = method(*args, **kwargs)
  File "/home/hass/.homeassistant/custom_components/google_fit/sensor.py", line 626, in update
    sleep_dataset =  self._client.users().sessions().list(userId='me',fields='session',startTime=starttime,endTime=endtime).execute()
  File "/srv/hass/lib/python3.8/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/srv/hass/lib/python3.8/site-packages/googleapiclient/http.py", line 842, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://fitness.googleapis.com/fitness/v1/users/me/sessions?fields=session&startTime=2021-03-28T17%3A00%3A00Z&endTime=2021-03-29T11%3A00%3A00Z&alt=json returned "Session limit of 10000 exceeded.">
cyberjunky commented 3 years ago

@syphernl Hi thanks for reporting, I didn't know this older integration still worked. The integration polls every 10 minutes which is almost 30000 times per month. So if this is the real (maybe new) limit, we can only poll once every 31 minutes.

cyberjunky commented 3 years ago

We are not the only one: https://stackoverflow.com/questions/66805576/session-limit-of-10000-exceeded

poisondima commented 3 years ago

Hi I have same problem too :(

cyberjunky commented 3 years ago

@poisondima @syphernl you can try to change the 10 minutes to 30 in the code. On these two lines: https://github.com/cyberjunky/home-assistant-google_fit/blob/3c9f0cb57caec5883f60a94b73e6e436f74f2f8e/custom_components/google_fit/sensor.py#L31 https://github.com/cyberjunky/home-assistant-google_fit/blob/3c9f0cb57caec5883f60a94b73e6e436f74f2f8e/custom_components/google_fit/sensor.py#L32

poisondima commented 3 years ago

Thank you, I changed for 60 minutes, now I will wait for the end of the limit

syphernl commented 3 years ago

I've done the same (set it to 30 though). Not sure when the limit expires but we'll see.


FYI: In regards to sleep updates there seems to have been a few changes: https://developers.google.com/fit/improvements. I got an email about this earlier today that some oAuth scopes will be restricted soon:

Google Fit API (To be categorized as restricted in spring 2021)
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.blood_glucose.read
https://www.googleapis.com/auth/fitness.blood_pressure.read
https://www.googleapis.com/auth/fitness.body.read
https://www.googleapis.com/auth/fitness.body_temperature.read
https://www.googleapis.com/auth/fitness.heart_rate.read
https://www.googleapis.com/auth/fitness.location.read
https://www.googleapis.com/auth/fitness.nutrition.read
https://www.googleapis.com/auth/fitness.oxygen_saturation.read
https://www.googleapis.com/auth/fitness.reproductive_health.read
https://www.googleapis.com/auth/fitness.sleep.read

This sensor currently uses:

Except for the fitness.body.write (not sure why it needs that scope) all of them are listed to be categorized to be restricted. So things might break (further) in the near future 😢

cyberjunky commented 3 years ago

Thanks, I have added it to version 1.0.4, can you test it?

syphernl commented 3 years ago

Works fine for me!

poisondima commented 3 years ago

Works! thanks.