Esempio n. 1
0
    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)
Esempio n. 2
0
    def get_od_for_init(self):
        cmd = Command(self.device_id,
                      "5", [self.od_channel],
                      self.task_id,
                      is_awaited=True)

        self.device.post_command(cmd)
        cmd.await_cmd()
        if cmd.is_valid:
            return cmd.response