@@ -216,6 +216,7 @@ async def full_connect(self) -> bool:
216216
217217 logger .info ("Loading data from panel memory" )
218218 await self .panel .load_memory ()
219+ self ._init_module_pgms ()
219220
220221 logger .info ("Running" )
221222 self .run_state = RunState .RUN
@@ -489,33 +490,61 @@ async def control_partition(self, partition: str, command: str) -> bool:
489490
490491 return accepted
491492
493+ def _init_module_pgms (self ):
494+ for addr , pgm_count in cfg .MODULE_PGM_ADDRESSES .items ():
495+ for pgm_index in range (1 , pgm_count + 1 ):
496+ key = f"module{ addr } _pgm{ pgm_index } "
497+ self .storage .get_container ("module_pgm" )[key ] = {
498+ "id" : pgm_index ,
499+ "key" : key ,
500+ "label" : f"Module { addr } PGM { pgm_index } " ,
501+ "module_address" : addr ,
502+ "pgm_index" : pgm_index ,
503+ }
504+ self .storage .update_container_object ("module_pgm" , key , {"on" : False })
505+
492506 async def control_output (self , output , command ) -> bool :
493507 command = command .lower ()
494508 logger .debug (f"Control Output: { output } - { command } " )
495509
496510 outputs_selected = self .storage .get_container ("pgm" ).select (output )
497-
498- # Not Found
499- if len (outputs_selected ) == 0 :
500- logger .error ("No outputs selected" )
501- return False
502-
503- # Apply state changes
504- accepted = False
505- try :
506- accepted = await self .panel .control_outputs (outputs_selected , command )
507- except NotImplementedError :
508- logger .error ("control_output is not implemented for this alarm type" )
509- except asyncio .CancelledError :
510- logger .error ("control_output canceled" )
511- except asyncio .TimeoutError :
512- logger .error ("control_output timeout" )
513- # Apply state changes
514-
515- # Refresh status
516- self .request_status_refresh () # Trigger status update
517-
518- return accepted
511+ if outputs_selected :
512+ accepted = False
513+ try :
514+ accepted = await self .panel .control_outputs (outputs_selected , command )
515+ except NotImplementedError :
516+ logger .error ("control_output is not implemented for this alarm type" )
517+ except asyncio .CancelledError :
518+ logger .error ("control_output canceled" )
519+ except asyncio .TimeoutError :
520+ logger .error ("control_output timeout" )
521+ self .request_status_refresh ()
522+ return accepted
523+
524+ module_pgm_selected = self .storage .get_container ("module_pgm" ).select (output )
525+ if module_pgm_selected :
526+ accepted = False
527+ module_pgm_container = self .storage .get_container ("module_pgm" )
528+ for key in module_pgm_selected :
529+ out = module_pgm_container [key ]
530+ try :
531+ accepted = await self .panel .control_module_pgm_outputs (
532+ out ["module_address" ], out ["pgm_index" ], command
533+ )
534+ except NotImplementedError :
535+ logger .error ("control_module_pgm_outputs is not implemented for this alarm type" )
536+ except asyncio .CancelledError :
537+ logger .error ("control_output canceled" )
538+ except asyncio .TimeoutError :
539+ logger .error ("control_output timeout" )
540+ if accepted :
541+ is_on = command in ("on" , "on_override" )
542+ self .storage .update_container_object ("module_pgm" , out ["key" ], {"on" : is_on })
543+ self .request_status_refresh ()
544+ return accepted
545+
546+ logger .error ("No outputs selected" )
547+ return False
519548
520549 async def send_panic (self , partition_id , panic_type , user_id ) -> bool :
521550 logger .debug (
0 commit comments