Commit 632616b0 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

handle weird printer status values

parent 54eed391
......@@ -153,9 +153,9 @@ class PrinterStatus {
return _percentageToLevel(tonerK);
}
final toners = [tonerC, tonerM, tonerM, tonerK]..sort((a, b) => a.compareTo(b));
final toners = [tonerC, tonerM, tonerM, tonerK]..sort((a, b) => (a ?? 0).compareTo(b ?? 0));
return _percentageToLevel(toners.first);
return _percentageToLevel(toners.first ?? 0);
}
int get totalPaper => (tray1 ?? 0) + (tray2 ?? 0) + (tray3 ?? 0);
......@@ -165,7 +165,7 @@ class PrinterStatus {
Level _percentageToLevel(int percentage) {
if (percentage >= 90) return Level.full;
if (percentage >= 20) return Level.mid;
if (percentage >= 25) return Level.mid;
if (percentage > 0) return Level.low;
return Level.empty;
}
......
......@@ -310,30 +310,34 @@ class PrintersBloc extends Bloc<PrintersEvent, PrintersState> {
if (printer.status != null) {
if (printer.status.tonerC > 100 || printer.status.tonerC < 0) {
printer.status.tonerC = null;
printer.status.tonerC = printer.status.tonerC.abs();
}
if (printer.status.tonerM > 100 || printer.status.tonerM < 0) {
printer.status.tonerM = null;
printer.status.tonerM = printer.status.tonerM.abs();
}
if (printer.status.tonerY > 100 || printer.status.tonerY < 0) {
printer.status.tonerY = null;
printer.status.tonerY = printer.status.tonerY.abs();
}
if (printer.status.tonerK > 100 || printer.status.tonerK < 0) {
printer.status.tonerK = null;
printer.status.tonerK = printer.status.tonerK.abs();
}
if (printer.status.tray1 < 0) {
printer.status.tray1 = null;
printer.status.tray1 = 0;
}
if (printer.status.tray2 < 0) {
printer.status.tray2 = null;
printer.status.tray2 = 0;
}
if (printer.status.tray3 < 0) {
printer.status.tray3 = null;
printer.status.tray3 = 0;
}
}
if (printer.status == null) {
printer.status = PrinterStatus(connection: ConnectionStatus.disconnected);
if (_printers[index].status != null) {
printer.status = _printers[index].status..connection = ConnectionStatus.disconnected;
} else {
printer.status = PrinterStatus(connection: ConnectionStatus.disconnected);
}
} else {
printer.status.connection = ConnectionStatus.connected;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment