printobserver-server 0.15.5

The printobserver server.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
//! A machine these journeys stand in for, and the state it holds.
//!
//! The layer under test here is the server: its API, the policy it puts every
//! action through, its record and its ingress. The printer is the external
//! system on the far side of a port, and this is what stands in for one — it
//! holds the state a printer holds, moves that state when an action reaches it,
//! and remembers what it was asked, so a journey can assert an operation's own
//! effect rather than its status code.
//!
//! It holds the files a printer holds too — each with the analysis `OctoPrint`
//! makes of it and the tally of how often it was printed — and answers how far
//! a file's own moves fed each tool up to a byte of it, so a journey can tell
//! the story the filament ledger is charged from: a file printed while nothing
//! was watching, a tally reset by a re-upload, a print cancelled part-way.
//!
//! It is not a substitute for the real thing. What proves the same operations
//! against a real `OctoPrint` is this crate's integration tier, which runs
//! against the instance `just octoprint-up` starts; the two tiers walk the same
//! declared operation list.

use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;

/// How long a job read waits for the others it was told to meet before going
/// on alone.
const PATIENCE: Duration = Duration::from_millis(400);

use printobserver_printer_api::{Adjustable, PrinterState};
use printobserver_printer_api::{
    BoxFuture, FileFacts, FilePrint, HeaterSnapshot, JobSnapshot, PrinterError, PrinterPort,
    PrinterSnapshot, ToolFilament,
};
use printobserver_types::{FileName, Reported, Timestamp};

/// One thing the machine was asked to do.
#[derive(Debug, Clone, PartialEq)]
pub enum Call {
    /// Pause the print.
    Pause,
    /// Resume the print.
    Resume,
    /// Cancel the print.
    Cancel,
    /// Start a print of a named file.
    Start(FileName),
    /// Set the feedrate factor.
    Feedrate(f64),
    /// Set the flowrate factor.
    Flowrate(f64),
    /// Set one tool's target temperature.
    ToolTarget(i64, f64),
    /// Set the bed's target temperature.
    BedTarget(f64),
    /// Set the fan percentage.
    Fan(f64),
}

/// What the machine holds, and what it has been asked.
#[derive(Debug)]
struct Held {
    /// The printer's own state.
    snapshot: PrinterSnapshot,
    /// The job it reports it is running.
    job: JobSnapshot,
    /// Everything it has been asked, in order.
    calls: Vec<Call>,
    /// Whether it answers no read at all, as a machine switched off does.
    unreadable: bool,
    /// The files it holds, with their analysis and their print tallies.
    files: Vec<FileFacts>,
    /// The G-code of each file a whole-file read streams, by name.
    gcode: Vec<(String, Vec<u8>)>,
    /// How many whole-file reads were asked of each file, by name.
    gcode_reads: Vec<String>,
}

/// A printer these journeys drive the server against.
#[derive(Debug)]
pub struct RecordingPrinter {
    /// What it holds.
    held: Mutex<Held>,
    /// How many job reads are to wait for one another, and how many have come.
    meeting: Mutex<(usize, usize)>,
    /// Signalled whenever a job read arrives.
    arrived: Condvar,
    /// How long a start takes to answer, after which the machine reports the
    /// job it names running, as `OctoPrint` does by the time its start answers;
    /// absent, a start answers at once and the job is the journey's to run.
    starting: Mutex<Option<Duration>>,
}

/// One feedrate factor, flagged against the range the contracts declare for it.
fn feedrate(value: f64) -> Reported<f64> {
    Reported::new(value, printobserver_printer_api::FEEDRATE_FACTOR_RANGE)
}

impl RecordingPrinter {
    /// A printer part-way through a print, at the values a print starts at.
    #[must_use]
    pub fn printing() -> Arc<Self> {
        Arc::new(Self {
            held: Mutex::new(Held {
                snapshot: PrinterSnapshot {
                    connection: PrinterState::Printing,
                    tools: vec![HeaterSnapshot {
                        actual_c: Some(Reported::new(
                            215.0,
                            printobserver_printer_api::HEATER_ACTUAL_C_RANGE,
                        )),
                        target_c: Some(Reported::new(
                            215.0,
                            printobserver_printer_api::HEATER_TARGET_C_RANGE,
                        )),
                        offset_c: None,
                    }],
                    bed: Some(HeaterSnapshot {
                        actual_c: Some(Reported::new(
                            60.0,
                            printobserver_printer_api::HEATER_ACTUAL_C_RANGE,
                        )),
                        target_c: Some(Reported::new(
                            60.0,
                            printobserver_printer_api::HEATER_TARGET_C_RANGE,
                        )),
                        offset_c: None,
                    }),
                    chamber: None,
                    feedrate_factor: Some(feedrate(1.0)),
                    flowrate_factor: Some(Reported::new(
                        1.0,
                        printobserver_printer_api::FLOWRATE_FACTOR_RANGE,
                    )),
                    fan_percent: Some(Reported::new(
                        40.0,
                        printobserver_printer_api::FAN_PERCENT_RANGE,
                    )),
                    observed_at: Timestamp::now(),
                },
                job: JobSnapshot {
                    file_name: Some("benchy.gcode".to_owned()),
                    file_origin: Some("local".to_owned()),
                    size_bytes: Some(4096),
                    estimated_print_time_s: Some(3600),
                    completion: Some(Reported::new(
                        0.25,
                        printobserver_printer_api::COMPLETION_RANGE,
                    )),
                    print_time_s: Some(900),
                    print_time_left_s: Some(2700),
                    state: PrinterState::Printing,
                    error: None,
                    file_position_bytes: None,
                    filament: Vec::new(),
                },
                calls: Vec::new(),
                unreadable: false,
                files: Vec::new(),
                gcode: Vec::new(),
                gcode_reads: Vec::new(),
            }),
            meeting: Mutex::new((0, 0)),
            arrived: Condvar::new(),
            starting: Mutex::new(None),
        })
    }

    /// Make this many job reads wait for one another before any answers.
    ///
    /// Two callers nothing keeps apart are made to overlap at the read, and two
    /// that something does keep apart each wait a moment alone and go on.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn job_reads_meet(&self, callers: usize) {
        *self.meeting.lock().expect("the meeting is not poisoned") = (callers, 0);
    }

    /// Arrive at the job read's meeting, and wait for the others when one is set.
    fn meet(&self) {
        let mut counts = self.meeting.lock().expect("the meeting is not poisoned");
        if counts.0 == 0 {
            return;
        }
        counts.1 += 1;
        self.arrived.notify_all();
        let _ = self
            .arrived
            .wait_timeout_while(counts, PATIENCE, |(wanted, came)| *came < *wanted)
            .expect("the meeting is not poisoned");
    }

    /// Take `delay` to answer every start, and run the job it names once it has.
    ///
    /// What a journey about a read made while a start is in flight needs: the
    /// machine is idle until the start answers and running the job after.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn starts_jobs_after(&self, delay: Duration) {
        *self.starting.lock().expect("the start is not poisoned") = Some(delay);
    }

    /// A switched-off machine: while set, both its snapshot and its job are
    /// refused as unreachable, which is how a listing is shown to answer anyway.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn unreadable(&self, unreadable: bool) {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .unreadable = unreadable;
    }

    /// The refusal a machine nothing can read answers, when it is one.
    fn unread(&self) -> Option<PrinterError> {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .unreadable
            .then(|| PrinterError::Unreachable {
                detail: "the machine is switched off".to_owned(),
            })
    }

    /// Hold one file, `size_bytes` long, whose analysis says each tool feeds
    /// `filament` — or, given none, that has no analysis yet — replacing any
    /// file of that name, tally and all, as a re-upload does.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn holds_file(&self, name: &str, size_bytes: i64, filament: Option<Vec<ToolFilament>>) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.files.retain(|file| file.file_name != name);
        held.files.push(FileFacts {
            file_name: name.to_owned(),
            origin: "local".to_owned(),
            size_bytes: Some(size_bytes),
            filament,
            successes: 0,
            failures: 0,
            last_print: None,
        });
    }

    /// Count one finished print of a held file in its tally, at `at`.
    ///
    /// # Panics
    ///
    /// Panics when it holds no such file.
    pub fn counts_print(&self, name: &str, success: bool, at: Timestamp) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        let file = held
            .files
            .iter_mut()
            .find(|file| file.file_name == name)
            .unwrap_or_else(|| panic!("the machine holds no `{name}`"));
        if success {
            file.successes += 1;
        } else {
            file.failures += 1;
        }
        file.last_print = Some(FilePrint { at, success });
    }

    /// Hold one file's G-code, which a whole-file read streams in 64 KiB
    /// pieces as the `OctoPrint` adapter's download does, and report it as the
    /// job's file and its size.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn holds_gcode(&self, name: &str, bytes: &[u8]) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.gcode.retain(|(held_name, _)| held_name != name);
        held.gcode.push((name.to_owned(), bytes.to_vec()));
        held.job.file_name = Some(name.to_owned());
        held.job.size_bytes = i64::try_from(bytes.len()).ok();
    }

    /// How many whole-file reads one file was asked for.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    #[must_use]
    pub fn gcode_reads(&self, name: &str) -> usize {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .gcode_reads
            .iter()
            .filter(|read| read.as_str() == name)
            .count()
    }

    /// Report the job at this byte of its file, as a print part-way through
    /// it does.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn at_byte(&self, position_bytes: i64) {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .job
            .file_position_bytes = Some(position_bytes);
    }

    /// Report the job read to its file's end with its completion at 1.0, as
    /// `OctoPrint` reports a print it finished.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn reports_finished(&self) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.job.file_position_bytes = held.job.size_bytes;
        held.job.completion = Some(Reported::new(
            1.0,
            printobserver_printer_api::COMPLETION_RANGE,
        ));
    }

    /// Report the job with no position in its file, as a job read taken while
    /// the printer is busy with a filament change can.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn reports_no_position(&self) {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .job
            .file_position_bytes = None;
    }

    /// Everything it has been asked, in order.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    #[must_use]
    pub fn calls(&self) -> Vec<Call> {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .calls
            .clone()
    }

    /// Forget what it has been asked, so a journey's next step starts clean.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn forget(&self) {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .calls
            .clear();
    }

    /// The state it holds now.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    #[must_use]
    pub fn snapshot(&self) -> PrinterSnapshot {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .snapshot
            .clone()
    }

    /// Put it in one state, which is what a journey about a state conflict needs.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn in_state(&self, state: PrinterState) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.snapshot.connection = state.clone();
        held.job.state = state;
    }

    /// Report `state` as the printer's own while its job goes on reporting
    /// what it did, as a firmware that faulted under a host still reporting
    /// the job does.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn reports_connection(&self, state: PrinterState) {
        self.held
            .lock()
            .expect("the machine is not poisoned")
            .snapshot
            .connection = state;
    }

    /// Run `file` in `state`, reporting `print_time_s` as its running time.
    ///
    /// The running time is what tells one job of a file from another, so this
    /// is how a journey stands a later job, a pause or a resume up.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn runs_job(&self, file: &str, state: PrinterState, print_time_s: Option<i64>) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.snapshot.connection = state.clone();
        held.job.file_name = Some(file.to_owned());
        held.job.state = state;
        held.job.print_time_s = print_time_s;
    }

    /// Make it report a value JSON denotes no spelling of.
    ///
    /// A disconnected thermistor and a division by a zero-valued reading both
    /// produce one, and the contracts refuse to emit one rather than writing
    /// `null` for it — so this is what a machine having that kind of bad day
    /// looks like from here.
    ///
    /// # Panics
    ///
    /// Panics when a thread panicked while it held the machine's state.
    pub fn reporting_nothing_denotable(&self) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        held.snapshot.feedrate_factor = Some(feedrate(f64::NAN));
    }

    /// What one adjustable reads as now, when the machine reports it.
    #[must_use]
    pub fn value_of(&self, adjustable: Adjustable) -> Option<f64> {
        let snapshot = self.snapshot();
        let reported = match adjustable {
            Adjustable::Feedrate => snapshot.feedrate_factor,
            Adjustable::Flowrate => snapshot.flowrate_factor,
            Adjustable::Fan => snapshot.fan_percent,
            Adjustable::BedTarget => snapshot.bed.as_ref().and_then(|heater| heater.target_c),
            Adjustable::ToolTarget { tool } => usize::try_from(tool)
                .ok()
                .and_then(|index| snapshot.tools.get(index))
                .and_then(|heater| heater.target_c),
        };
        reported.map(|value| value.value())
    }

    /// Record one call, and move what it changes.
    fn took(&self, call: Call) {
        let mut held = self.held.lock().expect("the machine is not poisoned");
        match &call {
            Call::Pause => held.snapshot.connection = PrinterState::Paused,
            Call::Resume => held.snapshot.connection = PrinterState::Printing,
            Call::Cancel => held.snapshot.connection = PrinterState::Cancelling,
            Call::Start(name) => {
                held.snapshot.connection = PrinterState::Printing;
                held.job.file_name = Some(name.as_str().to_owned());
            }
            Call::Feedrate(factor) => {
                held.snapshot.feedrate_factor = Some(Reported::new(
                    *factor,
                    printobserver_printer_api::FEEDRATE_FACTOR_RANGE,
                ));
            }
            Call::Flowrate(factor) => {
                held.snapshot.flowrate_factor = Some(Reported::new(
                    *factor,
                    printobserver_printer_api::FLOWRATE_FACTOR_RANGE,
                ));
            }
            Call::ToolTarget(tool, target) => {
                if let Some(heater) = usize::try_from(*tool)
                    .ok()
                    .and_then(|index| held.snapshot.tools.get_mut(index))
                {
                    heater.target_c = Some(Reported::new(
                        *target,
                        printobserver_printer_api::HEATER_TARGET_C_RANGE,
                    ));
                }
            }
            Call::BedTarget(target) => {
                if let Some(bed) = held.snapshot.bed.as_mut() {
                    bed.target_c = Some(Reported::new(
                        *target,
                        printobserver_printer_api::HEATER_TARGET_C_RANGE,
                    ));
                }
            }
            Call::Fan(percent) => {
                held.snapshot.fan_percent = Some(Reported::new(
                    *percent,
                    printobserver_printer_api::FAN_PERCENT_RANGE,
                ));
            }
        }
        held.calls.push(call);
    }
}

impl PrinterPort for RecordingPrinter {
    fn read_gcode<'a>(
        &'a self,
        file_name: FileName,
        sink: &'a mut dyn printobserver_printer_api::GcodeSink,
    ) -> BoxFuture<'a, Result<(), PrinterError>> {
        let bytes = {
            let mut held = self.held.lock().expect("the machine is not poisoned");
            held.gcode_reads.push(file_name.as_str().to_owned());
            held.gcode
                .iter()
                .find(|(name, _)| name == file_name.as_str())
                .map(|(_, bytes)| bytes.clone())
        };
        Box::pin(async move {
            let bytes = bytes.ok_or_else(|| PrinterError::Refused {
                status: 404,
                detail: format!("no file {file_name}"),
            })?;
            for piece in bytes.chunks(1 << 16) {
                if sink.take(piece).is_break() {
                    break;
                }
            }
            Ok(())
        })
    }

    fn snapshot(&self) -> BoxFuture<'_, Result<PrinterSnapshot, PrinterError>> {
        let taken = self.unread().map_or_else(|| Ok(Self::snapshot(self)), Err);
        Box::pin(async move { taken })
    }

    fn job(&self) -> BoxFuture<'_, Result<JobSnapshot, PrinterError>> {
        self.meet();
        let job = self.unread().map_or_else(
            || {
                Ok(self
                    .held
                    .lock()
                    .expect("the machine is not poisoned")
                    .job
                    .clone())
            },
            Err,
        );
        Box::pin(async move { job })
    }

    fn file_facts(&self, file_name: FileName) -> BoxFuture<'_, Result<FileFacts, PrinterError>> {
        let found = self.unread().map_or_else(
            || {
                self.held
                    .lock()
                    .expect("the machine is not poisoned")
                    .files
                    .iter()
                    .find(|file| file.file_name == file_name.as_str())
                    .cloned()
                    .ok_or_else(|| PrinterError::Refused {
                        status: 404,
                        detail: format!("there is no file {file_name}"),
                    })
            },
            Err,
        );
        Box::pin(async move { found })
    }

    fn printed_files(&self) -> BoxFuture<'_, Result<Vec<FileFacts>, PrinterError>> {
        let files = self.unread().map_or_else(
            || {
                Ok(self
                    .held
                    .lock()
                    .expect("the machine is not poisoned")
                    .files
                    .clone())
            },
            Err,
        );
        Box::pin(async move { files })
    }

    /// The file's analysed feed, in proportion to how far into its bytes the
    /// position is: a file whose moves are spread evenly through it.
    fn extruded_to(
        &self,
        file_name: FileName,
        position_bytes: i64,
    ) -> BoxFuture<'_, Result<Vec<ToolFilament>, PrinterError>> {
        let fed = self.unread().map_or_else(
            || {
                let held = self.held.lock().expect("the machine is not poisoned");
                let file = held
                    .files
                    .iter()
                    .find(|file| file.file_name == file_name.as_str())
                    .ok_or_else(|| PrinterError::Refused {
                        status: 404,
                        detail: format!("there is no file {file_name}"),
                    })?;
                // A test file is far shorter than a `u32` counts, so the
                // conversions lose nothing.
                let size = file.size_bytes.unwrap_or(1).max(1);
                let bytes = |count: i64| f64::from(u32::try_from(count).unwrap_or(u32::MAX));
                let fraction = bytes(position_bytes.clamp(0, size)) / bytes(size);
                Ok(file
                    .filament
                    .clone()
                    .unwrap_or_default()
                    .into_iter()
                    .map(|tool| ToolFilament {
                        length_mm: tool.length_mm * fraction,
                        volume_cm3: None,
                        ..tool
                    })
                    .collect())
            },
            Err,
        );
        Box::pin(async move { fed })
    }

    fn start(&self, file_name: FileName) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Start(file_name.clone()));
        let delay = *self.starting.lock().expect("the start is not poisoned");
        Box::pin(async move {
            if let Some(delay) = delay {
                tokio::time::sleep(delay).await;
                self.runs_job(file_name.as_str(), PrinterState::Printing, Some(0));
            }
            Ok(())
        })
    }

    fn pause(&self) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Pause);
        Box::pin(async move { Ok(()) })
    }

    fn resume(&self) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Resume);
        Box::pin(async move { Ok(()) })
    }

    fn cancel(&self) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Cancel);
        Box::pin(async move { Ok(()) })
    }

    fn set_feedrate_factor(&self, factor: f64) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Feedrate(factor));
        Box::pin(async move { Ok(()) })
    }

    fn set_flowrate_factor(&self, factor: f64) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Flowrate(factor));
        Box::pin(async move { Ok(()) })
    }

    fn set_tool_target_c(
        &self,
        tool: i64,
        target_c: f64,
    ) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::ToolTarget(tool, target_c));
        Box::pin(async move { Ok(()) })
    }

    fn set_bed_target_c(&self, target_c: f64) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::BedTarget(target_c));
        Box::pin(async move { Ok(()) })
    }

    fn set_fan_percent(&self, percent: f64) -> BoxFuture<'_, Result<(), PrinterError>> {
        self.took(Call::Fan(percent));
        Box::pin(async move { Ok(()) })
    }
}