Fix swallowed exceptions in action handlers for NETGEAR LTE (#181539)

This commit is contained in:
Martin
2026-09-07 13:15:24 +02:00
committed by GitHub
parent 6f02b27a2e
commit 17f1e6349a
3 changed files with 43 additions and 5 deletions
@@ -8,9 +8,10 @@ from eternalegypt.eternalegypt import Modem
from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService
from homeassistant.const import CONF_RECIPIENT
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import CONF_NOTIFY, LOGGER
from .const import CONF_NOTIFY, DOMAIN, LOGGER
async def async_get_service(
@@ -57,6 +58,9 @@ class NetgearNotifyService(BaseNotificationService):
for target in targets:
try:
await self.modem.sms(target, message)
# pylint: disable-next=home-assistant-action-swallowed-exception
except eternalegypt.Error:
LOGGER.error("Unable to send to %s", target)
except eternalegypt.Error as err:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="send_message_failed",
translation_placeholders={"target": target},
) from err
@@ -74,6 +74,9 @@
"exceptions": {
"config_entry_not_found": {
"message": "Failed to perform action \"{service}\". Config entry for target not found"
},
"send_message_failed": {
"message": "Failed to send SMS to {target}."
}
},
"services": {
+32 -1
View File
@@ -2,15 +2,21 @@
from unittest.mock import patch
import eternalegypt
import pytest
from homeassistant.components.netgear_lte.const import DOMAIN
from homeassistant.components.notify import (
ATTR_MESSAGE,
ATTR_TARGET,
DOMAIN as NOTIFY_DOMAIN,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
ICON_PATH = "/some/path"
MESSAGE = "one, two, testing, testing"
TARGET = "5555555556"
async def test_notify(hass: HomeAssistant, setup_integration: None) -> None:
@@ -23,8 +29,33 @@ async def test_notify(hass: HomeAssistant, setup_integration: None) -> None:
"netgear_lm1200",
{
ATTR_MESSAGE: MESSAGE,
ATTR_TARGET: "5555555556",
ATTR_TARGET: TARGET,
},
blocking=True,
)
assert len(mock.mock_calls) == 1
@pytest.mark.usefixtures("setup_integration")
async def test_notify_error(hass: HomeAssistant) -> None:
"""Test that a failed send raises an error with a translation key."""
with (
patch(
"homeassistant.components.netgear_lte.eternalegypt.Modem.sms",
side_effect=eternalegypt.Error,
),
pytest.raises(HomeAssistantError) as exc_info,
):
await hass.services.async_call(
NOTIFY_DOMAIN,
"netgear_lm1200",
{
ATTR_MESSAGE: MESSAGE,
ATTR_TARGET: TARGET,
},
blocking=True,
)
assert exc_info.value.translation_domain == DOMAIN
assert exc_info.value.translation_key == "send_message_failed"
assert exc_info.value.translation_placeholders == {"target": TARGET}