Skip to content

Commit

Permalink
Change status channel from hash map values to state description optio…
Browse files Browse the repository at this point in the history
…ns. (openhab#11739)

Signed-off-by: Stewart Cossey <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
  • Loading branch information
Cossey authored and andrasU committed Nov 12, 2022
1 parent 01bae20 commit 0893952
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public HPProductUsageFeatures(final Document document) {
final String inkName = currInk.getElementsByTagName("dd:MarkerColor").item(0).getTextContent();
final String consumeType = currInk.getElementsByTagName("dd:ConsumableTypeEnum").item(0).getTextContent();

if (consumeType.equalsIgnoreCase("printhead")) {
if ("printhead".equalsIgnoreCase(consumeType)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
package org.openhab.binding.hpprinter.internal.api;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.w3c.dom.Document;
Expand All @@ -30,8 +27,6 @@
public class HPStatus {
public static final String ENDPOINT = "/DevMgmt/ProductStatusDyn.xml";

private static final Map<String, String> STATUS_MESSAGES = initializeStatus();

private final String printerStatus;
private final boolean trayEmptyOrOpen;

Expand All @@ -44,7 +39,7 @@ public HPStatus(Document document) {
Element element = (Element) nodes.item(i);
String statusCategory = element.getElementsByTagName("pscat:StatusCategory").item(0).getTextContent();
if (!"genuineHP".equals(statusCategory) && !"trayEmpty".equals(statusCategory)) {
localPrinterStatus = STATUS_MESSAGES.getOrDefault(statusCategory, statusCategory);
localPrinterStatus = statusCategory;
}
if ("trayEmpty".equals(statusCategory)) {
localTrayEmptyOrOpen = true;
Expand All @@ -54,20 +49,6 @@ public HPStatus(Document document) {
printerStatus = localPrinterStatus;
}

private static Map<String, String> initializeStatus() {
Map<String, String> statusMap = new HashMap<>();

statusMap.put("processing", "Printing...");
statusMap.put("scanProcessing", "Scanning...");
statusMap.put("inPowerSave", "Power Save");
statusMap.put("ready", "Idle");
statusMap.put("initializing", "Initializing...");
statusMap.put("closeDoorOrCover", "Door/Cover Open");
statusMap.put("inkSystemInitializing", "Loading Ink...");
statusMap.put("shuttingDown", "Shutting Down...");
return statusMap;
}

public boolean getTrayEmptyOrOpen() {
return trayEmptyOrOpen;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@
<item-type>String</item-type>
<label>Status</label>
<description>Printer Status</description>
<state readOnly="true"/>
<state readOnly="true">
<options>
<option value="ready">Idle</option>
<option value="processing">Printing</option>
<option value="scanProcessing">Scanning</option>
<option value="inPowerSave">Power Save</option>
<option value="initializing">Initializing</option>
<option value="closeDoorOrCover">Door/Cover</option>
<option value="inkSystemInitializing">Loading Ink</option>
<option value="shuttingDown">Shutting Down</option>
<option value="replaceCartridgeOut">Cartridge Depleted</option>
</options>
</state>
</channel-type>

<channel-type id="readonlyswitch" advanced="true">
Expand Down

0 comments on commit 0893952

Please sign in to comment.