99_LOGGER = logging .getLogger (__name__ )
1010
1111class ConfigFlow (config_entries .ConfigFlow , domain = DOMAIN ):
12+ """First start of integration settings."""
1213 VERSION = 1
1314 CONNECTION_CLASS = config_entries .CONN_CLASS_LOCAL_PUSH
1415
1516 @staticmethod
1617 @callback
1718 def async_get_options_flow (config_entry ):
19+ """Get stored configuration data to present in async_step_init."""
20+ _LOGGER .warning ("async_get_options_flow called: %s" , config_entry )
1821 return OptionsFlowHandler (config_entry )
1922
2023 async def async_step_user (self , user_input = None ):
24+ """First step: Initial set-up of integration options."""
25+ _LOGGER .warning ("async_step_user" )
2126 schema = vol .Schema ({
22- vol .Required ("EMA host " , default = "3.67.1.32" ): str ,
23- vol .Required ("Message ignore age " , default = "1800" ): str ,
24- vol .Required ("Max stub interval " , default = "300" ): str ,
25- vol .Required ("No update timeout " , default = "600" ): str ,
26- vol .Optional ( "Send to EMA " , default = True ): bool ,
27+ vol .Required ("ema_host " , default = "3.67.1.32" ): str ,
28+ vol .Required ("message_ignore_age " , default = "1800" ): str ,
29+ vol .Required ("max_stub_interval " , default = "300" ): str ,
30+ vol .Required ("no_update_timeout " , default = "600" ): str ,
31+ vol .Required ( "send_to_ema " , default = True ): bool ,
2732 })
2833
2934 if user_input is not None :
@@ -36,25 +41,34 @@ async def async_step_user(self, user_input=None):
3641 data_schema = schema ,
3742 errors = {"base" : "Could not connect to the specified EMA host." },
3843 )
39-
4044 return self .async_show_form (step_id = "user" , data_schema = schema )
4145
46+
47+
4248class OptionsFlowHandler (config_entries .OptionsFlow ):
49+ """Regular change of integration options."""
4350 def __init__ (self , config_entry : config_entries .ConfigEntry ) -> None :
4451 self .config_entry = config_entry
4552
4653 async def async_step_init (self , user_input = None ):
47- current_options = self .config_entry .options or {}
54+ """Second step: Altering the integration options."""
55+ current_options = (
56+ self .config_entry .data
57+ if not self .config_entry .options
58+ else self .config_entry .options
59+ )
60+ _LOGGER .warning ("async_step_init with options: %s" , current_options )
61+
4862 schema = vol .Schema ({
49- vol .Optional ( "EMA host " , default = current_options .get ("ema_host" , "3.67.1.32 " )): str ,
50- vol .Optional ( "Message ignore age " , default = current_options .get ("Message ignore age" , "1800 " )): str ,
51- vol .Optional ( "Max stub interval " , default = current_options .get ("Max stub interval" , "300 " )): str ,
52- vol .Optional ( "No update timeout " , default = current_options .get ("No update timeout" , "600 " )): str ,
53- vol .Optional ( "Send to EMA " , default = current_options .get ("Send to EMA" , True )): bool ,
63+ vol .Required ( "ema_host " , default = current_options .get ("ema_host" )): str ,
64+ vol .Required ( "message_ignore_age " , default = current_options .get ("message_ignore_age " )): str ,
65+ vol .Required ( "max_stub_interval " , default = current_options .get ("max_stub_interval " )): str ,
66+ vol .Required ( "no_update_timeout " , default = current_options .get ("no_update_timeout " )): str ,
67+ vol .Required ( "send_to_ema " , default = current_options .get ("send_to_ema" )): bool ,
5468 })
5569
5670 if user_input is not None :
57- ema_host = user_input ["EMA host " ]
71+ ema_host = user_input ["ema_host " ]
5872 if await self .validate_ip (ema_host ):
5973 updated_options = current_options .copy ()
6074 updated_options .update (user_input )
@@ -65,7 +79,6 @@ async def async_step_init(self, user_input=None):
6579 data_schema = schema ,
6680 errors = {"base" : "Could not connect to the specified EMA host." },
6781 )
68-
6982 return self .async_show_form (step_id = "init" , data_schema = schema )
7083
7184 @staticmethod
0 commit comments