Raise ServiceValidationError on invalid select option (#106350)
* Raise ServiceValidationError on invalid select option * Fix tests * Correct place holders * More test fixes
This commit is contained in:
parent
fbcb31b103
commit
c7eab49c70
11 changed files with 60 additions and 27 deletions
|
@ -17,6 +17,7 @@ from homeassistant.components.select import (
|
|||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
|
@ -111,8 +112,8 @@ async def test_custom_integration_and_validation(
|
|||
await hass.async_block_till_done()
|
||||
assert hass.states.get("select.select_1").state == "option 2"
|
||||
|
||||
# test ValueError trigger
|
||||
with pytest.raises(ValueError):
|
||||
# test ServiceValidationError trigger
|
||||
with pytest.raises(ServiceValidationError) as exc:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
|
@ -120,11 +121,14 @@ async def test_custom_integration_and_validation(
|
|||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert exc.value.translation_domain == DOMAIN
|
||||
assert exc.value.translation_key == "not_valid_option"
|
||||
|
||||
assert hass.states.get("select.select_1").state == "option 2"
|
||||
|
||||
assert hass.states.get("select.select_2").state == STATE_UNKNOWN
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue