Handle Yamaha ValueError (#123547)
* fix yamaha remove info logging * ruff * fix yamnaha supress rxv.find UnicodeDecodeError * fix formatting * make more realistic * make more realistic and use parms * add value error after more feedback * ruff format * Update homeassistant/components/yamaha/media_player.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * remove unused method * add more debugging * Increase discovery timeout add more debug allow config to overrite dicovery for name --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/123968/head^2
parent
dde1ecbf5b
commit
2c3d97d373
|
@ -1,6 +1,7 @@
|
|||
"""Constants for the Yamaha component."""
|
||||
|
||||
DOMAIN = "yamaha"
|
||||
DISCOVER_TIMEOUT = 3
|
||||
KNOWN_ZONES = "known_zones"
|
||||
CURSOR_TYPE_DOWN = "down"
|
||||
CURSOR_TYPE_LEFT = "left"
|
||||
|
|
|
@ -31,6 +31,7 @@ from .const import (
|
|||
CURSOR_TYPE_RIGHT,
|
||||
CURSOR_TYPE_SELECT,
|
||||
CURSOR_TYPE_UP,
|
||||
DISCOVER_TIMEOUT,
|
||||
DOMAIN,
|
||||
KNOWN_ZONES,
|
||||
SERVICE_ENABLE_OUTPUT,
|
||||
|
@ -125,18 +126,33 @@ def _discovery(config_info):
|
|||
elif config_info.host is None:
|
||||
_LOGGER.debug("Config No Host Supplied Zones")
|
||||
zones = []
|
||||
for recv in rxv.find():
|
||||
for recv in rxv.find(DISCOVER_TIMEOUT):
|
||||
zones.extend(recv.zone_controllers())
|
||||
else:
|
||||
_LOGGER.debug("Config Zones")
|
||||
zones = None
|
||||
|
||||
# Fix for upstream issues in rxv.find() with some hardware.
|
||||
with contextlib.suppress(AttributeError):
|
||||
for recv in rxv.find():
|
||||
with contextlib.suppress(AttributeError, ValueError):
|
||||
for recv in rxv.find(DISCOVER_TIMEOUT):
|
||||
_LOGGER.debug(
|
||||
"Found Serial %s %s %s",
|
||||
recv.serial_number,
|
||||
recv.ctrl_url,
|
||||
recv.zone,
|
||||
)
|
||||
if recv.ctrl_url == config_info.ctrl_url:
|
||||
_LOGGER.debug("Config Zones Matched %s", config_info.ctrl_url)
|
||||
zones = recv.zone_controllers()
|
||||
_LOGGER.debug(
|
||||
"Config Zones Matched Serial %s: %s",
|
||||
recv.ctrl_url,
|
||||
recv.serial_number,
|
||||
)
|
||||
zones = rxv.RXV(
|
||||
config_info.ctrl_url,
|
||||
friendly_name=config_info.name,
|
||||
serial_number=recv.serial_number,
|
||||
model_name=recv.model_name,
|
||||
).zone_controllers()
|
||||
break
|
||||
|
||||
if not zones:
|
||||
|
@ -170,7 +186,7 @@ async def async_setup_platform(
|
|||
|
||||
entities = []
|
||||
for zctrl in zone_ctrls:
|
||||
_LOGGER.debug("Receiver zone: %s", zctrl.zone)
|
||||
_LOGGER.debug("Receiver zone: %s serial %s", zctrl.zone, zctrl.serial_number)
|
||||
if config_info.zone_ignore and zctrl.zone in config_info.zone_ignore:
|
||||
_LOGGER.debug("Ignore receiver zone: %s %s", config_info.name, zctrl.zone)
|
||||
continue
|
||||
|
|
|
@ -86,10 +86,18 @@ async def test_setup_host(hass: HomeAssistant, device, device2, main_zone) -> No
|
|||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_setup_attribute_error(hass: HomeAssistant, device, main_zone) -> None:
|
||||
"""Test set up integration encountering an Attribute Error."""
|
||||
@pytest.mark.parametrize(
|
||||
("error"),
|
||||
[
|
||||
AttributeError,
|
||||
ValueError,
|
||||
UnicodeDecodeError("", b"", 1, 0, ""),
|
||||
],
|
||||
)
|
||||
async def test_setup_find_errors(hass: HomeAssistant, device, main_zone, error) -> None:
|
||||
"""Test set up integration encountering an Error."""
|
||||
|
||||
with patch("rxv.find", side_effect=AttributeError):
|
||||
with patch("rxv.find", side_effect=error):
|
||||
assert await async_setup_component(hass, MP_DOMAIN, CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Reference in New Issue