Bladeren bron

Fix an exception when no capabilities are read

The intended behavior for Sink.get_source_cap() when no
Source_Capabilities are read was to return an empty list.  This wasn't
done before, instead raising a ValueError when read_pdo() tried to parse
"No Source_Capabilities" as an UnknownPDO.  Now we're a bit more
cautious, and the bug is fixed.
Clara Hobbs 7 jaren geleden
bovenliggende
commit
f715d5db9e
3 gewijzigde bestanden met toevoegingen van 9 en 2 verwijderingen
  1. 5
    1
      pdbuddy/__init__.py
  2. 1
    1
      setup.py
  3. 3
    0
      test_pdbuddy/__init__.py

+ 5
- 1
pdbuddy/__init__.py Bestand weergeven

@@ -427,6 +427,8 @@ def read_pdo(text):
427 427
                 peak_i=peak_i,
428 428
                 v=v,
429 429
                 i=i)
430
+    elif pdo_type == "No Source_Capabilities":
431
+        return None
430 432
     else:
431 433
         # Make an UnknownPDO
432 434
         return UnknownPDO(value=int(pdo_type, 16))
@@ -445,6 +447,8 @@ def read_pdo_list(text):
445 447
     # Read the PDOs
446 448
     pdo_list = []
447 449
     for start, end in zip(pdo_start_list[:-1], pdo_start_list[1:]):
448
-        pdo_list.append(read_pdo(text[start:end]))
450
+        pdo = read_pdo(text[start:end])
451
+        if pdo is not None:
452
+            pdo_list.append(pdo)
449 453
 
450 454
     return pdo_list

+ 1
- 1
setup.py Bestand weergeven

@@ -5,7 +5,7 @@ with open("README.rst") as file:
5 5
 
6 6
 setup(
7 7
     name = "pd-buddy-python",
8
-    version = "0.3.0",
8
+    version = "0.3.1",
9 9
     author = "Clayton G. Hobbs",
10 10
     author_email = "clay@lakeserv.net",
11 11
     description = ("Python library for configuring PD Buddy Sink devices"),

+ 3
- 0
test_pdbuddy/__init__.py Bestand weergeven

@@ -133,6 +133,9 @@ class SinkTestCase(unittest.TestCase):
133 133
         except ValueError:
134 134
             self.skipTest("Unknown value returned by PD Buddy Sink")
135 135
 
136
+    def test_get_source_cap(self):
137
+        self.assertIsInstance(self.pdbs.get_source_cap(), list)
138
+
136 139
     def test_send_command_invalid(self):
137 140
         with self.assertRaises(KeyError):
138 141
             self.pdbs.send_command("foo bar")

Laden…
Annuleren
Opslaan