55from hardwarelibrary .communication import USBPort , TextCommand
66from hardwarelibrary .physicaldevice import *
77from hardwarelibrary .notificationcenter import NotificationCenter , Notification
8+ from hardwarelibrary .powermeters .capabilities import Capability
89
910class PowerMeterNotification (Enum ):
1011 didMeasure = "didMeasure"
@@ -14,20 +15,22 @@ class PowerMeterDevice(PhysicalDevice):
1415 def __init__ (self , serialNumber :str , idProduct :int , idVendor :int ):
1516 super ().__init__ (serialNumber , idProduct , idVendor )
1617 self .absolutePower = 0
17- self .calibrationWavelength = None
1818
19- # Hardware hooks a driver must implement, on top of doInitializeDevice
20- # and doShutdownDevice inherited from PhysicalDevice.
21- @abstractmethod
22- def doGetAbsolutePower (self ):
23- ...
19+ def capabilities (self ) -> list :
20+ # The capability mixins, not the marker nor the device class itself
21+ # (a driver is a Capability subclass too, but it is a PhysicalDevice).
22+ return [klass for klass in type (self ).__mro__
23+ if issubclass (klass , Capability )
24+ and klass is not Capability
25+ and not issubclass (klass , PhysicalDevice )]
2426
25- @abstractmethod
26- def doGetCalibrationWavelength (self ):
27- ...
27+ def hasCapability (self , capabilityClass ) -> bool :
28+ return isinstance (self , capabilityClass )
2829
30+ # Measuring absolute power is the one capability every power meter has, so
31+ # its hook stays on the base; optional capabilities live in mixins.
2932 @abstractmethod
30- def doSetCalibrationWavelength (self , wavelength ):
33+ def doGetAbsolutePower (self ):
3134 ...
3235
3336 def measureAbsolutePower (self ):
@@ -36,13 +39,5 @@ def measureAbsolutePower(self):
3639 NotificationCenter ().postNotification (PowerMeterNotification .didMeasure , notifyingObject = self , userInfo = power )
3740 return power
3841
39- def getCalibrationWavelength (self ):
40- self .doGetCalibrationWavelength ()
41- return self .calibrationWavelength
42-
43- def setCalibrationWavelength (self , wavelength ):
44- self .doSetCalibrationWavelength (wavelength )
45- self .doGetCalibrationWavelength ()
46-
4742 def doGetStatusUserInfo (self ):
4843 return self .measureAbsolutePower ()
0 commit comments