99
1010import homeassistant .helpers .config_validation as cv
1111import voluptuous as vol
12- from homeassistant .const import ATTR_HIDDEN , CONF_ENTITIES , CONF_NAME , WEEKDAYS
12+ from homeassistant .const import ATTR_HIDDEN , CONF_ENTITIES , CONF_NAME
1313from homeassistant .core import callback
1414from homeassistant .helpers import selector
1515from homeassistant .helpers .schema_config_entry_flow import (
@@ -63,15 +63,18 @@ def optional(
6363 return vol .Optional (key , description = {"suggested_value" : suggested_value })
6464
6565
66- async def general_options_schema (
66+ async def general_config_schema (
6767 handler : SchemaConfigFlowHandler | SchemaOptionsFlowHandler ,
6868) -> vol .Schema :
69- """Generate options schema."""
69+ """Generate config schema."""
7070 return vol .Schema (
7171 {
72+ optional (CONF_NAME , handler .options ): selector .TextSelector (),
7273 required (
7374 const .CONF_FREQUENCY , handler .options , const .DEFAULT_FREQUENCY
74- ): vol .In (const .FREQUENCY_OPTIONS ),
75+ ): selector .SelectSelector (
76+ selector .SelectSelectorConfig (options = const .FREQUENCY_OPTIONS )
77+ ),
7578 optional (
7679 const .CONF_ICON_NORMAL , handler .options , const .DEFAULT_ICON_NORMAL
7780 ): selector .IconSelector (),
@@ -91,16 +94,17 @@ async def general_options_schema(
9194 )
9295
9396
94- async def general_config_schema (
97+ async def general_options_schema (
9598 handler : SchemaConfigFlowHandler | SchemaOptionsFlowHandler ,
9699) -> vol .Schema :
97- """Generate config schema."""
100+ """Generate options schema."""
98101 return vol .Schema (
99102 {
100- optional (CONF_NAME , handler .options ): selector .TextSelector (),
101103 required (
102104 const .CONF_FREQUENCY , handler .options , const .DEFAULT_FREQUENCY
103- ): vol .In (const .FREQUENCY_OPTIONS ),
105+ ): selector .SelectSelector (
106+ selector .SelectSelectorConfig (options = const .FREQUENCY_OPTIONS )
107+ ),
104108 optional (
105109 const .CONF_ICON_NORMAL , handler .options , const .DEFAULT_ICON_NORMAL
106110 ): selector .IconSelector (),
@@ -127,7 +131,9 @@ async def detail_config_schema(
127131 options_schema : Dict [vol .Optional | vol .Required , Any ] = {}
128132 if handler .options [const .CONF_FREQUENCY ] in const .ANNUAL_FREQUENCY :
129133 # "annual"
130- options_schema [required (const .CONF_DATE , handler .options )] = str
134+ options_schema [
135+ required (const .CONF_DATE , handler .options )
136+ ] = selector .TextSelector ()
131137 elif handler .options [const .CONF_FREQUENCY ] in const .GROUP_FREQUENCY :
132138 # "group"
133139 options_schema [
@@ -140,41 +146,67 @@ async def detail_config_schema(
140146 elif handler .options [const .CONF_FREQUENCY ] not in const .BLANK_FREQUENCY :
141147 # everything else except "blank" and every-n-days
142148 if handler .options [const .CONF_FREQUENCY ] not in const .DAILY_FREQUENCY :
143- weekdays_dict = {weekday : weekday for weekday in WEEKDAYS }
144149 options_schema [
145150 required (const .CONF_COLLECTION_DAYS , handler .options )
146- ] = cv .multi_select (weekdays_dict )
151+ ] = selector .SelectSelector (
152+ selector .SelectSelectorConfig (
153+ options = const .WEEKDAY_OPTIONS ,
154+ multiple = True ,
155+ mode = selector .SelectSelectorMode .LIST ,
156+ )
157+ )
147158 # everything else except "blank"
148159 options_schema [
149160 optional (const .CONF_FIRST_MONTH , handler .options , const .DEFAULT_FIRST_MONTH )
150- ] = vol .In (const .MONTH_OPTIONS )
161+ ] = selector .SelectSelector (
162+ selector .SelectSelectorConfig (options = const .MONTH_OPTIONS )
163+ )
151164 options_schema [
152165 optional (const .CONF_LAST_MONTH , handler .options , const .DEFAULT_LAST_MONTH )
153- ] = vol .In (const .MONTH_OPTIONS )
166+ ] = selector .SelectSelector (
167+ selector .SelectSelectorConfig (options = const .MONTH_OPTIONS )
168+ )
154169 if handler .options [const .CONF_FREQUENCY ] in const .MONTHLY_FREQUENCY :
155170 # "monthly"
156171 options_schema [
157172 optional (const .CONF_WEEKDAY_ORDER_NUMBER , handler .options )
158- ] = vol .All (
159- cv .multi_select (
160- {"1" : "1st" , "2" : "2nd" , "3" : "3rd" , "4" : "4th" , "5" : "5th" }
161- ),
173+ ] = selector .SelectSelector (
174+ selector .SelectSelectorConfig (
175+ options = const .ORDER_OPTIONS ,
176+ multiple = True ,
177+ mode = selector .SelectSelectorMode .LIST ,
178+ )
162179 )
163180 options_schema [
164181 optional (const .CONF_FORCE_WEEK_NUMBERS , handler .options )
165- ] = bool
182+ ] = selector . BooleanSelector ()
166183 if handler .options [const .CONF_FREQUENCY ] in const .WEEKLY_DAILY_MONTHLY :
167184 # "every-n-weeks", "every-n-days", "monthly"
168- options_schema [required (const .CONF_PERIOD , handler .options )] = vol .All (
169- vol .Coerce (int ), vol .Range (min = 1 , max = 1000 )
185+ uom = {"every-n-weeks" : "weeks" , "every-n-days" : "days" , "monthly" : "month" }
186+ options_schema [
187+ required (const .CONF_PERIOD , handler .options )
188+ ] = selector .NumberSelector (
189+ selector .NumberSelectorConfig (
190+ min = 1 ,
191+ max = 1000 ,
192+ mode = selector .NumberSelectorMode .BOX ,
193+ unit_of_measurement = uom [handler .options [const .CONF_FREQUENCY ]],
194+ )
170195 )
171196 if handler .options [const .CONF_FREQUENCY ] in const .WEEKLY_FREQUENCY_X :
172197 # every-n-weeks
173198 options_schema [
174199 required (
175200 const .CONF_FIRST_WEEK , handler .options , const .DEFAULT_FIRST_WEEK
176201 )
177- ] = vol .All (vol .Coerce (int ), vol .Range (min = 1 , max = 52 ))
202+ ] = selector .NumberSelector (
203+ selector .NumberSelectorConfig (
204+ min = 1 ,
205+ max = 52 ,
206+ mode = selector .NumberSelectorMode .BOX ,
207+ unit_of_measurement = "weeks" ,
208+ )
209+ )
178210 if handler .options [const .CONF_FREQUENCY ] in const .DAILY_FREQUENCY :
179211 # every-n-days
180212 options_schema [
@@ -186,10 +218,10 @@ async def detail_config_schema(
186218 required (
187219 const .CONF_VERBOSE_FORMAT , handler .options , const .DEFAULT_VERBOSE_FORMAT
188220 )
189- ] = cv . string
221+ ] = selector . TextSelector ()
190222 options_schema [
191223 required (const .CONF_DATE_FORMAT , handler .options , const .DEFAULT_DATE_FORMAT )
192- ] = cv . string
224+ ] = selector . TextSelector ()
193225 return vol .Schema (options_schema )
194226
195227
0 commit comments