raise HomeAssistantError when velux gateway reboot fails (#159585)

Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
wollew
2025-12-23 13:41:49 +01:00
committed by GitHub
co-authored by Josef Zweck
parent 3e498d289b
commit 82d84d7adf
2 changed files with 59 additions and 3 deletions
+45
View File
@@ -13,9 +13,12 @@ from unittest.mock import patch
import pytest
from pyvlx.exception import PyVLXException
from homeassistant.components.velux.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.setup import async_setup_component
from tests.common import AsyncMock, ConfigEntry, MockConfigEntry
@@ -100,3 +103,45 @@ async def test_unload_does_not_disconnect_if_platform_unload_fails(
# Verify disconnect was NOT called since platform unload failed
mock_pyvlx.disconnect.assert_not_awaited()
@pytest.mark.usefixtures("setup_integration")
async def test_reboot_gateway_service_raises_on_exception(
hass: HomeAssistant, mock_pyvlx: AsyncMock
) -> None:
"""Test that reboot_gateway service raises HomeAssistantError on exception."""
mock_pyvlx.reboot_gateway.side_effect = OSError("Connection failed")
with pytest.raises(HomeAssistantError, match="Failed to reboot gateway"):
await hass.services.async_call(
"velux",
"reboot_gateway",
blocking=True,
)
mock_pyvlx.reboot_gateway.side_effect = PyVLXException("Reboot failed")
with pytest.raises(HomeAssistantError, match="Failed to reboot gateway"):
await hass.services.async_call(
"velux",
"reboot_gateway",
blocking=True,
)
async def test_reboot_gateway_service_raises_validation_error(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
"""Test that reboot_gateway service raises ServiceValidationError when no gateway is loaded."""
# Add the config entry but don't set it up
mock_config_entry.add_to_hass(hass)
# Set up the velux integration's async_setup to register the service
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
with pytest.raises(ServiceValidationError, match="No loaded Velux gateway found"):
await hass.services.async_call(
"velux",
"reboot_gateway",
blocking=True,
)