Rename stream_type to frontend_stream_type (#57923)

Camera devices may support multiple stream sources so we want to clarify that
this is meant to decide which stream source is used in the frontend only.

Will set stream_type temporarily to allow rollout without breaking nightly,
and this will be removed after frontend is updated.
This commit is contained in:
Allen Porter 2021-10-17 20:16:29 -07:00 committed by GitHub
parent a1176cc79a
commit dafea00f41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -422,7 +422,7 @@ class Camera(Entity):
return MIN_STREAM_INTERVAL
@property
def stream_type(self) -> str | None:
def frontend_stream_type(self) -> str | None:
"""Return the type of stream supported by this camera.
A camera may have a single stream type which is used to inform the
@ -570,8 +570,10 @@ class Camera(Entity):
if self.motion_detection_enabled:
attrs["motion_detection"] = self.motion_detection_enabled
if self.stream_type:
attrs["stream_type"] = self.stream_type
if self.frontend_stream_type:
attrs["frontend_stream_type"] = self.frontend_stream_type
# Remove after home-assistant/frontend#10298 is merged into nightly
attrs["stream_type"] = self.frontend_stream_type
return attrs
@ -746,11 +748,11 @@ async def ws_camera_web_rtc_offer(
entity_id = msg["entity_id"]
offer = msg["offer"]
camera = _get_camera_from_entity_id(hass, entity_id)
if camera.stream_type != STREAM_TYPE_WEB_RTC:
if camera.frontend_stream_type != STREAM_TYPE_WEB_RTC:
connection.send_error(
msg["id"],
"web_rtc_offer_failed",
f"Camera does not support WebRTC, stream_type={camera.stream_type}",
f"Camera does not support WebRTC, frontend_stream_type={camera.frontend_stream_type}",
)
return
try:

View File

@ -118,7 +118,7 @@ class NestCamera(Camera):
return supported_features
@property
def stream_type(self) -> str | None:
def frontend_stream_type(self) -> str | None:
"""Return the type of stream supported by this camera."""
if CameraLiveStreamTrait.NAME not in self._device.traits:
return None
@ -131,9 +131,11 @@ class NestCamera(Camera):
"""Return the source of the stream."""
if not self.supported_features & SUPPORT_STREAM:
return None
if self.stream_type != STREAM_TYPE_HLS:
if CameraLiveStreamTrait.NAME not in self._device.traits:
return None
trait = self._device.traits[CameraLiveStreamTrait.NAME]
if StreamingProtocol.RTSP not in trait.supported_protocols:
return None
if not self._stream:
_LOGGER.debug("Fetching stream url")
try:

View File

@ -53,7 +53,7 @@ async def mock_camera_web_rtc_fixture(hass):
await hass.async_block_till_done()
with patch(
"homeassistant.components.camera.Camera.stream_type",
"homeassistant.components.camera.Camera.frontend_stream_type",
new_callable=PropertyMock(return_value=STREAM_TYPE_WEB_RTC),
), patch(
"homeassistant.components.camera.Camera.async_handle_web_rtc_offer",