telenet_telemeter icon indicating copy to clipboard operation
telenet_telemeter copied to clipboard

Rate Limit requests from Telenet

Open Spiffo opened this issue 3 months ago • 2 comments

Can you add a rate limiter? Requesting usage from Telenet once every 15 mins should be enough, right?

I'm on 2.0.4

This error originated from a custom integration.

Logger: custom_components.telenet_telemeter.utils
Source: custom_components/telenet_telemeter/utils.py:88
integration: Telenet Telemeter (documentation, issues)
First occurred: 10:38:25 (948 occurrences)
Last logged: 18:04:31

[mobileBundleUsage bundle]: Failed to call [HttpMethod.GET](https://api.prd.telenet.be/ocapi/public/api/mobile-service/v3/mobilesubscriptions/xxxxxxxxx/usages?type=bundle). Statuscode was 429. Exception was AssertionError()
[mobileBundleUsage lineIdentifier]: Failed to call [HttpMethod.GET](https://api.prd.telenet.be/ocapi/public/api/mobile-service/v3/mobilesubscriptions/xxxxxxxxx/usages?type=bundle&lineIdentifier=aaaaaaaaaa). Statuscode was 429. Exception was AssertionError()
[mobileBundleUsage lineIdentifier]: Failed to call [HttpMethod.GET](https://api.prd.telenet.be/ocapi/public/api/mobile-service/v3/mobilesubscriptions/xxxxxxxxx/usages?type=bundle&lineIdentifier=bbbbbbbbbb). Statuscode was 429. Exception was AssertionError()
[mobileBundleUsage lineIdentifier]: Failed to call [HttpMethod.GET](https://api.prd.telenet.be/ocapi/public/api/mobile-service/v3/mobilesubscriptions/xxxxxxxxx/usages?type=bundle&lineIdentifier=cccccccccc). Statuscode was 429. Exception was AssertionError()
[mobileBundleUsage lineIdentifier]: Failed to call [HttpMethod.GET](https://api.prd.telenet.be/ocapi/public/api/mobile-service/v3/mobilesubscriptions/xxxxxxxxx/usages?type=bundle&lineIdentifier=dddddddddd). Statuscode was 429. Exception was AssertionError()

Spiffo avatar Oct 08 '25 16:10 Spiffo

This chunk of error logging is also flooding my log...

ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.telenet_mobile_1234657980 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/requests/models.py", line 976, in json
    return complexjson.loads(self.text, **kwargs)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/local/lib/python3.13/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ~~~~~~~~~~~~~~~^^^
  File "/usr/local/lib/python3.13/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/simplejson/scanner.py", line 79, in scan_once
    return _scan_once(string, idx)
  File "/usr/local/lib/python3.13/site-packages/simplejson/scanner.py", line 70, in _scan_once
    raise JSONDecodeError(errmsg, string, idx)
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 963, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1314, in async_device_update
    await self.async_update()
  File "/config/custom_components/telenet_telemeter/sensor.py", line 1260, in async_update
    mobileusage = await self._hass.async_add_executor_job(lambda: self._data._session.mobileBundleUsage(self._productSubscription.get('bundleIdentifier'),self._identifier))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/telenet_telemeter/sensor.py", line 1260, in <lambda>
    mobileusage = await self._hass.async_add_executor_job(lambda: self._data._session.mobileBundleUsage(self._productSubscription.get('bundleIdentifier'),self._identifier))
                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/telenet_telemeter/utils.py", line 277, in mobileBundleUsage
    return response.json()
           ~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/requests/models.py", line 980, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Spiffo avatar Oct 13 '25 14:10 Spiffo

strange, as there is already a rate limitation integrated: MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=240)

I should convert the full integration to use a DataUpdateCoordinator class, but I can't promis yet when I'll have time fort this.

myTselection avatar Oct 20 '25 19:10 myTselection