def _run(self): self.average_od = self.measure_initial_od_average() od_variant = 'od_1' if self.od_channel == 1 else 'od_0' while self.is_active: commands = [] for _name, _command in self.commands_to_execute.items(): command = Command(self.device_id, _command.get("id"), _command.get("args", []), self.task_id, is_awaited=True) commands.append((_name, command)) self.device.post_command(command, 1) for name, command in commands: command.await_cmd() if command.is_valid and name == od_variant: od = command.response['od'] self.latest_values.appendleft(od) od_is_outlier = self.handle_outlier(od) if not od_is_outlier: self.od.value = od command.response = { 'od': od, 'outlier': od_is_outlier, 'channel': self.od_channel } command.save_data_to_db() sleep(self.sleep_period)
def _execute_command(self, command: Command): try: validity = True response = self.get_command_reference( command.command_id)(*command.args) except Exception as e: validity = False response = e Log.error(e) command.response = response command.is_valid = validity command.executed_on = (self.device_class, self.device_id) command.resolve() return command