@@ -48,30 +48,59 @@ def async_get_options_flow(config_entry):
4848
4949class AndroidWsPlayerOptionsFlow (config_entries .OptionsFlow ):
5050 async def async_step_init (self , user_input = None ):
51+ errors : dict [str , str ] = {}
52+
5153 if user_input is not None :
52- # Update entry title (friendly name shown in UI )
54+ device_id = user_input [ CONF_DEVICE_ID ]. strip ( )
5355 new_title = user_input ["name" ].strip ()
54- if new_title and new_title != self .config_entry .title :
55- self .hass .config_entries .async_update_entry (self .config_entry , title = new_title )
5656
57- # Store other tunables in options
58- return self .async_create_entry (
59- title = "" ,
60- data = {
61- CONF_EVENT_TYPE : user_input .get (CONF_EVENT_TYPE , DEFAULT_EVENT_TYPE ).strip (),
62- },
63- )
57+ if not device_id :
58+ errors ["base" ] = "invalid_device_id"
59+ else :
60+ for entry in self .hass .config_entries .async_entries (DOMAIN ):
61+ if (
62+ entry .entry_id != self .config_entry .entry_id
63+ and entry .unique_id == device_id
64+ ):
65+ errors [CONF_DEVICE_ID ] = "already_configured"
66+ break
67+
68+ if not errors :
69+ data = dict (self .config_entry .data )
70+ data [CONF_DEVICE_ID ] = device_id
71+
72+ self .hass .config_entries .async_update_entry (
73+ self .config_entry ,
74+ title = new_title or self .config_entry .title ,
75+ data = data ,
76+ unique_id = device_id ,
77+ )
78+
79+ return self .async_create_entry (
80+ title = "" ,
81+ data = {
82+ CONF_EVENT_TYPE : user_input .get (
83+ CONF_EVENT_TYPE , DEFAULT_EVENT_TYPE
84+ ).strip (),
85+ },
86+ )
6487
6588 schema = vol .Schema (
6689 {
6790 vol .Required ("name" , default = self .config_entry .title ): str ,
91+ vol .Required (
92+ CONF_DEVICE_ID , default = self .config_entry .data [CONF_DEVICE_ID ]
93+ ): str ,
6894 vol .Optional (
6995 CONF_EVENT_TYPE ,
7096 default = self .config_entry .options .get (
71- CONF_EVENT_TYPE , self .config_entry .data .get (CONF_EVENT_TYPE , DEFAULT_EVENT_TYPE )
97+ CONF_EVENT_TYPE ,
98+ self .config_entry .data .get (CONF_EVENT_TYPE , DEFAULT_EVENT_TYPE ),
7299 ),
73100 ): str ,
74101 }
75102 )
76103
77- return self .async_show_form (step_id = "init" , data_schema = schema )
104+ return self .async_show_form (
105+ step_id = "init" , data_schema = schema , errors = errors
106+ )
0 commit comments