3030 CONF_UNIT_OF_MEASUREMENT ,
3131)
3232from homeassistant .core import HomeAssistant
33+ from homeassistant .exceptions import HomeAssistantError , ServiceValidationError
3334from homeassistant .setup import async_setup_component
3435
3536from .conftest import (
@@ -134,6 +135,23 @@ async def test_service_relays(
134135
135136 control_relays .assert_awaited_with (relay_states )
136137
138+ # wrong states string
139+ with (
140+ patch .object (MockModuleConnection , "control_relays" ) as control_relays ,
141+ pytest .raises (HomeAssistantError ) as exc_info ,
142+ ):
143+ await hass .services .async_call (
144+ DOMAIN ,
145+ LcnService .RELAYS ,
146+ {
147+ CONF_DEVICE_ID : get_device (hass , entry , (0 , 7 , False )).id ,
148+ CONF_STATE : "0011TT--00" ,
149+ },
150+ blocking = True ,
151+ )
152+ assert exc_info .value .translation_domain == DOMAIN
153+ assert exc_info .value .translation_key == "invalid_length_of_states_string"
154+
137155
138156async def test_service_led (
139157 hass : HomeAssistant ,
@@ -328,7 +346,7 @@ async def test_service_send_keys_hit_deferred(
328346 patch .object (
329347 MockModuleConnection , "send_keys_hit_deferred"
330348 ) as send_keys_hit_deferred ,
331- pytest .raises (ValueError ) ,
349+ pytest .raises (ServiceValidationError ) as exc_info ,
332350 ):
333351 await hass .services .async_call (
334352 DOMAIN ,
@@ -342,6 +360,8 @@ async def test_service_send_keys_hit_deferred(
342360 },
343361 blocking = True ,
344362 )
363+ assert exc_info .value .translation_domain == DOMAIN
364+ assert exc_info .value .translation_key == "invalid_send_keys_action"
345365
346366
347367async def test_service_lock_keys (
@@ -369,6 +389,24 @@ async def test_service_lock_keys(
369389
370390 lock_keys .assert_awaited_with (0 , lock_states )
371391
392+ # wrong states string
393+ with (
394+ patch .object (MockModuleConnection , "lock_keys" ) as lock_keys ,
395+ pytest .raises (HomeAssistantError ) as exc_info ,
396+ ):
397+ await hass .services .async_call (
398+ DOMAIN ,
399+ LcnService .LOCK_KEYS ,
400+ {
401+ CONF_DEVICE_ID : get_device (hass , entry , (0 , 7 , False )).id ,
402+ CONF_TABLE : "a" ,
403+ CONF_STATE : "0011TT--00" ,
404+ },
405+ blocking = True ,
406+ )
407+ assert exc_info .value .translation_domain == DOMAIN
408+ assert exc_info .value .translation_key == "invalid_length_of_states_string"
409+
372410
373411async def test_service_lock_keys_tab_a_temporary (
374412 hass : HomeAssistant ,
@@ -406,7 +444,7 @@ async def test_service_lock_keys_tab_a_temporary(
406444 patch .object (
407445 MockModuleConnection , "lock_keys_tab_a_temporary"
408446 ) as lock_keys_tab_a_temporary ,
409- pytest .raises (ValueError ) ,
447+ pytest .raises (ServiceValidationError ) as exc_info ,
410448 ):
411449 await hass .services .async_call (
412450 DOMAIN ,
@@ -420,6 +458,8 @@ async def test_service_lock_keys_tab_a_temporary(
420458 },
421459 blocking = True ,
422460 )
461+ assert exc_info .value .translation_domain == DOMAIN
462+ assert exc_info .value .translation_key == "invalid_lock_keys_table"
423463
424464
425465async def test_service_dyn_text (
0 commit comments