Skip to content

Commit

Permalink
anyStateReasonContains()
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Dec 13, 2024
1 parent 27c4d93 commit ddcf1a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,20 @@ class IppPrinter(
fun isStopped(updateStateAttributes: Boolean = false) = stateIs(updateStateAttributes, Stopped)
fun isProcessing(updateStateAttributes: Boolean = false) = stateIs(updateStateAttributes, Processing)

fun isPaused() = stateReasons.contains("paused")
fun isOffline() = stateReasons.contains("offline-report") // reported by CUPS
fun isTonerLow() = stateReasons.contains("toner-low")
fun isTonerEmpty() = stateReasons.any { it.contains("toner-empty") } // toner-empty-error
fun isMediaJam() = stateReasons.contains("media-jam")
fun isMediaLow() = stateReasons.contains("media-low")
fun isMediaEmpty() = stateReasons.any { it.contains("media-empty") } // media-empty-report
fun isMediaNeeded() = stateReasons.contains("media-needed")
internal fun anyStateReasonContains(reason: String) =
stateReasons.any { it.contains(reason) } // support "...-error" and "...-report" values

fun isPaused() = anyStateReasonContains("paused")
fun isOffline() = anyStateReasonContains("offline")
fun isTonerLow() = anyStateReasonContains("toner-low")
fun isTonerEmpty() = anyStateReasonContains("toner-empty")
fun isMediaJam() = anyStateReasonContains("media-jam")
fun isMediaLow() = anyStateReasonContains("media-low")
fun isMediaEmpty() = anyStateReasonContains("media-empty")
fun isMediaNeeded() = anyStateReasonContains("media-needed")

fun isDuplexSupported() = sidesSupported.any { it.startsWith("two-sided") }
fun supportsOperations(vararg operations: IppOperation) = operationsSupported.containsAll(operations.toList())
fun isDuplexSupported() = sidesSupported.any { it.startsWith("two-sided") }
fun supportsVersion(version: String) = versionsSupported.contains(version)
fun isCups() = attributes.contains("cups-version")

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/de/gmuth/ipp/client/IppPrinterTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import de.gmuth.ipp.attributes.TemplateAttributes.jobName
import de.gmuth.ipp.attributes.TemplateAttributes.jobPriority
import de.gmuth.ipp.attributes.TemplateAttributes.numberUp
import de.gmuth.ipp.attributes.TemplateAttributes.orientationRequested
import de.gmuth.ipp.attributes.TemplateAttributes.outputBin
import de.gmuth.ipp.attributes.TemplateAttributes.pageRanges
import de.gmuth.ipp.attributes.TemplateAttributes.printerResolution
import de.gmuth.ipp.client.WhichJobs.Completed
Expand Down Expand Up @@ -118,6 +119,7 @@ class IppPrinterTests {
jobPriority(30),
copies(1),
numberUp(1),
outputBin("tray-2"),
pageRanges(1..5),
printerResolution(600),
orientationRequested(Portrait),
Expand Down

0 comments on commit ddcf1a1

Please sign in to comment.