@@ -47,7 +47,7 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
47
47
await hass .async_block_till_done ()
48
48
49
49
assert result3 ["type" ] is FlowResultType .CREATE_ENTRY
50
- assert result3 ["title" ] == "Germany, BW "
50
+ assert result3 ["title" ] == "Germany, Baden-Württemberg "
51
51
assert result3 ["data" ] == {
52
52
"country" : "DE" ,
53
53
"province" : "BW" ,
@@ -178,7 +178,7 @@ async def test_form_babel_unresolved_language(hass: HomeAssistant) -> None:
178
178
await hass .async_block_till_done ()
179
179
180
180
assert result ["type" ] is FlowResultType .CREATE_ENTRY
181
- assert result ["title" ] == "Germany, BW "
181
+ assert result ["title" ] == "Germany, Baden-Württemberg "
182
182
assert result ["data" ] == {
183
183
"country" : "DE" ,
184
184
"province" : "BW" ,
@@ -225,7 +225,7 @@ async def test_form_babel_replace_dash_with_underscore(hass: HomeAssistant) -> N
225
225
await hass .async_block_till_done ()
226
226
227
227
assert result ["type" ] is FlowResultType .CREATE_ENTRY
228
- assert result ["title" ] == "Germany, BW "
228
+ assert result ["title" ] == "Germany, Baden-Württemberg "
229
229
assert result ["data" ] == {
230
230
"country" : "DE" ,
231
231
"province" : "BW" ,
@@ -237,7 +237,7 @@ async def test_reconfigure(hass: HomeAssistant) -> None:
237
237
"""Test reconfigure flow."""
238
238
entry = MockConfigEntry (
239
239
domain = DOMAIN ,
240
- title = "Germany, BW " ,
240
+ title = "Germany, Baden-Württemberg " ,
241
241
data = {"country" : "DE" , "province" : "BW" },
242
242
)
243
243
entry .add_to_hass (hass )
@@ -256,7 +256,7 @@ async def test_reconfigure(hass: HomeAssistant) -> None:
256
256
assert result ["type" ] is FlowResultType .ABORT
257
257
assert result ["reason" ] == "reconfigure_successful"
258
258
entry = hass .config_entries .async_get_entry (entry .entry_id )
259
- assert entry .title == "Germany, NW "
259
+ assert entry .title == "Germany, Nordrhein-Westfalen "
260
260
assert entry .data == {"country" : "DE" , "province" : "NW" }
261
261
262
262
@@ -297,7 +297,7 @@ async def test_reconfigure_incorrect_language(hass: HomeAssistant) -> None:
297
297
298
298
entry = MockConfigEntry (
299
299
domain = DOMAIN ,
300
- title = "Germany, BW " ,
300
+ title = "Germany, Baden-Württemberg " ,
301
301
data = {"country" : "DE" , "province" : "BW" },
302
302
)
303
303
entry .add_to_hass (hass )
@@ -316,7 +316,7 @@ async def test_reconfigure_incorrect_language(hass: HomeAssistant) -> None:
316
316
assert result ["type" ] is FlowResultType .ABORT
317
317
assert result ["reason" ] == "reconfigure_successful"
318
318
entry = hass .config_entries .async_get_entry (entry .entry_id )
319
- assert entry .title == "Germany, NW "
319
+ assert entry .title == "Germany, Nordrhein-Westfalen "
320
320
assert entry .data == {"country" : "DE" , "province" : "NW" }
321
321
322
322
@@ -325,13 +325,13 @@ async def test_reconfigure_entry_exists(hass: HomeAssistant) -> None:
325
325
"""Test reconfigure flow stops if other entry already exist."""
326
326
entry = MockConfigEntry (
327
327
domain = DOMAIN ,
328
- title = "Germany, BW " ,
328
+ title = "Germany, Baden-Württemberg " ,
329
329
data = {"country" : "DE" , "province" : "BW" },
330
330
)
331
331
entry .add_to_hass (hass )
332
332
entry2 = MockConfigEntry (
333
333
domain = DOMAIN ,
334
- title = "Germany, NW " ,
334
+ title = "Germany, Nordrhein-Westfalen " ,
335
335
data = {"country" : "DE" , "province" : "NW" },
336
336
)
337
337
entry2 .add_to_hass (hass )
@@ -350,7 +350,7 @@ async def test_reconfigure_entry_exists(hass: HomeAssistant) -> None:
350
350
assert result ["type" ] is FlowResultType .ABORT
351
351
assert result ["reason" ] == "already_configured"
352
352
entry = hass .config_entries .async_get_entry (entry .entry_id )
353
- assert entry .title == "Germany, BW "
353
+ assert entry .title == "Germany, Baden-Württemberg "
354
354
assert entry .data == {"country" : "DE" , "province" : "BW" }
355
355
356
356
@@ -425,6 +425,47 @@ async def test_form_with_options(
425
425
assert state .state == STATE_OFF
426
426
427
427
428
+ async def test_form_with_subdivision_aliases (hass : HomeAssistant ) -> None :
429
+ """Test the flow with a country using subdivision aliases (friendly names)."""
430
+ await hass .config .async_set_time_zone ("Europe/Paris" )
431
+
432
+ result = await hass .config_entries .flow .async_init (
433
+ DOMAIN , context = {"source" : config_entries .SOURCE_USER }
434
+ )
435
+ assert result ["type" ] is FlowResultType .FORM
436
+
437
+ result = await hass .config_entries .flow .async_configure (
438
+ result ["flow_id" ],
439
+ {
440
+ CONF_COUNTRY : "FR" ,
441
+ },
442
+ )
443
+ await hass .async_block_till_done ()
444
+
445
+ assert result ["type" ] is FlowResultType .FORM
446
+ # Find friendly name exposed to the user
447
+ options = {
448
+ option ["value" ]: option ["label" ]
449
+ for option in result ["data_schema" ].schema ["province" ].config ["options" ]
450
+ }
451
+ assert options ["RE" ] == "La Réunion"
452
+
453
+ result = await hass .config_entries .flow .async_configure (
454
+ result ["flow_id" ],
455
+ {
456
+ CONF_PROVINCE : "RE" ,
457
+ },
458
+ )
459
+ await hass .async_block_till_done (wait_background_tasks = True )
460
+
461
+ assert result ["type" ] is FlowResultType .CREATE_ENTRY
462
+ assert result ["title" ] == "France, La Réunion"
463
+ assert result ["data" ] == {
464
+ CONF_COUNTRY : "FR" ,
465
+ CONF_PROVINCE : "RE" ,
466
+ }
467
+
468
+
428
469
@pytest .mark .usefixtures ("mock_setup_entry" )
429
470
async def test_options_abort_no_categories (hass : HomeAssistant ) -> None :
430
471
"""Test the options flow abort if no categories to select."""
0 commit comments