1010
1111from homeassistant .components .bluetooth import async_discovered_service_info
1212from homeassistant .components .bluetooth .models import BluetoothServiceInfoBleak
13- from homeassistant .config_entries import ConfigFlow , ConfigFlowResult
13+ from homeassistant .config_entries import (
14+ SOURCE_RECONFIGURE ,
15+ ConfigFlow ,
16+ ConfigFlowResult ,
17+ )
1418from homeassistant .const import CONF_ADDRESS , CONF_PIN , CONF_TIMEOUT
1519from homeassistant .data_entry_flow import FlowResult
1620from homeassistant .helpers .device_registry import format_mac
@@ -62,22 +66,35 @@ def __init__(self) -> None:
6266 self ._discovered_device : str | None = None
6367 self ._discovered_devices : list [str ] = []
6468
65- def _create_entry (self , pin : int , device_name : str | None = None ) -> FlowResult :
69+ def _create_entry (
70+ self ,
71+ pin : int ,
72+ device_name : str | None = None ,
73+ timeout : int = DEFAULT_TIMEOUT_SECONDS ,
74+ retry_count : int = DEFAULT_RETRY_COUNT ,
75+ ) -> FlowResult :
6676 """Create an entry for a discovered device."""
6777
78+ entry_data = {
79+ CONF_ADDRESS : None ,
80+ CONF_PIN : pin ,
81+ CONF_DEVICE_NAME : device_name ,
82+ CONF_TIMEOUT : timeout ,
83+ CONF_RETRY_COUNT : retry_count ,
84+ }
85+
86+ if self .source == SOURCE_RECONFIGURE :
87+ entry_data [CONF_ADDRESS ] = self ._existing_entry_data [CONF_ADDRESS ]
88+ return self .async_update_reload_and_abort (
89+ self ._get_reconfigure_entry (),
90+ data = entry_data ,
91+ )
92+
6893 if self ._discovery_info is None or self ._discovery_info .address is None :
6994 raise ValueError ("Discovery info not set" )
95+ entry_data [CONF_ADDRESS ] = self ._discovery_info .address
7096
71- return self .async_create_entry (
72- title = device_name ,
73- data = {
74- CONF_ADDRESS : self ._discovery_info .address ,
75- CONF_PIN : pin ,
76- CONF_DEVICE_NAME : device_name ,
77- CONF_TIMEOUT : DEFAULT_TIMEOUT_SECONDS ,
78- CONF_RETRY_COUNT : DEFAULT_RETRY_COUNT ,
79- },
80- )
97+ return self .async_create_entry (title = device_name , data = entry_data )
8198
8299 async def async_step_bluetooth_confirm (
83100 self , user_input : dict [str , Any ] | None = None
@@ -86,7 +103,10 @@ async def async_step_bluetooth_confirm(
86103
87104 if user_input is not None :
88105 return self ._create_entry (
89- user_input [CONF_PIN ], user_input .get (CONF_DEVICE_NAME )
106+ user_input [CONF_PIN ],
107+ user_input .get (CONF_DEVICE_NAME ),
108+ timeout = user_input .get (CONF_TIMEOUT ),
109+ retry_count = user_input .get (CONF_RETRY_COUNT ),
90110 )
91111
92112 try :
0 commit comments