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
Add event_stream() which returns stream of camera events #146
Conversation
@tchellomello @dougsland @NickWaterton I'd appreciate your comments/suggestions/feedback, even though I still have some work to do before I consider it finished. Thx! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just two questions.
Regarding the urllib3 warning, I found this old issue that has not been resolved: urllib3/urllib3#800 I also found a suggested work around here: home-assistant/core#17042 I will add a similar Filter here so users don't have to worry about it. |
I did some experimenting by powering off the camera while in a call to (I did consider setting a read timeout anyway, e.g., 60 seconds. Then, when the timeout occurs, the generator would end, and another instance of the generator could be started. This might be one way to handle the camera going away. Unfortunately that would mean events could be missed. So, that's not really a practical solution.) I did some research and discovered a TCP connection will (by default) stay established forever, even if there is no data sent in either direction. Therefore there's no way, in that scenario, to tell if the server (i.e., camera) is alive and healthy. The solution that I found suggested is to set class SOHTTPAdapter(requests.adapters.HTTPAdapter):
def __init__(self, *args, **kwargs):
self.socket_options = kwargs.pop("socket_options", None)
super().__init__(*args, **kwargs)
def init_poolmanager(self, *args, **kwargs):
if self.socket_options is not None:
kwargs["socket_options"] = self.socket_options
super().init_poolmanager(*args, **kwargs)
so_adapter = SOHTTPAdapter(socket_options=(
HTTPConnection.default_socket_options +
[
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 10),
(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 5),
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4),
]
)) Then, instead of using I'll play with this some more to make sure it handles all the scenarios I can think of, then I'll commit another change that uses this technique. |
Increase default timeout to 6.05 sec.
88fb959
to
5502368
Compare
Got some feedback in this community forum topic. |
I modified Home Assistant's amcrest integration to use this new |
Patch looks good to me, the workaround from request library also looks good. |
Fell free to merge after testing. |
Thanks! BTW, I've been testing since before I created the PR. 🤣 |
Description
Currently, determining if motion or other events occur requires polling via
event_channels_happened()
(or one of the other methods or properties that use it.) This can delay response to events, and can even miss events if the event duration is shorter than the polling period.This adds a new method --
event_stream()
-- which will return events as they happen. It is a generator and will normally not return, so it should be run in a separate thread or process.Example use case
To do
Thanks to @NickWaterton and his groundwork in PR #140!