]> git.basschouten.com Git - openhab-addons.git/blob
70332b87a59e90e2b909d46cddb9348266fc6510
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hpprinter.internal.api;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19 import org.w3c.dom.NodeList;
20
21 /**
22  * The {@link HPStatus} is responsible for handling reading of status data.
23  *
24  * @author Stewart Cossey - Initial contribution
25  */
26 @NonNullByDefault
27 public class HPStatus {
28     public static final String ENDPOINT = "/DevMgmt/ProductStatusDyn.xml";
29
30     private final String printerStatus;
31     private final boolean trayEmptyOrOpen;
32
33     public HPStatus(Document document) {
34         NodeList nodes = document.getDocumentElement().getElementsByTagName("psdyn:Status");
35
36         String localPrinterStatus = "Unknown";
37         boolean localTrayEmptyOrOpen = false;
38         for (int i = 0; i < nodes.getLength(); i++) {
39             Element element = (Element) nodes.item(i);
40             String statusCategory = element.getElementsByTagName("pscat:StatusCategory").item(0).getTextContent();
41             if (!"genuineHP".equals(statusCategory) && !"trayEmpty".equals(statusCategory)) {
42                 localPrinterStatus = statusCategory;
43             }
44             if ("trayEmpty".equals(statusCategory)) {
45                 localTrayEmptyOrOpen = true;
46             }
47         }
48         trayEmptyOrOpen = localTrayEmptyOrOpen;
49         printerStatus = localPrinterStatus;
50     }
51
52     public boolean getTrayEmptyOrOpen() {
53         return trayEmptyOrOpen;
54     }
55
56     public @Nullable String getPrinterStatus() {
57         return printerStatus;
58     }
59 }