BaQs / pyEzviz

Python package for ezviz cameras
Apache License 2.0
103 stars 45 forks source link

disable/decouple detection_sensibility api from the main status function #106

Closed kekkokk closed 1 year ago

kekkokk commented 1 year ago

Hi everyone, I was having problem in HA of cameras not responding anymore when setting them in sleep mode.

I found this related issues: https://github.com/home-assistant/core/issues/85238 https://github.com/RenierM26/ha-ezviz/issues/90 https://github.com/RenierM26/ha-ezviz/issues/30 https://github.com/RenierM26/ha-ezviz/issues/8

So I tried debugging directly into pyEzviz and I saw that the timeout problem is always caused by the API POST call for the detection_sensibility.

I thought that when making a request, the Ezviz server would send me a cached information about my device's status but it seems that it is not the case with detection_sensibility (more specifically with /v3/alarms/v2/advanced API).

If the privacy is enabled on the camera the request would almost certainly timeout and an "Unknown" value is returned by the library. I also noticed that when I disabled the privacy mode on all cameras and did subsequent requests, sometimes it timed out on the camera that is more "network problematic" in my house.

Skipping the self._detection_sensibility() in the status() function, made the integration blazing fast.

TL;DR I might be completely wrong but it seems that when requesting the detection_sensibility, the request is forwarded directly to the device itself, instead, all the other information comes directly from ezviz cloud. And if the device is in sleep or privacy mode, the request will probably timeout. Also if the network of the device is poor.

Wouldn't it make sense to decouple the status() in a status() function and add a specific detection() function that might be called by HA integration @RenierM26 less frequently or maybe add an option to disable it since it's causing problems?

I mean, I can live without knowing the exact sensibility I set in the app, but when I leave my house I currently can't rely on the fact that the cameras would exit from the sleep mode and enable the alarm because the integration is completely unresponsive.

With 2 cameras on sleep mode I went from 45 seconds to under 1 second disabling these POSTs

itsmartinho commented 1 year ago

Same issue for me.

RenierM26 commented 1 year ago

Hi @kekkokk,

Thank you for listing all the issues. I have decoupled detection sensitivity from the main function in both the api and ha-ezviz.

There is also a open pull request on home assistant core

https://github.com/home-assistant/core/pull/93995