@@ -27,6 +27,9 @@ async def async_step_user(self, user_input=None, usb_device=None):
2727 errors = {}
2828
2929 if user_input is not None :
30+ if user_input [CONF_SERIAL_PORT ] == "Enter Manually" :
31+ self .user_input = user_input
32+ return await self .async_step_manual_path ()
3033 return self .async_create_entry (title = "Pylontech Battery" , data = user_input )
3134
3235 ports = await self .hass .async_add_executor_job (serial .tools .list_ports .comports )
@@ -36,7 +39,8 @@ async def async_step_user(self, user_input=None, usb_device=None):
3639
3740 if usb_device and usb_device not in list_of_ports :
3841 list_of_ports [usb_device ] = usb_device
39-
42+
43+ list_of_ports ["Enter Manually" ] = "Enter Manually"
4044 default_port = usb_device if usb_device else vol .UNDEFINED
4145
4246 schema = vol .Schema ({
@@ -50,6 +54,19 @@ async def async_step_user(self, user_input=None, usb_device=None):
5054 step_id = "user" , data_schema = schema , errors = errors
5155 )
5256
57+ async def async_step_manual_path (self , user_input = None ):
58+ """Handle manual serial port entry."""
59+ if user_input is not None :
60+ self .user_input [CONF_SERIAL_PORT ] = user_input [CONF_SERIAL_PORT ]
61+ return self .async_create_entry (title = "Pylontech Battery" , data = self .user_input )
62+
63+ return self .async_show_form (
64+ step_id = "manual_path" ,
65+ data_schema = vol .Schema ({
66+ vol .Required (CONF_SERIAL_PORT ): str
67+ })
68+ )
69+
5370 @staticmethod
5471 @callback
5572 def async_get_options_flow (config_entry ):
@@ -72,7 +89,10 @@ async def async_step_user(self, user_input=None):
7289 current_cap = self .config_entry .options .get (CONF_BATTERY_CAPACITY , self .config_entry .data .get (CONF_BATTERY_CAPACITY , DEFAULT_BATTERY_CAPACITY ))
7390
7491 if user_input is not None :
75- return self .async_create_entry (title = "" , data = user_input )
92+ if user_input [CONF_SERIAL_PORT ] == "Enter Manually" :
93+ self .user_input = user_input
94+ return await self .async_step_manual_path ()
95+ return self .async_create_entry (title = "" , data = user_input )
7696
7797 ports = await self .hass .async_add_executor_job (serial .tools .list_ports .comports )
7898 list_of_ports = {}
@@ -83,6 +103,8 @@ async def async_step_user(self, user_input=None):
83103 if current_port is not None and current_port not in list_of_ports :
84104 list_of_ports [current_port ] = current_port
85105
106+ list_of_ports ["Enter Manually" ] = "Enter Manually"
107+
86108 default_port = current_port if current_port is not None else vol .UNDEFINED
87109
88110 schema = vol .Schema ({
@@ -93,3 +115,16 @@ async def async_step_user(self, user_input=None):
93115 })
94116
95117 return self .async_show_form (step_id = "user" , data_schema = schema , errors = errors )
118+
119+ async def async_step_manual_path (self , user_input = None ):
120+ """Handle manual serial port entry."""
121+ if user_input is not None :
122+ self .user_input [CONF_SERIAL_PORT ] = user_input [CONF_SERIAL_PORT ]
123+ return self .async_create_entry (title = "" , data = self .user_input )
124+
125+ return self .async_show_form (
126+ step_id = "manual_path" ,
127+ data_schema = vol .Schema ({
128+ vol .Required (CONF_SERIAL_PORT , default = self .user_input .get (CONF_SERIAL_PORT , "" )): str
129+ })
130+ )
0 commit comments