From 9fcd25e9131dd961c80301f674d12625de478718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Tue, 6 Oct 2020 21:26:12 +0200 Subject: [PATCH 1/3] Add: Camera via ffmpeg mjpeg stream --- custom_components/tapo_control/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/tapo_control/manifest.json b/custom_components/tapo_control/manifest.json index d415b65..1b10c72 100644 --- a/custom_components/tapo_control/manifest.json +++ b/custom_components/tapo_control/manifest.json @@ -2,10 +2,10 @@ "domain": "tapo_control", "name": "Tapo: Cameras Control", "documentation": "https://github.com/JurajNyiri/HomeAssistant-Tapo-Control", - "dependencies": [], "issue_tracker": "https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/issues", "codeowners": ["@JurajNyiri"], "requirements": ["pytapo==0.11"], + "dependencies": ["ffmpeg"], "config_flow": true } \ No newline at end of file From 722978439e8cd0b561a1dcac70e4541eb6297979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Tue, 6 Oct 2020 21:26:29 +0200 Subject: [PATCH 2/3] Add: Camera via ffmpeg mjpeg stream --- custom_components/tapo_control/camera.py | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/custom_components/tapo_control/camera.py b/custom_components/tapo_control/camera.py index 40f98d0..b77c86b 100644 --- a/custom_components/tapo_control/camera.py +++ b/custom_components/tapo_control/camera.py @@ -7,8 +7,13 @@ from homeassistant.util import slugify from homeassistant.helpers import entity_platform from homeassistant.components.camera import SUPPORT_STREAM, Camera +from homeassistant.components.ffmpeg import DATA_FFMPEG +from homeassistant.helpers.aiohttp_client import ( + async_aiohttp_proxy_stream +) +from haffmpeg.camera import CameraMjpeg from .utils import getCamData -import logging +import logging _LOGGER = logging.getLogger(__name__) @@ -56,6 +61,7 @@ class TapoCamEntity(Camera): def __init__(self, hass: HomeAssistant, entry: dict, controller: Tapo, HDStream: boolean, camData): super().__init__() self._controller = controller + self._ffmpeg = hass.data[DATA_FFMPEG] self._entry = entry self._hdstream = HDStream self._host = entry.data.get(CONF_IP_ADDRESS) @@ -115,7 +121,25 @@ def model(self): def should_poll(self): return True - async def stream_source(self): + async def async_camera_image(self): + return None + + async def handle_async_mjpeg_stream(self, request): + streaming_url = self.getStreamSource() + stream = CameraMjpeg(self._ffmpeg.binary, loop=self.hass.loop) + await stream.open_camera(streaming_url) + try: + stream_reader = await stream.get_reader() + return await async_aiohttp_proxy_stream( + self.hass, + request, + stream_reader, + self._ffmpeg.ffmpeg_stream_content_type, + ) + finally: + await stream.close() + + def getStreamSource(self): if(self._hdstream): streamType = "stream1" else: From 6d2fbf8816aaafb64c21d1e12dff90ede52a2cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Tue, 6 Oct 2020 21:34:52 +0200 Subject: [PATCH 3/3] Add: Play stream service --- custom_components/tapo_control/camera.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/tapo_control/camera.py b/custom_components/tapo_control/camera.py index b77c86b..3538beb 100644 --- a/custom_components/tapo_control/camera.py +++ b/custom_components/tapo_control/camera.py @@ -151,6 +151,9 @@ async def async_update(self): camData = await getCamData(self.hass, self._controller) self.updateCam(camData) + async def stream_source(self): + return self.getStreamSource() + def updateCam(self, camData): self._state = "idle" self._motion_detection_enabled = camData['motion_detection_enabled']