mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Do not swallow WLED errors (#72407)
This commit is contained in:
parent
a5402d725f
commit
652892e535
@ -2,7 +2,7 @@
|
||||
|
||||
from wled import WLEDConnectionError, WLEDError
|
||||
|
||||
from .const import LOGGER
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
|
||||
def wled_exception_handler(func):
|
||||
@ -18,11 +18,11 @@ def wled_exception_handler(func):
|
||||
self.coordinator.update_listeners()
|
||||
|
||||
except WLEDConnectionError as error:
|
||||
LOGGER.error("Error communicating with API: %s", error)
|
||||
self.coordinator.last_update_success = False
|
||||
self.coordinator.update_listeners()
|
||||
raise HomeAssistantError("Error communicating with WLED API") from error
|
||||
|
||||
except WLEDError as error:
|
||||
LOGGER.error("Invalid response from API: %s", error)
|
||||
raise HomeAssistantError("Invalid response from WLED API") from error
|
||||
|
||||
return handler
|
||||
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
@ -55,11 +56,11 @@ async def test_button_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED buttons."""
|
||||
mock_wled.reset.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
@ -71,18 +72,17 @@ async def test_button_error(
|
||||
state = hass.states.get("button.wled_rgb_light_restart")
|
||||
assert state
|
||||
assert state.state == "2021-11-04T16:37:00+00:00"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
|
||||
|
||||
async def test_button_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED buttons."""
|
||||
mock_wled.reset.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
@ -94,4 +94,3 @@ async def test_button_connection_error(
|
||||
state = hass.states.get("button.wled_rgb_light_restart")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
|
@ -25,6 +25,7 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@ -305,11 +306,11 @@ async def test_light_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED lights."""
|
||||
mock_wled.segment.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
@ -321,7 +322,6 @@ async def test_light_error(
|
||||
state = hass.states.get("light.wled_rgb_light")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
||||
|
||||
@ -330,11 +330,11 @@ async def test_light_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED switches."""
|
||||
mock_wled.segment.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
@ -346,7 +346,6 @@ async def test_light_connection_error(
|
||||
state = hass.states.get("light.wled_rgb_light")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
||||
|
||||
|
@ -14,6 +14,7 @@ from homeassistant.components.number.const import (
|
||||
from homeassistant.components.wled.const import SCAN_INTERVAL
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@ -109,11 +110,11 @@ async def test_speed_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED numbers."""
|
||||
mock_wled.segment.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
@ -128,7 +129,6 @@ async def test_speed_error(
|
||||
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
||||
assert state
|
||||
assert state.state == "16"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
||||
|
||||
@ -137,11 +137,11 @@ async def test_speed_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED numbers."""
|
||||
mock_wled.segment.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
@ -156,7 +156,6 @@ async def test_speed_connection_error(
|
||||
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
||||
|
||||
@ -250,11 +249,11 @@ async def test_intensity_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED numbers."""
|
||||
mock_wled.segment.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
@ -269,7 +268,6 @@ async def test_intensity_error(
|
||||
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
||||
assert state
|
||||
assert state.state == "64"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, intensity=21)
|
||||
|
||||
@ -278,11 +276,11 @@ async def test_intensity_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED numbers."""
|
||||
mock_wled.segment.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
@ -297,6 +295,5 @@ async def test_intensity_connection_error(
|
||||
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, intensity=128)
|
||||
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
import homeassistant.util.dt as dt_util
|
||||
@ -161,11 +162,11 @@ async def test_color_palette_select_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.segment.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -180,7 +181,6 @@ async def test_color_palette_select_error(
|
||||
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
||||
assert state
|
||||
assert state.state == "Random Cycle"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
||||
|
||||
@ -189,11 +189,11 @@ async def test_color_palette_select_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.segment.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -208,7 +208,6 @@ async def test_color_palette_select_connection_error(
|
||||
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
||||
|
||||
@ -280,11 +279,11 @@ async def test_preset_select_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.preset.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -299,7 +298,6 @@ async def test_preset_select_error(
|
||||
state = hass.states.get("select.wled_rgbw_light_preset")
|
||||
assert state
|
||||
assert state.state == "Preset 1"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.preset.call_count == 1
|
||||
mock_wled.preset.assert_called_with(preset="Preset 2")
|
||||
|
||||
@ -309,11 +307,11 @@ async def test_preset_select_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.preset.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -328,7 +326,6 @@ async def test_preset_select_connection_error(
|
||||
state = hass.states.get("select.wled_rgbw_light_preset")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.preset.call_count == 1
|
||||
mock_wled.preset.assert_called_with(preset="Preset 2")
|
||||
|
||||
@ -400,11 +397,11 @@ async def test_playlist_select_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.playlist.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -419,7 +416,6 @@ async def test_playlist_select_error(
|
||||
state = hass.states.get("select.wled_rgbw_light_playlist")
|
||||
assert state
|
||||
assert state.state == "Playlist 1"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.playlist.call_count == 1
|
||||
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
||||
|
||||
@ -429,11 +425,11 @@ async def test_playlist_select_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.playlist.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -448,7 +444,6 @@ async def test_playlist_select_connection_error(
|
||||
state = hass.states.get("select.wled_rgbw_light_playlist")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.playlist.call_count == 1
|
||||
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
||||
|
||||
@ -489,11 +484,11 @@ async def test_live_select_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.live.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -508,7 +503,6 @@ async def test_live_select_error(
|
||||
state = hass.states.get("select.wled_rgb_light_live_override")
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.live.call_count == 1
|
||||
mock_wled.live.assert_called_with(live=1)
|
||||
|
||||
@ -517,11 +511,11 @@ async def test_live_select_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED selects."""
|
||||
mock_wled.live.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
@ -536,6 +530,5 @@ async def test_live_select_connection_error(
|
||||
state = hass.states.get("select.wled_rgb_light_live_override")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
assert mock_wled.live.call_count == 1
|
||||
mock_wled.live.assert_called_with(live=2)
|
||||
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
import homeassistant.util.dt as dt_util
|
||||
@ -175,11 +176,11 @@ async def test_switch_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED switches."""
|
||||
mock_wled.nightlight.side_effect = WLEDError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
@ -191,18 +192,17 @@ async def test_switch_error(
|
||||
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert "Invalid response from API" in caplog.text
|
||||
|
||||
|
||||
async def test_switch_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED switches."""
|
||||
mock_wled.nightlight.side_effect = WLEDConnectionError
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
@ -214,7 +214,6 @@ async def test_switch_connection_error(
|
||||
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert "Error communicating with API" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_wled", ["wled/rgb_single_segment.json"], indirect=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user