async def test_anna_climate_sensor_entities(hass, mock_smile_anna): """Test creation of climate related sensor entities as single master thermostat.""" mock_smile_anna.single_master_thermostat.side_effect = Mock(return_value=False) entry = await async_init_integration(hass, mock_smile_anna) assert entry.state == ConfigEntryState.LOADED state = hass.states.get("sensor.auxiliary_outdoor_temperature") assert float(state.state) == 18.0
async def test_no_still_image_url(hass, hass_client, mock_av_open): """Test that the component can grab images from stream with no still_image_url.""" with mock_av_open: assert await async_setup_component( hass, "camera", { "camera": { "name": "config_test", "platform": "generic", "stream_source": "rtsp://example.com:554/rtsp/", }, }, ) await hass.async_block_till_done() client = await hass_client() with patch( "homeassistant.components.generic.camera.GenericCamera.stream_source", return_value=None, ) as mock_stream_source: # First test when there is no stream_source should fail resp = await client.get("/api/camera_proxy/camera.config_test") await hass.async_block_till_done() mock_stream_source.assert_called_once() assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR with patch("homeassistant.components.camera.create_stream" ) as mock_create_stream: # Now test when creating the stream succeeds mock_stream = Mock() mock_stream.async_get_image = AsyncMock() mock_stream.async_get_image.return_value = b"stream_keyframe_image" mock_create_stream.return_value = mock_stream # should start the stream and get the image resp = await client.get("/api/camera_proxy/camera.config_test") await hass.async_block_till_done() mock_create_stream.assert_called_once() mock_stream.async_get_image.assert_called_once() assert resp.status == HTTPStatus.OK assert await resp.read() == b"stream_keyframe_image"
async def test_hmip_dump_hap_config_services(hass, mock_hap_with_service): """Test dump configuration services.""" with patch("pathlib.Path.write_text", return_value=Mock()) as write_mock: await hass.services.async_call("homematicip_cloud", "dump_hap_config", {"anonymize": True}, blocking=True) home = mock_hap_with_service.home assert home.mock_calls[-1][0] == "download_configuration" assert len(home.mock_calls) == 8 # pylint: disable=W0212 assert len(write_mock.mock_calls) > 0
async def test_frame_interval_property(hass): """Test that the frame interval is calculated and returned correctly.""" await async_setup_component( hass, "camera", { "camera": { "name": "config_test", "platform": "generic", "stream_source": "rtsp://example.com:554/rtsp/", "framerate": 5, }, }, ) await hass.async_block_till_done() request = Mock() with patch("homeassistant.components.camera.async_get_still_stream" ) as mock_get_stream: await async_get_mjpeg_stream(hass, request, "camera.config_test") assert mock_get_stream.call_args_list[0][0][3] == pytest.approx(0.2)