Skip to content

Commit

Permalink
Code refactoring after #619
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 5, 2024
1 parent 2907c8d commit 202a53a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import voluptuous as vol
from aiohttp import web
from aiohttp.web_exceptions import HTTPUnauthorized, HTTPGone, HTTPNotFound
from homeassistant.components.image import ImageEntity
from homeassistant.components.camera import async_get_image as camera_get_image
from homeassistant.components.image import _async_get_image as image_get_image
from homeassistant.components.hassio.ingress import _websocket_forward
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.image import ImageEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
Expand Down Expand Up @@ -175,7 +174,8 @@ async def ws_connect(hass: HomeAssistantType, params: dict) -> str:
raise Exception("Missing url or entity")

return urljoin("ws" + server[4:], "api/ws") + "?" + urlencode(query)



def _get_image_from_entity_id(hass: HomeAssistantType, entity_id: str) -> ImageEntity:
"""Get camera component from entity_id."""
if (component := hass.data.get("image")) is None:
Expand All @@ -198,10 +198,10 @@ async def ws_poster(hass: HomeAssistantType, params: dict) -> web.Response:
# support entity_id as poster
image = await camera_get_image(hass, poster)
return web.Response(body=image.content, content_type=image.content_type)

if poster.startswith("image."):
# support entity_id as poster
image_entity = _get_image_from_entity_id(hass, poster)
image_entity = _get_image_from_entity_id(hass, poster)
image = await image_entity.async_image()
_LOGGER.debug(f"webrtc image_entity: {image_entity} - {len(image)}")
return web.Response(body=image, content_type="image/jpeg")
Expand Down

0 comments on commit 202a53a

Please sign in to comment.