Skip to content

Commit

Permalink
Remove image entity from dependencies #636
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Feb 17, 2024
1 parent ed2ebb7 commit c04fb85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import time
import uuid
from pathlib import Path
from typing import Union, cast
from typing import Union
from urllib.parse import urlencode, urljoin

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from aiohttp import web
from aiohttp.web_exceptions import HTTPUnauthorized, HTTPGone, HTTPNotFound
from homeassistant.components.camera import async_get_image as camera_get_image
from homeassistant.components.camera import async_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 @@ -176,15 +175,15 @@ async def ws_connect(hass: HomeAssistantType, params: dict) -> str:
return urljoin("ws" + server[4:], "api/ws") + "?" + urlencode(query)


def _get_image_from_entity_id(hass: HomeAssistantType, entity_id: str) -> ImageEntity:
def _get_image_from_entity_id(hass: HomeAssistantType, entity_id: str):
"""Get camera component from entity_id."""
if (component := hass.data.get("image")) is None:
raise Exception("Image integration not set up")

if (image := component.get_entity(entity_id)) is None:
raise Exception("Image not found")

return cast(ImageEntity, image)
return image


async def ws_poster(hass: HomeAssistantType, params: dict) -> web.Response:
Expand All @@ -196,7 +195,7 @@ async def ws_poster(hass: HomeAssistantType, params: dict) -> web.Response:

if poster.startswith("camera."):
# support entity_id as poster
image = await camera_get_image(hass, poster)
image = await async_get_image(hass, poster)
return web.Response(body=image.content, content_type=image.content_type)

if poster.startswith("image."):
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "WebRTC Camera",
"render_readme": true,
"homeassistant": "2023.7.0"
"homeassistant": "2022.5.0"
}
5 changes: 2 additions & 3 deletions tests/test_backward.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from homeassistant.components.image import ImageEntity
from homeassistant.components.media_player import MediaPlayerEntityFeature


def test_2022_5_0():
assert MediaPlayerEntityFeature


def test_2023_7_0():
assert ImageEntity
# def test_2023_7_0():
# assert ImageEntity

0 comments on commit c04fb85

Please sign in to comment.