@@ -76,56 +76,50 @@ def _get_registry_params(value, x):
7676
7777
7878class _MetaGPIOExpander (type ):
79- def __new__ (mcs , clsname , bases , dct , * args , ** kwargs ):
80- result_dct = {}
79+ def __new__ (mcs , clsname , bases , dct , * args , ** kwargs ): # pylint: disable=unused-argument
80+ _result_dct = {}
8181
8282 for key , value in dct .items ():
8383 # variable has full qualified name
84- result_dct [key ] = value
84+ _result_dct [key ] = value
8585
8686 if key == '_NUM_GPIO' :
8787 # call to get only interesting data
88- _ , _width , _adder , _ = _get_registry_params (value , 1 )
88+ _ , _width , _ , _ = _get_registry_params (value , 1 )
8989 # entire registries
90- result_dct ['input_ports' ] = ROBits (8 * _width , _INPUT_PORT , 0 , register_width = _width )
91- result_dct ['output_ports' ] = RWBits (8 * _width , _OUTPUT_PORT , 0 , register_width = _width )
92- result_dct ['polarity_inversions' ] = RWBits (8 * _width , _POLARITY_REGISTER , 0 , register_width = _width )
93- result_dct ['configuration_ports' ] = RWBits (8 * _width , _CONFIG_REGISTER , 0 , register_width = _width )
90+ _result_dct ['input_ports' ] = ROBits (8 * _width , _INPUT_PORT , 0 , register_width = _width )
91+ _result_dct ['output_ports' ] = RWBits (8 * _width , _OUTPUT_PORT , 0 , register_width = _width )
92+ _result_dct ['polarity_inversions' ] = RWBits (8 * _width , _POLARITY_REGISTER , 0 , register_width = _width )
93+ _result_dct ['configuration_ports' ] = RWBits (8 * _width , _CONFIG_REGISTER , 0 , register_width = _width )
9494
9595 # create single bit registries
9696 for x in range (value ):
9797 _name , _reg_address_multiplier , _adder , _idx = _get_registry_params (value , x )
9898
99- _cfg_reg = RWBit (_CONFIG_REGISTER * _reg_address_multiplier + _adder , _idx )
100- _input_reg = ROBit (_INPUT_PORT * _reg_address_multiplier + _adder , _idx )
101- _output_reg = RWBit (_OUTPUT_PORT * _reg_address_multiplier + _adder , _idx )
102- _polarity_reg = RWBit (_POLARITY_REGISTER * _reg_address_multiplier + _adder , _idx )
103-
10499 # REGISTRY 0 and 1 INPUT PORT
105- prop_name = f"I{ _name } { _idx } "
106- result_dct [prop_name ] = _input_reg
100+ _result_dct [f"I{ _name } { _idx } " ] = ROBit (_INPUT_PORT * _reg_address_multiplier + _adder , _idx )
107101
108102 # REGISTRY 2 and 3 OUTPUT PORT
109- prop_name = f"O{ _name } { _idx } "
110- result_dct [prop_name ] = _output_reg
103+ _result_dct [f"O{ _name } { _idx } " ] = RWBit (_OUTPUT_PORT * _reg_address_multiplier + _adder , _idx )
111104
112105 # REGISTRY 4 and 5 POLARITY INVERSION REGISTER
113- prop_name = f"N{ _name } { _idx } "
114- result_dct [prop_name ] = _polarity_reg
106+ _result_dct [f"N{ _name } { _idx } " ] = RWBit (_POLARITY_REGISTER * _reg_address_multiplier + _adder , _idx )
115107
116108 # REGISTRY 6 and 7 CONFIGURATION REGISTER
117- prop_name = f"C{ _name } { _idx } "
118- result_dct [prop_name ] = _cfg_reg
109+ _result_dct [f"C{ _name } { _idx } " ] = RWBit (_CONFIG_REGISTER * _reg_address_multiplier + _adder , _idx )
119110
120- inst = super (_MetaGPIOExpander , mcs ).__new__ (mcs , clsname , bases , result_dct )
121- return inst
111+ return super (_MetaGPIOExpander , mcs ).__new__ (mcs , clsname , bases , _result_dct )
122112
123113
124114class _BaseGPIOExpander (metaclass = _MetaGPIOExpander ):
125- def __init__ (self , i2c_bus : I2C , address : int , ** kwargs ) -> None :
115+ def __init__ (self , i2c_bus : I2C , address : int , ** kwargs ) -> None : # pylint: disable=unused-argument
126116 self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
127117
128- def max_gpios (self ):
118+ def max_gpios (self ) -> int :
119+ """Return subclass' gpio number.
120+
121+ :return int value from subclass's attribute.
122+ """
129123 return getattr (self , '_NUM_GPIO' )
130124
131125
0 commit comments