3333 "db_days" : {"required" : False , "config" : "db_days" , "default" : 30 },
3434 },
3535 "can_restart" : False ,
36+ "phase" : 0 ,
3637 },
3738 "ha" : {
3839 "class" : HAInterface ,
4546 "db_primary" : {"required" : False , "config" : "db_primary" , "default" : False },
4647 },
4748 "can_restart" : False ,
49+ "phase" : 0 ,
4850 },
4951 "ha_history" : {
5052 "class" : HAHistory ,
5153 "name" : "Home Assistant History" ,
5254 "args" : {},
5355 "can_restart" : False ,
56+ "phase" : 0 ,
57+ },
58+ "web" : {
59+ "class" : WebInterface ,
60+ "name" : "Web Interface" ,
61+ "args" : {
62+ "port" : {"required" : False , "config" : "web_port" , "default" : 5052 },
63+ },
64+ "phase" : 0 ,
5465 },
55- "web" : {"class" : WebInterface , "name" : "Web Interface" , "args" : {"port" : {"required" : False , "config" : "web_port" , "default" : 5052 }}},
5666 "mcp" : {
5767 "class" : PredbatMCPServer ,
5868 "name" : "MCP Server" ,
6171 "mcp_secret" : {"required" : False , "config" : "mcp_secret" , "default" : "predbat_mcp_secret" },
6272 "mcp_port" : {"required" : False , "config" : "mcp_port" , "default" : 8199 },
6373 },
74+ "phase" : 1 ,
6475 },
6576 "solar" : {
6677 "class" : SolarAPI ,
8091 "pv_scaling" : {"required" : False , "config" : "pv_scaling" , "default" : 1.0 },
8192 },
8293 "required_or" : ["solcast_host" , "forecast_solar" , "pv_forecast_today" ],
94+ "phase" : 1 ,
8395 },
8496 "gecloud" : {
8597 "class" : GECloudDirect ,
100112 "config" : "ge_cloud_automatic" ,
101113 },
102114 },
115+ "phase" : 1 ,
103116 },
104117 "gecloud_data" : {
105118 "class" : GECloudData ,
123136 "config" : "days_previous" ,
124137 },
125138 },
139+ "phase" : 1 ,
126140 },
127141 "octopus" : {
128142 "class" : OctopusAPI ,
143157 "config" : "octopus_automatic" ,
144158 },
145159 },
160+ "phase" : 1 ,
146161 },
147162 "ohme" : {
148163 "class" : OhmeAPI ,
162177 "config" : "ohme_automatic_octopus_intelligent" ,
163178 },
164179 },
180+ "phase" : 1 ,
165181 },
166182 "fox" : {
167183 "class" : FoxAPI ,
178194 "config" : "fox_automatic" ,
179195 },
180196 },
197+ "phase" : 1 ,
181198 },
182199 "alert_feed" : {
183200 "class" : AlertFeed ,
190207 "config" : "alerts" ,
191208 },
192209 },
210+ "phase" : 1 ,
193211 },
194212 "carbon" : {
195213 "class" : CarbonAPI ,
198216 "postcode" : {"required" : True , "config" : "carbon_postcode" },
199217 "automatic" : {"required" : False , "config" : "carbon_automatic" , "default" : False },
200218 },
219+ "phase" : 1 ,
201220 },
202221}
203222
@@ -209,11 +228,13 @@ def __init__(self, base):
209228 self .base = base
210229 self .log = base .log
211230
212- def initialize (self , only = None ):
231+ def initialize (self , only = None , phase = 0 ):
213232 """Initialize components without starting them"""
214233 for component_name , component_info in COMPONENT_LIST .items ():
215234 if only and component_name != only :
216235 continue
236+ if component_info .get ("phase" , 0 ) != phase :
237+ continue
217238
218239 have_all_args = True
219240 self .components [component_name ] = None
@@ -246,14 +267,16 @@ def initialize(self, only=None):
246267 self .log (f"Initializing { component_info ['name' ]} interface" )
247268 self .components [component_name ] = component_info ["class" ](* arg_dict .values (), self .base )
248269
249- def start (self , only = None ):
270+ def start (self , only = None , phase = 0 ):
250271 """Start all initialized components"""
251272 failed = False
252273 for component_name , component_info in COMPONENT_LIST .items ():
253274 if only and component_name != only :
254275 continue
255276 component = self .components .get (component_name )
256277 if component :
278+ if component_info .get ("phase" , 0 ) != phase :
279+ continue
257280 if self .component_tasks .get (component_name , None ) and self .component_tasks [component_name ].is_alive ():
258281 self .log (f"Info: { component_info ['name' ]} interface already started" )
259282 continue
0 commit comments