Fix yamaha legacy receivers (#122985)
This commit is contained in:
parent
d530137bec
commit
fd5533d719
2 changed files with 46 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
|
@ -129,11 +130,15 @@ def _discovery(config_info):
|
|||
else:
|
||||
_LOGGER.debug("Config Zones")
|
||||
zones = None
|
||||
for recv in rxv.find():
|
||||
if recv.ctrl_url == config_info.ctrl_url:
|
||||
_LOGGER.debug("Config Zones Matched %s", config_info.ctrl_url)
|
||||
zones = recv.zone_controllers()
|
||||
break
|
||||
|
||||
# Fix for upstream issues in rxv.find() with some hardware.
|
||||
with contextlib.suppress(AttributeError):
|
||||
for recv in rxv.find():
|
||||
if recv.ctrl_url == config_info.ctrl_url:
|
||||
_LOGGER.debug("Config Zones Matched %s", config_info.ctrl_url)
|
||||
zones = recv.zone_controllers()
|
||||
break
|
||||
|
||||
if not zones:
|
||||
_LOGGER.debug("Config Zones Fallback")
|
||||
zones = rxv.RXV(config_info.ctrl_url, config_info.name).zone_controllers()
|
||||
|
|
|
@ -53,7 +53,20 @@ def device_fixture(main_zone):
|
|||
yield device
|
||||
|
||||
|
||||
async def test_setup_host(hass: HomeAssistant, device, main_zone) -> None:
|
||||
@pytest.fixture(name="device2")
|
||||
def device2_fixture(main_zone):
|
||||
"""Mock the yamaha device."""
|
||||
device = FakeYamahaDevice(
|
||||
"http://127.0.0.1:80/YamahaRemoteControl/ctrl", "Receiver 2", zones=[main_zone]
|
||||
)
|
||||
with (
|
||||
patch("rxv.RXV", return_value=device),
|
||||
patch("rxv.find", return_value=[device]),
|
||||
):
|
||||
yield device
|
||||
|
||||
|
||||
async def test_setup_host(hass: HomeAssistant, device, device2, main_zone) -> None:
|
||||
"""Test set up integration with host."""
|
||||
assert await async_setup_component(hass, MP_DOMAIN, CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -63,6 +76,28 @@ async def test_setup_host(hass: HomeAssistant, device, main_zone) -> None:
|
|||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
with patch("rxv.find", return_value=[device2]):
|
||||
assert await async_setup_component(hass, MP_DOMAIN, CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("media_player.yamaha_receiver_main_zone")
|
||||
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_setup_attribute_error(hass: HomeAssistant, device, main_zone) -> None:
|
||||
"""Test set up integration encountering an Attribute Error."""
|
||||
|
||||
with patch("rxv.find", side_effect=AttributeError):
|
||||
assert await async_setup_component(hass, MP_DOMAIN, CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("media_player.yamaha_receiver_main_zone")
|
||||
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_setup_no_host(hass: HomeAssistant, device, main_zone) -> None:
|
||||
"""Test set up integration without host."""
|
||||
|
|
Loading…
Add table
Reference in a new issue