alexmohr / sonyapilib

Contains a python api to control sony devices.
MIT License
20 stars 11 forks source link

Rate limiting for warnings #59

Open alexmohr opened 4 years ago

alexmohr commented 4 years ago

In the meantime I've tested this PR with Home Assistant, and it works (hooray!), but I noticed that the library is quite noisy if the device is turned off during startup:

2020-09-20 23:58:44 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=52323): Max retries exceeded with url: /dmr.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb23f92a90>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:47 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=50001): Max retries exceeded with url: /Ircc.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb22e791d0>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:47 ERROR (SyncWorker_35) [sonyapilib.device] failed to get device information: HTTPConnectionPool(host='bdp-s370', port=50001): Max retries exceeded with url: /Ircc.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb22e791d0>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:50 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=50202): Max retries exceeded with url: /appslist (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb2254bb50>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:51 WARNING (MainThread) [homeassistant.helpers.entity] Update of media_player.sony_bdp_s370 is taking over 10 seconds
2020-09-20 23:58:51 WARNING (MainThread) [homeassistant.components.media_player] Updating sony media_player took longer than the scheduled update interval 0:00:10

These lines keep repeating every few seconds, so they really fill up the logs. I think the errors should be degraded to warnings, but maybe some kind of rate limiting could be applied, too. I don't think they are caused by my patch or the type of device (are newer devices always-on?), but who knows...

Originally posted by @mtdcr in https://github.com/alexmohr/sonyapilib/pull/58#issuecomment-695842872