Skip to content

Commit

Permalink
Fix wrong filtering, amount of trays reported
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Sep 24, 2020
1 parent 4c9d97b commit 4dc9289
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
14 changes: 9 additions & 5 deletions pysyncthru/__init__.py
Expand Up @@ -148,15 +148,19 @@ def toner_status(self, filter_supported: bool = True) -> Dict[str, Any]:
def input_tray_status(self, filter_supported: bool = True) -> Dict[int, Any]:
"""Return the state of all input trays."""
tray_status = {}
for i in range(1, 5):
for tray in (
*("{}{}".format(SyncThru.TRAY, i) for i in range(1, 6)),
"mp",
"manual",
):
try:
tray_stat = self.data.get("{}{}".format(SyncThru.TRAY, i), {})
if filter_supported and tray_stat.get("opt", 0) == 0:
tray_stat = self.data.get(tray, {})
if filter_supported and tray_stat.get("opt", 0) != 1:
continue
else:
tray_status[i] = tray_stat
tray_status[tray] = tray_stat
except (KeyError, AttributeError):
tray_status[i] = {}
tray_status[tray] = {}
return tray_status

def output_tray_status(self) -> Dict[int, Dict[str, str]]:
Expand Down
37 changes: 32 additions & 5 deletions pysyncthru/tests/test_web.py
Expand Up @@ -92,7 +92,7 @@ def test_input_tray_filter(self):
self.assertEqual(
self.syncthru.input_tray_status(True),
{
1: {
"tray1": {
"capa": 150,
"newError": "",
"opt": 1,
Expand All @@ -108,7 +108,7 @@ def test_input_tray_no_filter(self):
self.assertEqual(
self.syncthru.input_tray_status(False),
{
1: {
"tray1": {
"capa": 150,
"newError": "",
"opt": 1,
Expand All @@ -117,7 +117,7 @@ def test_input_tray_no_filter(self):
"paper_type1": 2,
"paper_type2": 0,
},
2: {
"tray2": {
"capa": 0,
"newError": "",
"opt": 0,
Expand All @@ -126,7 +126,7 @@ def test_input_tray_no_filter(self):
"paper_type1": 2,
"paper_type2": 0,
},
3: {
"tray3": {
"capa": 0,
"newError": "",
"opt": 0,
Expand All @@ -135,7 +135,7 @@ def test_input_tray_no_filter(self):
"paper_type1": 2,
"paper_type2": 0,
},
4: {
"tray4": {
"capa": 0,
"newError": "",
"opt": 0,
Expand All @@ -144,6 +144,33 @@ def test_input_tray_no_filter(self):
"paper_type1": 2,
"paper_type2": 0,
},
"tray5": {
"opt": 0,
"paper_size1": 0,
"paper_size2": 0,
"paper_type1": 0,
"paper_type2": 0,
"capa": 0,
"newError": "0",
},
"mp": {
"opt": 0,
"paper_size1": 0,
"paper_size2": 0,
"paper_type1": 2,
"paper_type2": 0,
"capa": 0,
"newError": "",
},
"manual": {
"opt": 0,
"paper_size1": 0,
"paper_size2": 0,
"paper_type1": 2,
"paper_type2": 0,
"capa": 0,
"newError": "",
},
},
)

Expand Down

0 comments on commit 4dc9289

Please sign in to comment.