vesync last response None (#191710)

This commit is contained in:
cdnninja
2026-11-10 07:06:25 +01:00
committed by GitHub
parent ac4e310ac4
commit 7859f5316a
2 changed files with 46 additions and 1 deletions
+3 -1
View File
@@ -189,5 +189,7 @@ class VeSyncSelectEntity(VeSyncBaseEntity, SelectEntity):
async def async_select_option(self, option: str) -> None:
"""Set an option."""
if not await self.entity_description.select_option_fn(self.device, option):
raise HomeAssistantError(self.device.last_response.message)
if self.device.last_response:
raise HomeAssistantError(self.device.last_response.message)
raise HomeAssistantError("Unknown error selecting option, no response.")
self.async_write_ha_state()
+43
View File
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, Mock
import pytest
from pyvesync.const import DeviceStatus
from pyvesync.utils.errors import ResponseInfo
from homeassistant.components.select import (
ATTR_OPTION,
@@ -21,6 +22,7 @@ from homeassistant.components.vesync.select import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from .common import ENTITY_HUMIDIFIER_300S_NIGHT_LIGHT_SELECT
@@ -82,3 +84,44 @@ async def test_humidifier_nightlight_level(
hass.states.get(ENTITY_HUMIDIFIER_300S_NIGHT_LIGHT_SELECT).state
== expected_state
)
@pytest.mark.parametrize(
"install_humidifier_device", ["humidifier_300s"], indirect=True
)
@pytest.mark.parametrize(
("last_response", "message"),
[
pytest.param(
ResponseInfo(name="error", error_type="error", message="Device error"),
"Device error",
id="last_response",
),
pytest.param(
None,
"Unknown error selecting option, no response.",
id="no_last_response",
),
],
)
@pytest.mark.usefixtures("install_humidifier_device")
async def test_select_option_device_failure(
hass: HomeAssistant,
humidifier_300s: Mock,
last_response: ResponseInfo | None,
message: str,
) -> None:
"""Test an error is raised when the device rejects the option."""
humidifier_300s.set_nightlight_brightness.return_value = False
humidifier_300s.last_response = last_response
with pytest.raises(HomeAssistantError, match=message):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: ENTITY_HUMIDIFIER_300S_NIGHT_LIGHT_SELECT,
ATTR_OPTION: HUMIDIFIER_NIGHT_LIGHT_LEVEL_DIM,
},
blocking=True,
)