2424from pioreactor .pubsub import Client
2525from pioreactor .pubsub import create_client
2626from pioreactor .pubsub import QOS
27- from pioreactor .state import JobState as states
27+ from pioreactor .states import JobState as st
2828from pioreactor .utils import append_signal_handlers
2929from pioreactor .utils import get_running_pio_job_id
3030from pioreactor .utils import is_pio_job_running
@@ -115,7 +115,7 @@ class _BackgroundJob(metaclass=PostInitCaller):
115115 State management & hooks
116116 ---------------------------
117117
118- So this class controls most of the state convention that we follow (states inspired by Homie):
118+ So this class controls most of the state convention that we follow (st inspired by Homie):
119119
120120 ┌──────────┐
121121 │ │
@@ -139,7 +139,7 @@ class _BackgroundJob(metaclass=PostInitCaller):
139139
140140 https://asciiflow.com/#/share/eJzNVEsKgzAQvYrM2lW7Uc%2BSjehQAmksmoIi3qJ4kC7F0%2FQkTS0tRE0crYuGWWSEeZ95wRpkfEaI5FUIH0RcYQ4R1AxKBlEYhD6DSt8OwVHfFJZKNww8wnnc%2BsViTBKhjOYzRqHYXm2nKURWqBdT2xFsGDrnDYytzLsioEzVjr5sQ7b2GoOyNWOGWCbn2pzewizaR0bmyCab%2BAJyyRVJ0PBSvBzjtFphQE%2BlvEgyKTFRmBrU%2B3rZIzXL%2B3Kn1t4dqXn2M6Cafqbu%2FxxicYHUSBZpHC0VoBCIFy5PP%2F9TV%2Bgkb87BBg00T7Hk%2FaY%3D)
141141
142- states -mermaid-diagram
142+ st -mermaid-diagram
143143 init --> ready
144144 init --> lost
145145 ready --> lost
@@ -236,11 +236,11 @@ class _BackgroundJob(metaclass=PostInitCaller):
236236 """
237237
238238 # Homie lifecycle (normally per device (i.e. an rpi) but we are using it for "nodes", in Homie parlance)
239- INIT : pt .JobState = states .INIT
240- READY : pt .JobState = states .READY
241- DISCONNECTED : pt .JobState = states .DISCONNECTED
242- SLEEPING : pt .JobState = states .SLEEPING
243- LOST : pt .JobState = states .LOST
239+ INIT : pt .JobState = st .INIT
240+ READY : pt .JobState = st .READY
241+ DISCONNECTED : pt .JobState = st .DISCONNECTED
242+ SLEEPING : pt .JobState = st .SLEEPING
243+ LOST : pt .JobState = st .LOST
244244
245245 # initial state is disconnected, set other metadata
246246 state = DISCONNECTED
@@ -318,7 +318,7 @@ def __init__(self, unit: pt.Unit, experiment: pt.Experiment, source: str = "app"
318318 }
319319
320320 # this comes _after_ adding state to published settings
321- self .set_state (states .INIT )
321+ self .set_state (st .INIT )
322322
323323 self ._set_up_exit_protocol ()
324324 self ._blocking_event = threading .Event ()
@@ -358,7 +358,7 @@ def __post__init__(self) -> None:
358358 """
359359 # setting READY should happen after we write to the job manager, since a job might do a long-running
360360 # task in on_ready, which delays writing to the db, which means `pio kill` might not see it.
361- self .set_state (states .READY )
361+ self .set_state (st .READY )
362362
363363 @property
364364 def job_key (self ):
@@ -488,7 +488,7 @@ def _callback(client, userdata, message: pt.MQTTMessage) -> t.Optional[T]:
488488
489489 def set_state (self , new_state : pt .JobState ) -> None :
490490 """
491- The preferred way to change states is to use this function (instead of self.state = state). Note:
491+ The preferred way to change st is to use this function (instead of self.state = state). Note:
492492
493493 - no-op if in the same state
494494 - will call the transition callback
@@ -551,8 +551,8 @@ def clean_up(self) -> None:
551551 """
552552 Disconnect from brokers, set state to "disconnected", stop any activity.
553553 """
554- if self .state is not states .DISCONNECTED :
555- self .set_state (states .DISCONNECTED )
554+ if self .state is not st .DISCONNECTED :
555+ self .set_state (st .DISCONNECTED )
556556 self ._clean_up_resources ()
557557
558558 def add_to_published_settings (self , setting : str , props : pt .PublishableSetting ) -> None :
@@ -745,7 +745,7 @@ def exit_gracefully(reason: int | str, *args) -> None:
745745 pass
746746
747747 def init (self ) -> None :
748- self .state = states .INIT
748+ self .state = st .INIT
749749
750750 try :
751751 # we delay the specific on_init until after we have done our important protocols.
@@ -759,7 +759,7 @@ def init(self) -> None:
759759 self ._log_state (self .state )
760760
761761 def ready (self ) -> None :
762- self .state = states .READY
762+ self .state = st .READY
763763
764764 try :
765765 self .on_ready ()
@@ -771,7 +771,7 @@ def ready(self) -> None:
771771 self ._log_state (self .state )
772772
773773 def sleeping (self ) -> None :
774- self .state = states .SLEEPING
774+ self .state = st .SLEEPING
775775
776776 try :
777777 self .on_sleeping ()
@@ -788,7 +788,7 @@ def lost(self) -> None:
788788 # 1. Monitor can send a lost signal if `check_against_processes_running` triggers.
789789 # I think it makes sense to ignore it?
790790
791- self .state = states .LOST
791+ self .state = st .LOST
792792 self ._log_state (self .state )
793793
794794 def disconnected (self ) -> None :
@@ -805,7 +805,7 @@ def disconnected(self) -> None:
805805 self .logger .debug ("Error in on_disconnected:" )
806806 self .logger .debug (e , exc_info = True )
807807
808- self .state = states .DISCONNECTED
808+ self .state = st .DISCONNECTED
809809 self ._log_state (self .state )
810810
811811 # we "set" the internal event, which will cause any event.waits to end blocking. This should happen last.
@@ -863,7 +863,7 @@ def _publish_defined_settings_to_broker(
863863 self ._publish_setting (name )
864864
865865 def _log_state (self , state : pt .JobState ) -> None :
866- if state in {states .READY , states .DISCONNECTED , states .LOST }:
866+ if state in {st .READY , st .DISCONNECTED , st .LOST }:
867867 self .logger .info (state .capitalize () + "." )
868868 else :
869869 self .logger .debug (state .capitalize () + "." )
@@ -1167,9 +1167,9 @@ def _desired_dodging_mode(self, enable_dodging_od: bool, od_state: pt.JobState |
11671167 # enable_dodging_od is true - user wants it on
11681168 if od_state is None :
11691169 return False
1170- if od_state in {states .READY , states .SLEEPING , states .INIT }:
1170+ if od_state in {st .READY , st .SLEEPING , st .INIT }:
11711171 return True
1172- if od_state in {states .LOST , states .DISCONNECTED }:
1172+ if od_state in {st .LOST , st .DISCONNECTED }:
11731173 return False
11741174 return False
11751175
@@ -1207,7 +1207,7 @@ def set_currently_dodging_od(self, value: bool):
12071207 def set_enable_dodging_od (self , value : bool ):
12081208 """Turn dodging on/off based on user intent, then align mode with current OD state."""
12091209 self .enable_dodging_od = value
1210- od_state = states .READY if is_pio_job_running ("od_reading" ) else states .DISCONNECTED
1210+ od_state = st .READY if is_pio_job_running ("od_reading" ) else st .DISCONNECTED
12111211
12121212 desired = self ._desired_dodging_mode (self .enable_dodging_od , od_state )
12131213 self .set_currently_dodging_od (desired )
0 commit comments