11from __future__ import annotations
2+ import asyncio
23from homeassistant import config_entries
34from homeassistant .config_entries import ConfigEntry
45from homeassistant .core import callback
89
910_LOGGER = logging .getLogger (__name__ )
1011DOMAIN = "uhomeuponor"
12+ CONF_SUPPORTS_HEATING = "supports_heating"
13+ CONF_SUPPORTS_COOLING = "supports_cooling"
1114
1215class UhomeuponorConfigFlow (config_entries .ConfigFlow , domain = DOMAIN ):
1316 """Uponor config flow."""
@@ -16,22 +19,25 @@ class UhomeuponorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
1619
1720 async def async_step_user (self , user_input = None ):
1821 errors = {}
22+ _LOGGER .info ("Init config step uhomeuponor" )
1923 if self ._async_current_entries ():
2024 return self .async_abort (reason = "single_instance_allowed" )
2125 if user_input is not None :
22- _LOGGER .info ("user_input: %s" , user_input )
26+ _LOGGER .debug ("user_input: %s" , user_input )
2327 # Validate user input
2428 #valid = await is_valid(user_input)
2529 #if valid:
2630 #title = f"{self.info[CONF_HOST]} - {self.device_id}"
2731 title = f"Uhome Uponor"
28- prefix = user_input .get (CONF_PREFIX ) if user_input .get (CONF_PREFIX ) else ""
32+ data = {
33+ CONF_HOST : user_input [CONF_HOST ],
34+ CONF_PREFIX : (user_input .get (CONF_PREFIX ) if user_input .get (CONF_PREFIX ) else "" ),
35+ CONF_SUPPORTS_HEATING : user_input [CONF_SUPPORTS_HEATING ],
36+ CONF_SUPPORTS_COOLING : user_input [CONF_SUPPORTS_COOLING ]}
2937 return self .async_create_entry (
3038 title = title ,
31- data = {
32- "host" : user_input [CONF_HOST ],
33- "prefix" : prefix ,
34- },
39+ data = data
40+ # options=data
3541 )
3642
3743 return self .async_show_form (
@@ -40,56 +46,58 @@ async def async_step_user(self, user_input=None):
4046 {
4147 vol .Required (CONF_HOST ): str ,
4248 vol .Optional (CONF_PREFIX ): str ,
49+ vol .Optional (CONF_SUPPORTS_HEATING , default = True ): bool ,
50+ vol .Optional (CONF_SUPPORTS_COOLING , default = True ): bool ,
4351 }
4452 ), errors = errors
4553 )
4654
47- # @staticmethod
48- # @callback
49- # def async_get_options_flow(
50- # config_entry: ConfigEntry,
51- # ) -> UhomeuponorOptionsFlowHandler:
52- # """Options callback for uponor."""
53- # return UhomeuponorOptionsFlowHandler(config_entry)
55+ @staticmethod
56+ @callback
57+ def async_get_options_flow (entry : config_entries .ConfigEntry ):
58+ return OptionsFlowHandler (entry )
5459
60+ class OptionsFlowHandler (config_entries .OptionsFlow ):
5561
56- # class UhomeuponorOptionsFlowHandler(config_entries.OptionsFlow):
57- # """Config flow options for uponor."""
62+ def __init__ (self , config_entry ):
63+ """Initialize options flow."""
64+ self .config_entry = config_entry
5865
59- # def __init__(self, entry: ConfigEntry) -> None:
60- # """Initialize AccuWeather options flow."""
61- # self.config_entry = entry
62-
63- # async def async_step_init(self, user_input=None):
64- # """Manage the options."""
65- # return await self.async_step_user()
66-
67- # async def async_step_user(self, user_input=None):
68- # errors = {}
69- # if user_input is not None:
70- # _LOGGER.info ("Aqui debemos hacer algo con user_input: %s", user_input)
71- # # Validate user input
72- # #valid = await is_valid(user_input)
73- # #if valid:
74- # #title = f"{self.info[CONF_HOST]} - {self.device_id}"
75- # title = f"Uhome Uponor"
76- # return self.async_create_entry(
77- # title=title,
78- # data={
79- # "host": user_input[CONF_HOST],
80- # "prefix": user_input[CONF_PREFIX],
81- # },
82- # )
66+ async def async_step_init (self , _user_input = None ):
67+ """Manage the options."""
68+ return await self .async_step_user ()
69+
70+ async def async_step_user (self , user_input = None ):
71+ """Handle a flow initialized by the user."""
72+ _LOGGER .debug ("entra en step user: %s" , user_input )
73+ _LOGGER .info ("Init Option config step uhomeuponor" )
74+ errors = {}
75+ options = self .config_entry .data
76+ if user_input is not None :
77+ data = {
78+ CONF_HOST : user_input [CONF_HOST ],
79+ CONF_PREFIX : user_input [CONF_PREFIX ],
80+ CONF_SUPPORTS_HEATING : user_input [CONF_SUPPORTS_HEATING ],
81+ CONF_SUPPORTS_COOLING : user_input [CONF_SUPPORTS_COOLING ],
82+ }
83+ _LOGGER .debug ("user_input data: %s, id: %s" , data , self .config_entry .entry_id )
84+ title = f"Uhome Uponor"
85+ return self .async_create_entry (
86+ title = title ,
87+ data = data
88+ )
8389
84- # return self.async_show_form(
85- # step_id="user",
86- # data_schema=vol.Schema(
87- # {
88- # vol.Required(CONF_HOST): str,
89- # vol.Optional(CONF_PREFIX): str,
90- # }
91- # ), errors=errors
92- # )
90+ return self .async_show_form (
91+ step_id = "user" ,
92+ data_schema = vol .Schema (
93+ {
94+ vol .Required (CONF_HOST , default = options .get (CONF_HOST )): str ,
95+ vol .Optional (CONF_PREFIX , default = options .get (CONF_PREFIX )): str ,
96+ vol .Optional (CONF_SUPPORTS_HEATING , default = options .get (CONF_SUPPORTS_HEATING )): bool ,
97+ vol .Optional (CONF_SUPPORTS_COOLING , default = options .get (CONF_SUPPORTS_COOLING )): bool ,
98+ }
99+ ), errors = errors
100+ )
93101
94102# class UhomeuponorDicoveryFlow(DiscoveryFlowHandler[Awaitable[bool]], domain=DOMAIN):
95103# """Discovery flow handler."""
0 commit comments