Skip to content

Commit

Permalink
Merge pull request #14 from JurajNyiri/camera_stream_debug
Browse files Browse the repository at this point in the history
Camera stream debug
  • Loading branch information
JurajNyiri authored Oct 6, 2020
2 parents e5bcb52 + 6d2fbf8 commit 08d4b38
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions custom_components/tapo_control/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -127,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']
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tapo_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 08d4b38

Please sign in to comment.