Skip to content

Commit 1f452d5

Browse files
committed
Add the missing ranges so labels are usable and add a test to catch it in future
1 parent 6e404bd commit 1f452d5

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

data/rdm/PidDataTest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ def testLoad(self):
5151
self.assertEqual(store.ManufacturerIdToName(32767),
5252
"RESERVED FOR PROTOTYPING/EXPERIMENTAL USE ONLY")
5353

54+
def testData(self):
55+
store = PidStore.GetStore(os.environ['PIDDATA'])
56+
57+
self.assertIsNotNone(store)
58+
59+
pids = store.Pids()
60+
61+
# For fields (atoms) with ranges, check all labeled values are correctly
62+
# within a range so they can be used
63+
for pid in pids:
64+
for command in (PidStore.RDM_GET,
65+
PidStore.RDM_SET,
66+
PidStore.RDM_DISCOVERY):
67+
if pid.RequestSupported(command):
68+
for atom in pid.GetRequest(command).GetAtoms():
69+
# If we've only got labels then ranges are auto-generated
70+
if atom.HasRanges() and atom.HasLabels():
71+
for (label) in atom._labels:
72+
self.assertTrue(
73+
atom.ValidateRawValueInRange(atom._labels[label]),
74+
"Label %s (%d) of %s not in a range in PID %s (0x%04hx)" %
75+
(label, atom._labels[label], atom.name, pid.name,
76+
pid.value))
77+
5478

5579
if __name__ == '__main__':
5680
unittest.main()

data/rdm/pids.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,10 @@ pid {
17701770
value: 0
17711771
label: "Root"
17721772
}
1773+
range {
1774+
min: 0
1775+
max: 0
1776+
}
17731777
range {
17741778
min: 1
17751779
max: 512
@@ -1782,6 +1786,10 @@ pid {
17821786
value: 0
17831787
label: "Root Device"
17841788
}
1789+
range {
1790+
min: 0
1791+
max: 0
1792+
}
17851793
range {
17861794
min: 1
17871795
max: 255
@@ -4386,6 +4394,10 @@ pid {
43864394
value: 0
43874395
label: "Un-set"
43884396
}
4397+
range {
4398+
min: 0
4399+
max: 0
4400+
}
43894401
range {
43904402
min: 1
43914403
max: 4294967295

python/ola/PidStore.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ def __repr__(self):
273273
def GetDescription(self, indent=0):
274274
return str(self)
275275

276+
@staticmethod
277+
def HasLabels():
278+
return False
279+
276280
@staticmethod
277281
def HasRanges():
278282
return False
@@ -438,6 +442,9 @@ def RawValue(self, value):
438442
"""
439443
return self._AccountForMultiplierPack(value)
440444

445+
def HasLabels(self):
446+
return (len(self._labels) > 0)
447+
441448
def HasRanges(self):
442449
return (len(self._ranges) > 0)
443450

0 commit comments

Comments
 (0)