From 7859f5316a89946c845a1d2da4cd2353fffcaf69 Mon Sep 17 00:00:00 2001 From: cdnninja Date: Tue, 10 Nov 2026 00:06:25 -0600 Subject: [PATCH] vesync last response None (#191710) --- homeassistant/components/vesync/select.py | 4 ++- tests/components/vesync/test_select.py | 43 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/vesync/select.py b/homeassistant/components/vesync/select.py index 0bd433baab07..9248a39baddf 100644 --- a/homeassistant/components/vesync/select.py +++ b/homeassistant/components/vesync/select.py @@ -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() diff --git a/tests/components/vesync/test_select.py b/tests/components/vesync/test_select.py index 438f7b63e9ee..4cbc49aed01c 100644 --- a/tests/components/vesync/test_select.py +++ b/tests/components/vesync/test_select.py @@ -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, + )