@@ -53,7 +53,20 @@ def device_fixture(main_zone):
5353 yield device
5454
5555
56- async def test_setup_host (hass : HomeAssistant , device , main_zone ) -> None :
56+ @pytest .fixture (name = "device2" )
57+ def device2_fixture (main_zone ):
58+ """Mock the yamaha device."""
59+ device = FakeYamahaDevice (
60+ "http://127.0.0.1:80/YamahaRemoteControl/ctrl" , "Receiver 2" , zones = [main_zone ]
61+ )
62+ with (
63+ patch ("rxv.RXV" , return_value = device ),
64+ patch ("rxv.find" , return_value = [device ]),
65+ ):
66+ yield device
67+
68+
69+ async def test_setup_host (hass : HomeAssistant , device , device2 , main_zone ) -> None :
5770 """Test set up integration with host."""
5871 assert await async_setup_component (hass , MP_DOMAIN , CONFIG )
5972 await hass .async_block_till_done ()
@@ -63,6 +76,28 @@ async def test_setup_host(hass: HomeAssistant, device, main_zone) -> None:
6376 assert state is not None
6477 assert state .state == "off"
6578
79+ with patch ("rxv.find" , return_value = [device2 ]):
80+ assert await async_setup_component (hass , MP_DOMAIN , CONFIG )
81+ await hass .async_block_till_done ()
82+
83+ state = hass .states .get ("media_player.yamaha_receiver_main_zone" )
84+
85+ assert state is not None
86+ assert state .state == "off"
87+
88+
89+ async def test_setup_attribute_error (hass : HomeAssistant , device , main_zone ) -> None :
90+ """Test set up integration encountering an Attribute Error."""
91+
92+ with patch ("rxv.find" , side_effect = AttributeError ):
93+ assert await async_setup_component (hass , MP_DOMAIN , CONFIG )
94+ await hass .async_block_till_done ()
95+
96+ state = hass .states .get ("media_player.yamaha_receiver_main_zone" )
97+
98+ assert state is not None
99+ assert state .state == "off"
100+
66101
67102async def test_setup_no_host (hass : HomeAssistant , device , main_zone ) -> None :
68103 """Test set up integration without host."""
0 commit comments