1919
2020from homeassistant .components import ai_task , conversation
2121from homeassistant .components .cloud .ai_task import (
22- CloudLLMTaskEntity ,
22+ CloudAITaskEntity ,
2323 async_prepare_image_generation_attachments ,
24- async_setup_entry ,
2524)
26- from homeassistant .components .cloud .const import DATA_CLOUD
2725from homeassistant .core import HomeAssistant
28- from homeassistant .exceptions import ConfigEntryAuthFailed , HomeAssistantError
26+ from homeassistant .exceptions import HomeAssistantError
2927
3028from tests .common import MockConfigEntry
3129
3230
3331@pytest .fixture
34- def mock_cloud_ai_task_entity (hass : HomeAssistant ) -> CloudLLMTaskEntity :
35- """Return a CloudLLMTaskEntity with a mocked cloud LLM."""
32+ def mock_cloud_ai_task_entity (hass : HomeAssistant ) -> CloudAITaskEntity :
33+ """Return a CloudAITaskEntity with a mocked cloud LLM."""
3634 cloud = MagicMock ()
3735 cloud .llm = MagicMock (
3836 async_generate_image = AsyncMock (),
@@ -42,32 +40,17 @@ def mock_cloud_ai_task_entity(hass: HomeAssistant) -> CloudLLMTaskEntity:
4240 cloud .valid_subscription = True
4341 entry = MockConfigEntry (domain = "cloud" )
4442 entry .add_to_hass (hass )
45- entity = CloudLLMTaskEntity (cloud , entry )
43+ entity = CloudAITaskEntity (cloud , entry )
4644 entity .entity_id = "ai_task.cloud_ai_task"
4745 entity .hass = hass
4846 return entity
4947
5048
51- async def test_setup_entry_skips_when_not_logged_in (
52- hass : HomeAssistant ,
53- ) -> None :
54- """Test setup_entry exits early when not logged in."""
55- cloud = MagicMock ()
56- cloud .is_logged_in = False
57- entry = MockConfigEntry (domain = "cloud" )
58- entry .add_to_hass (hass )
59- hass .data [DATA_CLOUD ] = cloud
60-
61- async_add_entities = AsyncMock ()
62- await async_setup_entry (hass , entry , async_add_entities )
63- async_add_entities .assert_not_called ()
64-
65-
6649@pytest .fixture (name = "mock_handle_chat_log" )
6750def mock_handle_chat_log_fixture () -> AsyncMock :
6851 """Patch the chat log handler."""
6952 with patch (
70- "homeassistant.components.cloud.ai_task.CloudLLMTaskEntity ._async_handle_chat_log" ,
53+ "homeassistant.components.cloud.ai_task.CloudAITaskEntity ._async_handle_chat_log" ,
7154 AsyncMock (),
7255 ) as mock :
7356 yield mock
@@ -171,7 +154,7 @@ async def test_prepare_image_generation_attachments_processing_error(
171154
172155async def test_generate_data_returns_text (
173156 hass : HomeAssistant ,
174- mock_cloud_ai_task_entity : CloudLLMTaskEntity ,
157+ mock_cloud_ai_task_entity : CloudAITaskEntity ,
175158 mock_handle_chat_log : AsyncMock ,
176159) -> None :
177160 """Test generating plain text data."""
@@ -200,7 +183,7 @@ async def fake_handle(chat_type, log, task_name, structure):
200183
201184async def test_generate_data_returns_json (
202185 hass : HomeAssistant ,
203- mock_cloud_ai_task_entity : CloudLLMTaskEntity ,
186+ mock_cloud_ai_task_entity : CloudAITaskEntity ,
204187 mock_handle_chat_log : AsyncMock ,
205188) -> None :
206189 """Test generating structured data."""
@@ -228,7 +211,7 @@ async def fake_handle(chat_type, log, task_name, structure):
228211
229212async def test_generate_data_invalid_json (
230213 hass : HomeAssistant ,
231- mock_cloud_ai_task_entity : CloudLLMTaskEntity ,
214+ mock_cloud_ai_task_entity : CloudAITaskEntity ,
232215 mock_handle_chat_log : AsyncMock ,
233216) -> None :
234217 """Test invalid JSON responses raise an error."""
@@ -256,7 +239,7 @@ async def fake_handle(chat_type, log, task_name, structure):
256239
257240
258241async def test_generate_image_no_attachments (
259- hass : HomeAssistant , mock_cloud_ai_task_entity : CloudLLMTaskEntity
242+ hass : HomeAssistant , mock_cloud_ai_task_entity : CloudAITaskEntity
260243) -> None :
261244 """Test generating an image without attachments."""
262245 mock_cloud_ai_task_entity ._cloud .llm .async_generate_image .return_value = {
@@ -281,7 +264,7 @@ async def test_generate_image_no_attachments(
281264
282265async def test_generate_image_with_attachments (
283266 hass : HomeAssistant ,
284- mock_cloud_ai_task_entity : CloudLLMTaskEntity ,
267+ mock_cloud_ai_task_entity : CloudAITaskEntity ,
285268 mock_prepare_generation_attachments : AsyncMock ,
286269) -> None :
287270 """Test generating an edited image when attachments are provided."""
@@ -319,7 +302,7 @@ async def test_generate_image_with_attachments(
319302 [
320303 (
321304 LLMAuthenticationError ("auth" ),
322- ConfigEntryAuthFailed ,
305+ HomeAssistantError ,
323306 "Cloud LLM authentication failed" ,
324307 ),
325308 (
@@ -346,7 +329,7 @@ async def test_generate_image_with_attachments(
346329)
347330async def test_generate_image_error_handling (
348331 hass : HomeAssistant ,
349- mock_cloud_ai_task_entity : CloudLLMTaskEntity ,
332+ mock_cloud_ai_task_entity : CloudAITaskEntity ,
350333 err : Exception ,
351334 expected_exception : type [Exception ],
352335 message : str ,
0 commit comments