def __init__(self) -> None: """Initializes coordinator.""" # Initialize parent class super().__init__() # Initialize logger self.logger = Logger("Coordinator", "coordinator") self.logger.debug("Initializing coordinator") # Initialize state self.state = State() # Initialize environment state dict, TODO: remove this self.state.environment = { "sensor": {"desired": {}, "reported": {}}, "actuator": {"desired": {}, "reported": {}}, "reported_sensor_stats": { "individual": {"instantaneous": {}, "average": {}}, "group": {"instantaneous": {}, "average": {}}, }, } # Initialize recipe state dict, TODO: remove this self.state.recipe = { "recipe_uuid": None, "start_timestamp_minutes": None, "last_update_minute": None, } # Initialize managers self.recipe = RecipeManager(self.state) self.iot = IotManager(self.state, self.recipe) # type: ignore self.resource = ResourceManager(self.state, self.iot) # type: ignore self.network = NetworkManager(self.state) # type: ignore self.upgrade = UpgradeManager(self.state) # type: ignore # Initialize state machine transitions self.transitions = { modes.INIT: [modes.CONFIG, modes.ERROR, modes.SHUTDOWN], modes.CONFIG: [modes.SETUP, modes.ERROR, modes.SHUTDOWN], modes.SETUP: [modes.NORMAL, modes.ERROR, modes.SHUTDOWN], modes.NORMAL: [modes.LOAD, modes.ERROR, modes.SHUTDOWN], modes.LOAD: [modes.CONFIG, modes.ERROR, modes.SHUTDOWN], modes.RESET: [modes.INIT, modes.SHUTDOWN], modes.ERROR: [modes.RESET, modes.SHUTDOWN], } # Initialize state machine mode self.mode = modes.INIT
def __init__(self): """Initializes coordinator.""" self.logger.debug("Initializing coordinator") # Initialize mode and error self.mode = Modes.INIT # Initialize latest publish timestamp self.latest_publish_timestamp = 0 # Initialize state machine transitions self.transitions = Transitions(self, TRANSITION_TABLE) # Initialize coordinator event handler self.events = CoordinatorEvents(self) # Initialize managers self.iot = IoTManager(self.state, self.recipe) self.resource = ResourceManager(self.state, self, self.iot) self.connect = ConnectManager(self.state, self.iot) self.upgrade = UpgradeManager(self.state)
def test_init() -> None: state = State() manager = ResourceManager(state, IotManager(state, RecipeManager(state)))