From 830f319c85398e328cb6461d2e879ab85de4f8e6 Mon Sep 17 00:00:00 2001 From: Steve Herrell <47094394+twrecked@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:10:47 -0500 Subject: [PATCH] Fix camera recording issue. (#840) --- changelog | 2 ++ custom_components.json | 4 ++-- custom_components/aarlo/__init__.py | 2 +- custom_components/aarlo/camera.py | 23 +++++++++++++++++---- custom_components/aarlo/manifest.json | 2 +- custom_components/aarlo/pyaarlo/__init__.py | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/changelog b/changelog index 1e16d8bd..3b88fe89 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ aarlo/pyaarlo +0.7.4.1: + Fix camera recording issue. 0.7.4: Remove the beta because 0.8.1 alpha coming. 0.7.4b20: diff --git a/custom_components.json b/custom_components.json index 5881ecc4..3f3ea8ba 100644 --- a/custom_components.json +++ b/custom_components.json @@ -1,6 +1,6 @@ { "aarlo": { - "version": "0.7.4", + "version": "0.7.4.1", "local_location": "/custom_components/aarlo/__init__.py", "remote_location": "https://raw.githubusercontent.com/twrecked/hass-aarlo/master/custom_components/aarlo/__init__.py", "visit_repo": "https://github.com/twrecked/hass-aarlo", @@ -18,7 +18,7 @@ ] }, "pyaarlo": { - "version": "0.7.4", + "version": "0.7.4.1", "local_location": "/custom_components/aarlo/pyaarlo/__init__.py", "remote_location": "https://raw.githubusercontent.com/twrecked/hass-aarlo/master/custom_components/aarlo/pyaarlo/__init__.py", "visit_repo": "https://github.com/twrecked/hass-aarlo", diff --git a/custom_components/aarlo/__init__.py b/custom_components/aarlo/__init__.py index d3081892..905e7b54 100644 --- a/custom_components/aarlo/__init__.py +++ b/custom_components/aarlo/__init__.py @@ -33,7 +33,7 @@ SIREN_STATE_KEY ) -__version__ = "0.7.4" +__version__ = "0.7.4.1" _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/aarlo/camera.py b/custom_components/aarlo/camera.py index e9d8d2c0..8b1bd17a 100644 --- a/custom_components/aarlo/camera.py +++ b/custom_components/aarlo/camera.py @@ -6,6 +6,7 @@ """ from __future__ import annotations +import asyncio import base64 import logging @@ -380,6 +381,8 @@ def update_state(_device, attr, value): elif value == "unavailable": self._state = "Unavailable" self.clear_stream() + elif value == "startUserStream": + pass else: self._state = STATE_IDLE self.clear_stream() @@ -474,7 +477,9 @@ def clear_stream(self): if hasattr(self, "stream"): if self.stream: _LOGGER.debug("clearing out stream variable") - self.stream.stop() + asyncio.run_coroutine_threadsafe( + self.stream.stop(), self.hass.loop + ) self.stream = None @property @@ -641,7 +646,7 @@ def _attach_hidden_stream(self, duration): CONF_DURATION: duration, CONF_LOOKBACK: 0, } - self.hass.services.call(DOMAIN, SERVICE_RECORD, data, blocking=True) + self.hass.services.call(DOMAIN, SERVICE_RECORD, data, blocking=False) _LOGGER.debug("waiting on stream connect") return self._camera.wait_for_user_stream() @@ -703,12 +708,22 @@ async def async_siren_off(self): return await self.hass.async_add_executor_job(self.siren_off) def start_recording(self, duration=30): + """ Create a recording in the Arlo library. + + Has to do 3 things: + - start a stream on the camera + - attach a dummy local stream to tell Arlo to really start the stream + - send a "record-this-stream" request. + + We force the "arlo" user agent to get an rtsp stream. + """ source = self._camera.start_recording_stream(user_agent="arlo") if source: + _LOGGER.debug(f"stream-url={source}") active = self._attach_hidden_stream(duration + 10) if active: - # source = self._camera.start_recording_stream() - self._camera.start_recording(duration=duration) + _LOGGER.debug("attached, recording") + source = self._camera.start_recording(duration=duration) return source _LOGGER.warning("failed to start recording for {}".format(self._camera.name)) return None diff --git a/custom_components/aarlo/manifest.json b/custom_components/aarlo/manifest.json index 37d44694..5530dc9d 100644 --- a/custom_components/aarlo/manifest.json +++ b/custom_components/aarlo/manifest.json @@ -7,5 +7,5 @@ "iot_class": "cloud_push", "issue_tracker": "https://github.com/twrecked/hass-aarlo/issues", "requirements": ["unidecode","cloudscraper>=1.2.71", "paho-mqtt"], - "version": "0.7.4" + "version": "0.7.4.1" } diff --git a/custom_components/aarlo/pyaarlo/__init__.py b/custom_components/aarlo/pyaarlo/__init__.py index 363f966e..65a86ae6 100644 --- a/custom_components/aarlo/pyaarlo/__init__.py +++ b/custom_components/aarlo/pyaarlo/__init__.py @@ -45,7 +45,7 @@ _LOGGER = logging.getLogger("pyaarlo") -__version__ = "0.7.4" +__version__ = "0.7.4.1" class PyArlo(object):