88from aiohasupervisor .models import StoreAddonUpdate
99import pytest
1010
11- from homeassistant .components .hassio import DOMAIN , HassioAPIError
11+ from homeassistant .components .hassio import DOMAIN
1212from homeassistant .components .hassio .const import REQUEST_REFRESH_DELAY
1313from homeassistant .core import HomeAssistant
1414from homeassistant .exceptions import HomeAssistantError
@@ -239,9 +239,7 @@ async def test_update_addon(hass: HomeAssistant, update_addon: AsyncMock) -> Non
239239 update_addon .assert_called_once_with ("test" , StoreAddonUpdate (backup = False ))
240240
241241
242- async def test_update_os (
243- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
244- ) -> None :
242+ async def test_update_os (hass : HomeAssistant , supervisor_client : AsyncMock ) -> None :
245243 """Test updating OS update entity."""
246244 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
247245 config_entry .add_to_hass (hass )
@@ -255,22 +253,17 @@ async def test_update_os(
255253 assert result
256254 await hass .async_block_till_done ()
257255
258- aioclient_mock .post (
259- "http://127.0.0.1/os/update" ,
260- json = {"result" : "ok" , "data" : {}},
261- )
262-
256+ supervisor_client .os .update .return_value = None
263257 await hass .services .async_call (
264258 "update" ,
265259 "install" ,
266260 {"entity_id" : "update.home_assistant_operating_system_update" },
267261 blocking = True ,
268262 )
263+ supervisor_client .os .update .assert_called_once ()
269264
270265
271- async def test_update_core (
272- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
273- ) -> None :
266+ async def test_update_core (hass : HomeAssistant , supervisor_client : AsyncMock ) -> None :
274267 """Test updating core update entity."""
275268 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
276269 config_entry .add_to_hass (hass )
@@ -284,21 +277,18 @@ async def test_update_core(
284277 assert result
285278 await hass .async_block_till_done ()
286279
287- aioclient_mock .post (
288- "http://127.0.0.1/core/update" ,
289- json = {"result" : "ok" , "data" : {}},
290- )
291-
280+ supervisor_client .homeassistant .update .return_value = None
292281 await hass .services .async_call (
293282 "update" ,
294283 "install" ,
295- {"entity_id" : "update.home_assistant_os_update " },
284+ {"entity_id" : "update.home_assistant_core_update " },
296285 blocking = True ,
297286 )
287+ supervisor_client .homeassistant .update .assert_called_once ()
298288
299289
300290async def test_update_supervisor (
301- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
291+ hass : HomeAssistant , supervisor_client : AsyncMock
302292) -> None :
303293 """Test updating supervisor update entity."""
304294 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
@@ -313,17 +303,14 @@ async def test_update_supervisor(
313303 assert result
314304 await hass .async_block_till_done ()
315305
316- aioclient_mock .post (
317- "http://127.0.0.1/supervisor/update" ,
318- json = {"result" : "ok" , "data" : {}},
319- )
320-
306+ supervisor_client .supervisor .update .return_value = None
321307 await hass .services .async_call (
322308 "update" ,
323309 "install" ,
324310 {"entity_id" : "update.home_assistant_supervisor_update" },
325311 blocking = True ,
326312 )
313+ supervisor_client .supervisor .update .assert_called_once ()
327314
328315
329316async def test_update_addon_with_error (
@@ -353,7 +340,7 @@ async def test_update_addon_with_error(
353340
354341
355342async def test_update_os_with_error (
356- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
343+ hass : HomeAssistant , supervisor_client : AsyncMock
357344) -> None :
358345 """Test updating OS update entity with error."""
359346 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
@@ -367,11 +354,7 @@ async def test_update_os_with_error(
367354 )
368355 await hass .async_block_till_done ()
369356
370- aioclient_mock .post (
371- "http://127.0.0.1/os/update" ,
372- exc = HassioAPIError ,
373- )
374-
357+ supervisor_client .os .update .side_effect = SupervisorError
375358 with pytest .raises (
376359 HomeAssistantError , match = r"^Error updating Home Assistant Operating System:"
377360 ):
@@ -384,7 +367,7 @@ async def test_update_os_with_error(
384367
385368
386369async def test_update_supervisor_with_error (
387- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
370+ hass : HomeAssistant , supervisor_client : AsyncMock
388371) -> None :
389372 """Test updating supervisor update entity with error."""
390373 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
@@ -398,11 +381,7 @@ async def test_update_supervisor_with_error(
398381 )
399382 await hass .async_block_till_done ()
400383
401- aioclient_mock .post (
402- "http://127.0.0.1/supervisor/update" ,
403- exc = HassioAPIError ,
404- )
405-
384+ supervisor_client .supervisor .update .side_effect = SupervisorError
406385 with pytest .raises (
407386 HomeAssistantError , match = r"^Error updating Home Assistant Supervisor:"
408387 ):
@@ -415,7 +394,7 @@ async def test_update_supervisor_with_error(
415394
416395
417396async def test_update_core_with_error (
418- hass : HomeAssistant , aioclient_mock : AiohttpClientMocker
397+ hass : HomeAssistant , supervisor_client : AsyncMock
419398) -> None :
420399 """Test updating core update entity with error."""
421400 config_entry = MockConfigEntry (domain = DOMAIN , data = {}, unique_id = DOMAIN )
@@ -429,11 +408,7 @@ async def test_update_core_with_error(
429408 )
430409 await hass .async_block_till_done ()
431410
432- aioclient_mock .post (
433- "http://127.0.0.1/core/update" ,
434- exc = HassioAPIError ,
435- )
436-
411+ supervisor_client .homeassistant .update .side_effect = SupervisorError
437412 with pytest .raises (
438413 HomeAssistantError , match = r"^Error updating Home Assistant Core:"
439414 ):
0 commit comments