This repository was archived by the owner on Nov 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,8 +32,10 @@ Version 0.5.0
3232 This allows us more freedom to build higher level decoding functions.
3333* Adding functionality to include ADC and GPIO responses as objects stored
3434 in the device pins.
35- * Protected pins dict and instead exposed a get_pin function on device.
35+ * Protected pins dict and instead exposed a `` get_pin `` function on device.
3636 This allows introspection on pin internals to making usage easier.
37+ * Updated ``get_compatible_pins `` to return a set of pin indices rather
38+ than a dict of pins. This is to encourage the use of ``get_pin `` OOP.
3739
3840Version 0.4.0
3941-------------
Original file line number Diff line number Diff line change @@ -106,14 +106,12 @@ def test_device_function(uos_device, function: UOSFunction):
106106 for volatility in Persistence :
107107 if volatility not in uos_device .device .functions_enabled [function .name ]:
108108 continue # Ignore unsupported volatilities for device
109- pins = uos_device .device .get_compatible_pins (function )
110- if pins is None or len (pins ) == 0 :
111- pins = [0 ] # insert a dummy pin for non-pinned functions.
112- for pin in pins :
109+ pins_indices = uos_device .device .get_compatible_pins (function )
110+ for pin_index in pins_indices :
113111 api_function = getattr (uos_device , function .name )
114112 call_arguments = {}
115113 if "pin" in signature (api_function ).parameters .keys ():
116- call_arguments ["pin" ] = pin
114+ call_arguments ["pin" ] = pin_index
117115 if "level" in signature (api_function ).parameters .keys ():
118116 call_arguments ["level" ] = 0
119117 if "volatility" in signature (api_function ).parameters .keys ():
Original file line number Diff line number Diff line change @@ -15,16 +15,18 @@ def test_get_compatible_pins(uos_device: UOSDevice):
1515 UOSFunctions .get_adc_input ,
1616 ):
1717 if function .name in uos_device .device .functions_enabled :
18- pins = uos_device .device .get_compatible_pins (function )
19- assert len (pins ) > 0
20- assert isinstance (pins [next (iter (pins ))], Pin )
21- if function == UOSFunctions .get_adc_input :
22- assert all (pins [pin ].adc_in for pin in pins )
23- elif function == UOSFunctions .set_gpio_output :
24- assert all (pins [pin ].gpio_out for pin in pins )
18+ pins_indices = uos_device .device .get_compatible_pins (function )
19+ assert len (pins_indices ) > 0
20+ for pin_index in pins_indices :
21+ pin = uos_device .device .get_pin (pin_index )
22+ assert isinstance (pin , Pin )
23+ if function == UOSFunctions .get_adc_input :
24+ assert pin .adc_in
25+ elif function == UOSFunctions .set_gpio_output :
26+ assert pin .gpio_out
2527 # Check lookup of function without pins returns empty list.
2628 pins = uos_device .device .get_compatible_pins (UOSFunctions .hard_reset )
27- assert isinstance (pins , dict )
29+ assert isinstance (pins , set )
2830 assert len (pins ) == 0
2931 # Check bad function throws unsupported error
3032 with pytest .raises (UOSUnsupportedError ):
Original file line number Diff line number Diff line change @@ -351,21 +351,21 @@ def get_pins(self) -> set:
351351 """Return a set of pin indices known by this device."""
352352 return set (self ._pins .keys ())
353353
354- def get_compatible_pins (self , function : UOSFunction ) -> dict :
355- """Return a dict of pin objects that are suitable for a function .
354+ def get_compatible_pins (self , function : UOSFunction ) -> set :
355+ """Get pins suitable for use with a particular UOS Function .
356356
357357 :param function: the string name of the UOS Schema function.
358- :return: Dict of pin objects, keyed on pin index .
358+ :return: Set of pin indices which support the function .
359359 """
360360 if (
361361 not isinstance (function , UOSFunction )
362362 or function not in UOSFunctions .enumerate_functions ()
363363 ):
364364 raise UOSUnsupportedError (f"UOS function { function .name } doesn't exist." )
365365 if function .pin_requirements is None : # pins are not relevant to this function
366- return {}
366+ return set ()
367367 return {
368- pin_index : pin
368+ pin_index
369369 for pin_index , pin in self ._pins .items ()
370370 if all (
371371 getattr (pin , requirement ) for requirement in function .pin_requirements
You can’t perform that action at this time.
0 commit comments