mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
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>
This commit is contained in:
parent
dde1ecbf5b
commit
2c3d97d373
@ -1,6 +1,7 @@
|
|||||||
"""Constants for the Yamaha component."""
|
"""Constants for the Yamaha component."""
|
||||||
|
|
||||||
DOMAIN = "yamaha"
|
DOMAIN = "yamaha"
|
||||||
|
DISCOVER_TIMEOUT = 3
|
||||||
KNOWN_ZONES = "known_zones"
|
KNOWN_ZONES = "known_zones"
|
||||||
CURSOR_TYPE_DOWN = "down"
|
CURSOR_TYPE_DOWN = "down"
|
||||||
CURSOR_TYPE_LEFT = "left"
|
CURSOR_TYPE_LEFT = "left"
|
||||||
|
@ -31,6 +31,7 @@ from .const import (
|
|||||||
CURSOR_TYPE_RIGHT,
|
CURSOR_TYPE_RIGHT,
|
||||||
CURSOR_TYPE_SELECT,
|
CURSOR_TYPE_SELECT,
|
||||||
CURSOR_TYPE_UP,
|
CURSOR_TYPE_UP,
|
||||||
|
DISCOVER_TIMEOUT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KNOWN_ZONES,
|
KNOWN_ZONES,
|
||||||
SERVICE_ENABLE_OUTPUT,
|
SERVICE_ENABLE_OUTPUT,
|
||||||
@ -125,18 +126,33 @@ def _discovery(config_info):
|
|||||||
elif config_info.host is None:
|
elif config_info.host is None:
|
||||||
_LOGGER.debug("Config No Host Supplied Zones")
|
_LOGGER.debug("Config No Host Supplied Zones")
|
||||||
zones = []
|
zones = []
|
||||||
for recv in rxv.find():
|
for recv in rxv.find(DISCOVER_TIMEOUT):
|
||||||
zones.extend(recv.zone_controllers())
|
zones.extend(recv.zone_controllers())
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("Config Zones")
|
_LOGGER.debug("Config Zones")
|
||||||
zones = None
|
zones = None
|
||||||
|
|
||||||
# Fix for upstream issues in rxv.find() with some hardware.
|
# Fix for upstream issues in rxv.find() with some hardware.
|
||||||
with contextlib.suppress(AttributeError):
|
with contextlib.suppress(AttributeError, ValueError):
|
||||||
for recv in rxv.find():
|
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:
|
if recv.ctrl_url == config_info.ctrl_url:
|
||||||
_LOGGER.debug("Config Zones Matched %s", config_info.ctrl_url)
|
_LOGGER.debug(
|
||||||
zones = recv.zone_controllers()
|
"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
|
break
|
||||||
|
|
||||||
if not zones:
|
if not zones:
|
||||||
@ -170,7 +186,7 @@ async def async_setup_platform(
|
|||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for zctrl in zone_ctrls:
|
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:
|
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)
|
_LOGGER.debug("Ignore receiver zone: %s %s", config_info.name, zctrl.zone)
|
||||||
continue
|
continue
|
||||||
|
@ -86,10 +86,18 @@ async def test_setup_host(hass: HomeAssistant, device, device2, main_zone) -> No
|
|||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_attribute_error(hass: HomeAssistant, device, main_zone) -> None:
|
@pytest.mark.parametrize(
|
||||||
"""Test set up integration encountering an Attribute Error."""
|
("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)
|
assert await async_setup_component(hass, MP_DOMAIN, CONFIG)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user