Exemple #1
0
async def test_camera(hass):
    """Test that Axis camera platform is loaded properly."""
    await setup_axis_integration(hass)

    assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1

    cam = hass.states.get(f"camera.{NAME}")
    assert cam.state == "idle"
    assert cam.name == NAME

    camera_entity = camera._get_camera_from_entity_id(hass, f"camera.{NAME}")
    assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
    assert camera_entity.mjpeg_source == "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi"
    assert (await camera_entity.stream_source() ==
            "rtsp://*****:*****@1.2.3.4/axis-media/media.amp?videocodec=h264")
Exemple #2
0
async def test_camera_with_stream_profile(hass):
    """Test that Axis camera entity is using the correct path with stream profike."""
    with patch.dict(ENTRY_OPTIONS, {CONF_STREAM_PROFILE: "profile_1"}):
        await setup_axis_integration(hass)

    assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1

    cam = hass.states.get(f"camera.{NAME}")
    assert cam.state == "idle"
    assert cam.name == NAME

    camera_entity = camera._get_camera_from_entity_id(hass, f"camera.{NAME}")
    assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
    assert (
        camera_entity.mjpeg_source ==
        "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi?&streamprofile=profile_1")
    assert (
        await camera_entity.stream_source() ==
        "rtsp://*****:*****@1.2.3.4/axis-media/media.amp?videocodec=h264&streamprofile=profile_1"
    )
Exemple #3
0
    async def _async_request_stream(self, entity_id: str) -> Stream:
        camera_entity = _get_camera_from_entity_id(self.hass,
                                                   self.state.entity_id)

        try:
            # noinspection PyUnresolvedReferences
            stream = await camera_entity.async_create_stream()
        except AttributeError:  # < 2022.2
            # noinspection PyUnresolvedReferences
            stream = await camera_entity.create_stream()

        if not stream:
            raise SmartHomeError(
                ERR_NOT_SUPPORTED_IN_CURRENT_MODE,
                f'{entity_id} does not support play stream service')

        stream.add_provider(VIDEO_STREAM_FORMAT)
        stream.start()
        stream.endpoint_url(VIDEO_STREAM_FORMAT)

        return stream