mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +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 wled import WLEDConnectionError, WLEDError
|
||||||
|
|
||||||
from .const import LOGGER
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
|
|
||||||
def wled_exception_handler(func):
|
def wled_exception_handler(func):
|
||||||
@ -18,11 +18,11 @@ def wled_exception_handler(func):
|
|||||||
self.coordinator.update_listeners()
|
self.coordinator.update_listeners()
|
||||||
|
|
||||||
except WLEDConnectionError as error:
|
except WLEDConnectionError as error:
|
||||||
LOGGER.error("Error communicating with API: %s", error)
|
|
||||||
self.coordinator.last_update_success = False
|
self.coordinator.last_update_success = False
|
||||||
self.coordinator.update_listeners()
|
self.coordinator.update_listeners()
|
||||||
|
raise HomeAssistantError("Error communicating with WLED API") from error
|
||||||
|
|
||||||
except WLEDError as error:
|
except WLEDError as error:
|
||||||
LOGGER.error("Invalid response from API: %s", error)
|
raise HomeAssistantError("Invalid response from WLED API") from error
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
|
||||||
@ -55,43 +56,41 @@ async def test_button_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED buttons."""
|
"""Test error handling of the WLED buttons."""
|
||||||
mock_wled.reset.side_effect = WLEDError
|
mock_wled.reset.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
BUTTON_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_PRESS,
|
BUTTON_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "button.wled_rgb_light_restart"},
|
SERVICE_PRESS,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "button.wled_rgb_light_restart"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("button.wled_rgb_light_restart")
|
state = hass.states.get("button.wled_rgb_light_restart")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "2021-11-04T16:37:00+00:00"
|
assert state.state == "2021-11-04T16:37:00+00:00"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
async def test_button_connection_error(
|
async def test_button_connection_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED buttons."""
|
"""Test error handling of the WLED buttons."""
|
||||||
mock_wled.reset.side_effect = WLEDConnectionError
|
mock_wled.reset.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
BUTTON_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_PRESS,
|
BUTTON_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "button.wled_rgb_light_restart"},
|
SERVICE_PRESS,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "button.wled_rgb_light_restart"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("button.wled_rgb_light_restart")
|
state = hass.states.get("button.wled_rgb_light_restart")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
|
@ -25,6 +25,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
@ -305,23 +306,22 @@ async def test_light_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED lights."""
|
"""Test error handling of the WLED lights."""
|
||||||
mock_wled.segment.side_effect = WLEDError
|
mock_wled.segment.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
LIGHT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_TURN_OFF,
|
LIGHT_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "light.wled_rgb_light"},
|
SERVICE_TURN_OFF,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "light.wled_rgb_light"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("light.wled_rgb_light")
|
state = hass.states.get("light.wled_rgb_light")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
||||||
|
|
||||||
@ -330,23 +330,22 @@ async def test_light_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED switches."""
|
"""Test error handling of the WLED switches."""
|
||||||
mock_wled.segment.side_effect = WLEDConnectionError
|
mock_wled.segment.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
LIGHT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_TURN_OFF,
|
LIGHT_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "light.wled_rgb_light"},
|
SERVICE_TURN_OFF,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "light.wled_rgb_light"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("light.wled_rgb_light")
|
state = hass.states.get("light.wled_rgb_light")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
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.components.wled.const import SCAN_INTERVAL
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, STATE_UNAVAILABLE
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, STATE_UNAVAILABLE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
@ -109,26 +110,25 @@ async def test_speed_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED numbers."""
|
"""Test error handling of the WLED numbers."""
|
||||||
mock_wled.segment.side_effect = WLEDError
|
mock_wled.segment.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
NUMBER_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SET_VALUE,
|
NUMBER_DOMAIN,
|
||||||
{
|
SERVICE_SET_VALUE,
|
||||||
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_speed",
|
{
|
||||||
ATTR_VALUE: 42,
|
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_speed",
|
||||||
},
|
ATTR_VALUE: 42,
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "16"
|
assert state.state == "16"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
||||||
|
|
||||||
@ -137,26 +137,25 @@ async def test_speed_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED numbers."""
|
"""Test error handling of the WLED numbers."""
|
||||||
mock_wled.segment.side_effect = WLEDConnectionError
|
mock_wled.segment.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
NUMBER_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SET_VALUE,
|
NUMBER_DOMAIN,
|
||||||
{
|
SERVICE_SET_VALUE,
|
||||||
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_speed",
|
{
|
||||||
ATTR_VALUE: 42,
|
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_speed",
|
||||||
},
|
ATTR_VALUE: 42,
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
state = hass.states.get("number.wled_rgb_light_segment_1_speed")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
mock_wled.segment.assert_called_with(segment_id=1, speed=42)
|
||||||
|
|
||||||
@ -250,26 +249,25 @@ async def test_intensity_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED numbers."""
|
"""Test error handling of the WLED numbers."""
|
||||||
mock_wled.segment.side_effect = WLEDError
|
mock_wled.segment.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
NUMBER_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SET_VALUE,
|
NUMBER_DOMAIN,
|
||||||
{
|
SERVICE_SET_VALUE,
|
||||||
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_intensity",
|
{
|
||||||
ATTR_VALUE: 21,
|
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_intensity",
|
||||||
},
|
ATTR_VALUE: 21,
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "64"
|
assert state.state == "64"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, intensity=21)
|
mock_wled.segment.assert_called_with(segment_id=1, intensity=21)
|
||||||
|
|
||||||
@ -278,25 +276,24 @@ async def test_intensity_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED numbers."""
|
"""Test error handling of the WLED numbers."""
|
||||||
mock_wled.segment.side_effect = WLEDConnectionError
|
mock_wled.segment.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
NUMBER_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SET_VALUE,
|
NUMBER_DOMAIN,
|
||||||
{
|
SERVICE_SET_VALUE,
|
||||||
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_intensity",
|
{
|
||||||
ATTR_VALUE: 128,
|
ATTR_ENTITY_ID: "number.wled_rgb_light_segment_1_intensity",
|
||||||
},
|
ATTR_VALUE: 128,
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
state = hass.states.get("number.wled_rgb_light_segment_1_intensity")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, intensity=128)
|
mock_wled.segment.assert_called_with(segment_id=1, intensity=128)
|
||||||
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -161,26 +162,25 @@ async def test_color_palette_select_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.segment.side_effect = WLEDError
|
mock_wled.segment.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
|
{
|
||||||
ATTR_OPTION: "Icefire",
|
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
|
||||||
},
|
ATTR_OPTION: "Icefire",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "Random Cycle"
|
assert state.state == "Random Cycle"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
||||||
|
|
||||||
@ -189,26 +189,25 @@ async def test_color_palette_select_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.segment.side_effect = WLEDConnectionError
|
mock_wled.segment.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
|
{
|
||||||
ATTR_OPTION: "Icefire",
|
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
|
||||||
},
|
ATTR_OPTION: "Icefire",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
state = hass.states.get("select.wled_rgb_light_segment_1_color_palette")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.segment.call_count == 1
|
assert mock_wled.segment.call_count == 1
|
||||||
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
|
||||||
|
|
||||||
@ -280,26 +279,25 @@ async def test_preset_select_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.preset.side_effect = WLEDError
|
mock_wled.preset.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
|
{
|
||||||
ATTR_OPTION: "Preset 2",
|
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
|
||||||
},
|
ATTR_OPTION: "Preset 2",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgbw_light_preset")
|
state = hass.states.get("select.wled_rgbw_light_preset")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "Preset 1"
|
assert state.state == "Preset 1"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.preset.call_count == 1
|
assert mock_wled.preset.call_count == 1
|
||||||
mock_wled.preset.assert_called_with(preset="Preset 2")
|
mock_wled.preset.assert_called_with(preset="Preset 2")
|
||||||
|
|
||||||
@ -309,26 +307,25 @@ async def test_preset_select_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.preset.side_effect = WLEDConnectionError
|
mock_wled.preset.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
|
{
|
||||||
ATTR_OPTION: "Preset 2",
|
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
|
||||||
},
|
ATTR_OPTION: "Preset 2",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgbw_light_preset")
|
state = hass.states.get("select.wled_rgbw_light_preset")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.preset.call_count == 1
|
assert mock_wled.preset.call_count == 1
|
||||||
mock_wled.preset.assert_called_with(preset="Preset 2")
|
mock_wled.preset.assert_called_with(preset="Preset 2")
|
||||||
|
|
||||||
@ -400,26 +397,25 @@ async def test_playlist_select_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.playlist.side_effect = WLEDError
|
mock_wled.playlist.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
|
{
|
||||||
ATTR_OPTION: "Playlist 2",
|
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
|
||||||
},
|
ATTR_OPTION: "Playlist 2",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgbw_light_playlist")
|
state = hass.states.get("select.wled_rgbw_light_playlist")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "Playlist 1"
|
assert state.state == "Playlist 1"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.playlist.call_count == 1
|
assert mock_wled.playlist.call_count == 1
|
||||||
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
||||||
|
|
||||||
@ -429,26 +425,25 @@ async def test_playlist_select_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.playlist.side_effect = WLEDConnectionError
|
mock_wled.playlist.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
|
{
|
||||||
ATTR_OPTION: "Playlist 2",
|
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
|
||||||
},
|
ATTR_OPTION: "Playlist 2",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgbw_light_playlist")
|
state = hass.states.get("select.wled_rgbw_light_playlist")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.playlist.call_count == 1
|
assert mock_wled.playlist.call_count == 1
|
||||||
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
|
||||||
|
|
||||||
@ -489,26 +484,25 @@ async def test_live_select_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.live.side_effect = WLEDError
|
mock_wled.live.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
|
{
|
||||||
ATTR_OPTION: "1",
|
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
|
||||||
},
|
ATTR_OPTION: "1",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgb_light_live_override")
|
state = hass.states.get("select.wled_rgb_light_live_override")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "0"
|
assert state.state == "0"
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
assert mock_wled.live.call_count == 1
|
assert mock_wled.live.call_count == 1
|
||||||
mock_wled.live.assert_called_with(live=1)
|
mock_wled.live.assert_called_with(live=1)
|
||||||
|
|
||||||
@ -517,25 +511,24 @@ async def test_live_select_connection_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED selects."""
|
"""Test error handling of the WLED selects."""
|
||||||
mock_wled.live.side_effect = WLEDConnectionError
|
mock_wled.live.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
SELECT_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SELECT_OPTION,
|
SELECT_DOMAIN,
|
||||||
{
|
SERVICE_SELECT_OPTION,
|
||||||
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
|
{
|
||||||
ATTR_OPTION: "2",
|
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
|
||||||
},
|
ATTR_OPTION: "2",
|
||||||
blocking=True,
|
},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("select.wled_rgb_light_live_override")
|
state = hass.states.get("select.wled_rgb_light_live_override")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Error communicating with API" in caplog.text
|
|
||||||
assert mock_wled.live.call_count == 1
|
assert mock_wled.live.call_count == 1
|
||||||
mock_wled.live.assert_called_with(live=2)
|
mock_wled.live.assert_called_with(live=2)
|
||||||
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -175,46 +176,44 @@ async def test_switch_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED switches."""
|
"""Test error handling of the WLED switches."""
|
||||||
mock_wled.nightlight.side_effect = WLEDError
|
mock_wled.nightlight.side_effect = WLEDError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
|
||||||
SWITCH_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_TURN_ON,
|
SWITCH_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "switch.wled_rgb_light_nightlight"},
|
SERVICE_TURN_ON,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "switch.wled_rgb_light_nightlight"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "Invalid response from API" in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_connection_error(
|
async def test_switch_connection_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
mock_wled: MagicMock,
|
mock_wled: MagicMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error handling of the WLED switches."""
|
"""Test error handling of the WLED switches."""
|
||||||
mock_wled.nightlight.side_effect = WLEDConnectionError
|
mock_wled.nightlight.side_effect = WLEDConnectionError
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
|
||||||
SWITCH_DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_TURN_ON,
|
SWITCH_DOMAIN,
|
||||||
{ATTR_ENTITY_ID: "switch.wled_rgb_light_nightlight"},
|
SERVICE_TURN_ON,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: "switch.wled_rgb_light_nightlight"},
|
||||||
)
|
blocking=True,
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
state = hass.states.get("switch.wled_rgb_light_nightlight")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNAVAILABLE
|
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)
|
@pytest.mark.parametrize("mock_wled", ["wled/rgb_single_segment.json"], indirect=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user